Use of AT_SECURE on Linux

Hello, list. I noticed that CPython does not sanitize environment when transition between SELinux contexts or AppArmor profiles happens, which I think is a good thing to do in cases when one sandboxed application runs a Python script with different (potentially less strict) sandbox configuration. On Linux, such transition is indicated by LSMs (SELinux, AppArmor) using the AT_SECURE bit in the aux. vector. Consult getauxval(3) in the glibc manual for details. Here is the paragraph describing AT_SECURE:
set-user-ID and capabilities are not directly relevant to Python since it is not possible to apply setuid bit or file capabilities to the script (with #!). Though, it might be relevant for other applications embedding CPython. The case with LSMs is directly relevant for standalone scripts since both SELinux and AppArmor allow applying per-script restrictions. There is the -I flag for the CPython interpreter that in my opinion does exactly what should be done when AT_SECURE bit is set. Since isolated flag is already checked by all relevant code paths in CPython and standard library, I believe it is a good idea to simply make AT_SECURE imply -I. Though I am not sure whether the behavior for other applications embedding CPython should be same. I can put together a patch to implement that if there is an interest and somebody can point me to an appropriate place to change. -- Cheers, Max Mazurov https://foxcpp.dev
participants (1)
-
Max Mazurov