tsphinx.addnodesdocument)}( rawsourcechildren]( translations LanguagesNode)}(hhh](h pending_xref)}(hhh]docutils.nodesTextChinese (Simplified)}parenthsba attributes}(ids]classes]names]dupnames]backrefs] refdomainstdreftypedoc reftarget,/translations/zh_CN/userspace-api/check_execmodnameN classnameN refexplicitutagnamehhh ubh)}(hhh]hChinese (Traditional)}hh2sbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget,/translations/zh_TW/userspace-api/check_execmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hItalian}hhFsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget,/translations/it_IT/userspace-api/check_execmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hJapanese}hhZsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget,/translations/ja_JP/userspace-api/check_execmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hKorean}hhnsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget,/translations/ko_KR/userspace-api/check_execmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hSpanish}hhsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget,/translations/sp_SP/userspace-api/check_execmodnameN classnameN refexplicituh1hhh ubeh}(h]h ]h"]h$]h&]current_languageEnglishuh1h hh _documenthsourceNlineNubhcomment)}(h SPDX-License-Identifier: GPL-2.0h]h SPDX-License-Identifier: GPL-2.0}hhsbah}(h]h ]h"]h$]h&] xml:spacepreserveuh1hhhhhhF/var/lib/git/docbuild/linux/Documentation/userspace-api/check_exec.rsthKubh)}(h'Copyright © 2024 Microsoft Corporationh]h'Copyright © 2024 Microsoft Corporation}hhsbah}(h]h ]h"]h$]h&]hhuh1hhhhhhhhKubhsection)}(hhh](htitle)}(hExecutability checkh]hExecutability check}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhhhhhKubh paragraph)}(hX:The ``AT_EXECVE_CHECK`` :manpage:`execveat(2)` flag, and the ``SECBIT_EXEC_RESTRICT_FILE`` and ``SECBIT_EXEC_DENY_INTERACTIVE`` securebits are intended for script interpreters and dynamic linkers to enforce a consistent execution security policy handled by the kernel. See the `samples/check-exec/inc.c`_ example.h](hThe }(hhhhhNhNubhliteral)}(h``AT_EXECVE_CHECK``h]hAT_EXECVE_CHECK}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhubh }(hhhhhNhNubhmanpage)}(h:manpage:`execveat(2)`h]h execveat(2)}(hhhhhNhNubah}(h]h ]hah"]h$]h&]hhpath execveat(2)pageexecveatsection2uh1hhhubh flag, and the }(hhhhhNhNubh)}(h``SECBIT_EXEC_RESTRICT_FILE``h]hSECBIT_EXEC_RESTRICT_FILE}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhubh and }(hhhhhNhNubh)}(h ``SECBIT_EXEC_DENY_INTERACTIVE``h]hSECBIT_EXEC_DENY_INTERACTIVE}(hj!hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhubh securebits are intended for script interpreters and dynamic linkers to enforce a consistent execution security policy handled by the kernel. See the }(hhhhhNhNubh reference)}(h`samples/check-exec/inc.c`_h]hsamples/check-exec/inc.c}(hj5hhhNhNubah}(h]h ]h"]h$]h&]namesamples/check-exec/inc.crefuri`https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/samples/check-exec/inc.cuh1j3hhٌresolvedKubh example.}(hhhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(hXKWhether an interpreter should check these securebits or not depends on the security risk of running malicious scripts with respect to the execution environment, and whether the kernel can check if a script is trustworthy or not. For instance, Python scripts running on a server can use arbitrary syscalls and access arbitrary files. Such interpreters should then be enlighten to use these securebits and let users define their security policy. However, a JavaScript engine running in a web browser should already be sandboxed and then should not be able to harm the user's environment.h]hXMWhether an interpreter should check these securebits or not depends on the security risk of running malicious scripts with respect to the execution environment, and whether the kernel can check if a script is trustworthy or not. For instance, Python scripts running on a server can use arbitrary syscalls and access arbitrary files. Such interpreters should then be enlighten to use these securebits and let users define their security policy. However, a JavaScript engine running in a web browser should already be sandboxed and then should not be able to harm the user’s environment.}(hjRhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(hXScript interpreters or dynamic linkers built for tailored execution environments (e.g. hardened Linux distributions or hermetic container images) could use ``AT_EXECVE_CHECK`` without checking the related securebits if backward compatibility is handled by something else (e.g. atomic update ensuring that all legitimate libraries are allowed to be executed). It is then recommended for script interpreters and dynamic linkers to check the securebits at run time by default, but also to provide the ability for custom builds to behave like if ``SECBIT_EXEC_RESTRICT_FILE`` or ``SECBIT_EXEC_DENY_INTERACTIVE`` were always set to 1 (i.e. always enforce restrictions).h](hScript interpreters or dynamic linkers built for tailored execution environments (e.g. hardened Linux distributions or hermetic container images) could use }(hj`hhhNhNubh)}(h``AT_EXECVE_CHECK``h]hAT_EXECVE_CHECK}(hjhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhj`ubhXp without checking the related securebits if backward compatibility is handled by something else (e.g. atomic update ensuring that all legitimate libraries are allowed to be executed). It is then recommended for script interpreters and dynamic linkers to check the securebits at run time by default, but also to provide the ability for custom builds to behave like if }(hj`hhhNhNubh)}(h``SECBIT_EXEC_RESTRICT_FILE``h]hSECBIT_EXEC_RESTRICT_FILE}(hjzhhhNhNubah}(h]h ]h"]h$]h&]uh1hhj`ubh or }(hj`hhhNhNubh)}(h ``SECBIT_EXEC_DENY_INTERACTIVE``h]hSECBIT_EXEC_DENY_INTERACTIVE}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhj`ubh9 were always set to 1 (i.e. always enforce restrictions).}(hj`hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(hhh](h)}(hAT_EXECVE_CHECKh]hAT_EXECVE_CHECK}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhK"ubh)}(hXPassing the ``AT_EXECVE_CHECK`` flag to :manpage:`execveat(2)` only performs a check on a regular file and returns 0 if execution of this file would be allowed, ignoring the file format and then the related interpreter dependencies (e.g. ELF libraries, script's shebang).h](h Passing the }(hjhhhNhNubh)}(h``AT_EXECVE_CHECK``h]hAT_EXECVE_CHECK}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh flag to }(hjhhhNhNubh)}(h:manpage:`execveat(2)`h]h execveat(2)}(hjhhhNhNubah}(h]h ]hah"]h$]h&]hhj execveat(2)jexecveatj j uh1hhjubh only performs a check on a regular file and returns 0 if execution of this file would be allowed, ignoring the file format and then the related interpreter dependencies (e.g. ELF libraries, script’s shebang).}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK$hjhhubh)}(hXPrograms should always perform this check to apply kernel-level checks against files that are not directly executed by the kernel but passed to a user space interpreter instead. All files that contain executable code, from the point of view of the interpreter, should be checked. However the result of this check should only be enforced according to ``SECBIT_EXEC_RESTRICT_FILE`` or ``SECBIT_EXEC_DENY_INTERACTIVE.``.h](hX`Programs should always perform this check to apply kernel-level checks against files that are not directly executed by the kernel but passed to a user space interpreter instead. All files that contain executable code, from the point of view of the interpreter, should be checked. However the result of this check should only be enforced according to }(hjhhhNhNubh)}(h``SECBIT_EXEC_RESTRICT_FILE``h]hSECBIT_EXEC_RESTRICT_FILE}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh or }(hjhhhNhNubh)}(h!``SECBIT_EXEC_DENY_INTERACTIVE.``h]hSECBIT_EXEC_DENY_INTERACTIVE.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK)hjhhubh)}(hXVThe main purpose of this flag is to improve the security and consistency of an execution environment to ensure that direct file execution (e.g. ``./script.sh``) and indirect file execution (e.g. ``sh script.sh``) lead to the same result. For instance, this can be used to check if a file is trustworthy according to the caller's environment.h](hThe main purpose of this flag is to improve the security and consistency of an execution environment to ensure that direct file execution (e.g. }(hjhhhNhNubh)}(h``./script.sh``h]h ./script.sh}(hj#hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh$) and indirect file execution (e.g. }(hjhhhNhNubh)}(h``sh script.sh``h]h sh script.sh}(hj5hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh) lead to the same result. For instance, this can be used to check if a file is trustworthy according to the caller’s environment.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK0hjhhubh)}(hXsIn a secure environment, libraries and any executable dependencies should also be checked. For instance, dynamic linking should make sure that all libraries are allowed for execution to avoid trivial bypass (e.g. using ``LD_PRELOAD``). For such secure execution environment to make sense, only trusted code should be executable, which also requires integrity guarantees.h](hIn a secure environment, libraries and any executable dependencies should also be checked. For instance, dynamic linking should make sure that all libraries are allowed for execution to avoid trivial bypass (e.g. using }(hjMhhhNhNubh)}(h``LD_PRELOAD``h]h LD_PRELOAD}(hjUhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjMubh). For such secure execution environment to make sense, only trusted code should be executable, which also requires integrity guarantees.}(hjMhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK6hjhhubh)}(hTo avoid race conditions leading to time-of-check to time-of-use issues, ``AT_EXECVE_CHECK`` should be used with ``AT_EMPTY_PATH`` to check against a file descriptor instead of a path.h](hITo avoid race conditions leading to time-of-check to time-of-use issues, }(hjmhhhNhNubh)}(h``AT_EXECVE_CHECK``h]hAT_EXECVE_CHECK}(hjuhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjmubh should be used with }(hjmhhhNhNubh)}(h``AT_EMPTY_PATH``h]h AT_EMPTY_PATH}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjmubh6 to check against a file descriptor instead of a path.}(hjmhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK