ipe: add script enforcement mechanism with AT_EXECVE_CHECK
Subsystems (3)
v3 cover ipe: add script enforcement mechanism with AT_EXECVE_CHECK
Indirect file execution through interpreters (e.g. python script.py, sh script.sh) should have integrity policy enforced by IPE based on the rules. Currently, IPE can only enforce policy on the interpreter binary itself, but has no visibility into the scripts that the interpreter executes.
Overview
--------
This patch series introduces script enforcement for IPE, allowing integrity evaluation of indirectly executed scripts through the AT_EXECVE_CHECK flag.
Patch 1 adds the core implementation with ipe_bprm_creds_for_exec() hook that integrates with the AT_EXECVE_CHECK mechanism.
Patch 2 updates admin guide documentation to explain the script enforcement mechanism.
The IPE test suite has been updated to include script enforcement tests:
https://github.com/microsoft/ipe/pull/6
Changes since v2:
- update AT_EXECVE_CHECK reference
Changes since v1:
- update the interpreters reference
Yanzhu Huang (2):
ipe: Add AT_EXECVE_CHECK support for script enforcement
ipe: Update documentation for script enforcement
Documentation/admin-guide/LSM/ipe.rst | 17 ++++++++++++++--- security/ipe/audit.c | 1 + security/ipe/hooks.c | 27 +++++++++++++++++++++++++++ security/ipe/hooks.h | 3 +++ security/ipe/ipe.c | 1 + 5 files changed, 46 insertions(+), 3 deletions(-)
--
2.43.0
PATCH v3 1/2 ipe: Add AT_EXECVE_CHECK support for script enforcement
This patch adds a new ipe_bprm_creds_for_exec() hook that integrates with the AT_EXECVE_CHECK mechanism. To enable script enforcement, interpreters need to incorporate the AT_EXECVE_CHECK flag when calling execveat() on script files before execuation.
When a userspace interpreter calls execveat() with the AT_EXECVE_CHECK flag, this hook triggers IPE policy evaluation on the script file. The hook only triggers IPE when bprm->is_check is true, ensuring it's being called from an AT_EXECVE_CHECK context. It then builds an evaluation context for an IPE_OP_EXEC operation and invokes IPE policy. The kernel returns the policy decision to the interpreter, which can then decide whether to proceed with script execution.
This extends IPE enforcement to indirectly executed scripts, permitting trusted scripts to execute while denying untrusted ones.
--- security/ipe/audit.c | 1 + security/ipe/hooks.c | 27 +++++++++++++++++++++++++++ security/ipe/hooks.h | 3 +++ security/ipe/ipe.c | 1 + 4 files changed, 32 insertions(+)
security/ipe/audit.c +1 -0
@@ -46,6 +46,7 @@ static const char *const audit_op_names[__IPE_OP_MAX + 1] = {static const char *const audit_hook_names[__IPE_HOOK_MAX] = {"BPRM_CHECK" , +"BPRM_CREDS_FOR_EXEC" ,"MMAP" ,"MPROTECT" ,"KERNEL_READ" ,
security/ipe/hooks.c +27 -0
@@ -35,6 +35,33 @@ int ipe_bprm_check_security(struct linux_binprm *bprm)return ipe_evaluate_event (&ctx); } +/** +* ipe_bprm_creds_for_exec() - ipe security hook function for bprm creds check. +* @bprm: Supplies a pointer to a linux_binprm structure to source the file +* being evaluated. +* +* This LSM hook is called when userspace signals the kernel to check a file +* for execution through the execveat syscall with the AT_EXECVE_CHECK flag. +* The hook triggers IPE policy evaluation on the script file and returns +* the policy decision to userspace. The userspace program receives the +* return code and can decide whether to proceed with script execution. +* +* Return: +* * %0 - Success +* * %-EACCES - Did not pass IPE policy +*/ +int ipe_bprm_creds_for_exec (struct linux_binprm *bprm) +{ +struct ipe_eval_ctx ctx =IPE_EVAL_CTX_INIT ; + +if (!bprm->is_check) +return 0 ; + +ipe_build_eval_ctx (&ctx, bprm->file,IPE_OP_EXEC , +IPE_HOOK_BPRM_CREDS_FOR_EXEC ); +return ipe_evaluate_event (&ctx); +} +/** * ipe_mmap_file() - ipe security hook function for mmap check. * @f: File being mmap'd. Can be NULL in the case of anonymous memory.
security/ipe/hooks.h +3 -0
@@ -13,6 +13,7 @@enum ipe_hook_type {IPE_HOOK_BPRM_CHECK =0 , +IPE_HOOK_BPRM_CREDS_FOR_EXEC ,IPE_HOOK_MMAP ,IPE_HOOK_MPROTECT ,IPE_HOOK_KERNEL_READ ,
@@ -24,6 +25,8 @@ enum ipe_hook_type {int ipe_bprm_check_security (struct linux_binprm *bprm); +int ipe_bprm_creds_for_exec (struct linux_binprm *bprm); +int ipe_mmap_file (struct file *f,unsigned long reqprot,unsigned long prot,unsigned long flags);
security/ipe/ipe.c +1 -0
@@ -47,6 +47,7 @@ struct ipe_inode *ipe_inode(const struct inode *inode)static struct security_hook_list ipe_hooks[]__ro_after_init = {LSM_HOOK_INIT (bprm_check_security, ipe_bprm_check_security), +LSM_HOOK_INIT (bprm_creds_for_exec, ipe_bprm_creds_for_exec),LSM_HOOK_INIT (mmap_file, ipe_mmap_file),LSM_HOOK_INIT (file_mprotect, ipe_file_mprotect),LSM_HOOK_INIT (kernel_read_file, ipe_kernel_read_file),
Signature · 1 line
2.43.0
PATCH v3 2/2 ipe: Update documentation for script enforcement
In reply to Yanzhu HuangThis patch adds explanation of script enforcement mechanism in admin guide documentation. Describes how IPE supports integrity enforcement for indirectly executed scripts through the AT_EXECVE_CHECK flag, and how this differs from kernel enforcement for compiled executables.
--- Documentation/admin-guide/LSM/ipe.rst | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
Documentation/admin-guide/LSM/ipe.rst +14 -3
@@ -95,7 +95,20 @@ languages when these scripts are invoked by passing these program files to the interpreter. This is because the way interpreters execute these files; the scripts themselves are not evaluated as executable code through one of IPE's hooks, but they are merely text files that are read -(as opposed to compiled executables) [#interpreters]_. +(as opposed to compiled executables). However, with the introduction of the +``AT_EXECVE_CHECK`` flag (:doc:`AT_EXECVE_CHECK </userspace-api/check_exec>`), +interpreters can use it to signal the kernel that a script file will be executed, +and request the kernel to perform LSM security checks on it. + +IPE's EXECUTE operation enforcement differs between compiled executables and +interpreted scripts: For compiled executables, enforcement is triggered +automatically by the kernel during ``execve()``, ``execveat()``, ``mmap()`` +and ``mprotect()`` syscalls when loading executable content. For interpreted +scripts, enforcement requires explicit interpreter integration using +``execveat()`` with ``AT_EXECVE_CHECK`` flag. Unlike exec syscalls that IPE +intercepts during the execution process, this mechanism needs the interpreter +to take the initiative, and existing interpreters won't be automatically +supported unless the signal call is added. Threat Model ------------
@@ -806,8 +819,6 @@ A: .. [#digest_cache_lsm] https://lore.kernel.org/lkml/[email protected]/ -.. [#interpreters] There is `some interest in solving this issue <https://lore.kernel.org/lkml/[email protected]/>`_. - .. [#devdoc] Please see :doc:`the design docs </security/ipe>` for more on this topic.
Signature · 1 line
2.43.0
Quoted 39 lines · Yanzhu Huang
Indirect file execution through interpreters (e.g. python
script.py, shscript.sh) should have integrity policy enforced by IPE based on the rules. Currently, IPE can only enforce policy on the interpreter binary itself, but has no visibility into the scripts that the interpreter executes.Overview
--------This patch series introduces script enforcement for IPE, allowing integrity evaluation of indirectly executed scripts through the
AT_EXECVE_CHECKflag.Patch 1 adds the core implementation with
ipe_bprm_creds_for_exec()hook that integrates with theAT_EXECVE_CHECKmechanism.Patch 2 updates admin guide documentation to explain the script enforcement mechanism.
The IPE test suite has been updated to include script enforcement tests:
https://github.com/microsoft/ipe/pull/6Changes since v2:
- updateAT_EXECVE_CHECKreferenceChanges since v1:
- update the interpreters referenceYanzhu Huang (2):
ipe: AddAT_EXECVE_CHECKsupport for script enforcement
ipe: Update documentation for script enforcementDocumentation/admin-guide/LSM/ipe.rst | 17 ++++++++++++++--- security/ipe/audit.c | 1 + security/ipe/hooks.c | 27 +++++++++++++++++++++++++++ security/ipe/hooks.h | 3 +++ security/ipe/ipe.c | 1 + 5 files changed, 46 insertions(+), 3 deletions(-)
Quoted 3 lines
--
2.43.0
Thanks, applied to ipe/next.
-Fan