Skip to content

Commit 6767818

Browse files
Yanzhu Huangjxwufan
authored andcommitted
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 execution. 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. Signed-off-by: Yanzhu Huang <yanzhuhuang@linux.microsoft.com> Signed-off-by: Fan Wu <wufan@kernel.org>
1 parent 864468a commit 6767818

4 files changed

Lines changed: 32 additions & 0 deletions

File tree

security/ipe/audit.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ static const char *const audit_op_names[__IPE_OP_MAX + 1] = {
4646

4747
static const char *const audit_hook_names[__IPE_HOOK_MAX] = {
4848
"BPRM_CHECK",
49+
"BPRM_CREDS_FOR_EXEC",
4950
"MMAP",
5051
"MPROTECT",
5152
"KERNEL_READ",

security/ipe/hooks.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,33 @@ int ipe_bprm_check_security(struct linux_binprm *bprm)
3535
return ipe_evaluate_event(&ctx);
3636
}
3737

38+
/**
39+
* ipe_bprm_creds_for_exec() - ipe security hook function for bprm creds check.
40+
* @bprm: Supplies a pointer to a linux_binprm structure to source the file
41+
* being evaluated.
42+
*
43+
* This LSM hook is called when userspace signals the kernel to check a file
44+
* for execution through the execveat syscall with the AT_EXECVE_CHECK flag.
45+
* The hook triggers IPE policy evaluation on the script file and returns
46+
* the policy decision to userspace. The userspace program receives the
47+
* return code and can decide whether to proceed with script execution.
48+
*
49+
* Return:
50+
* * %0 - Success
51+
* * %-EACCES - Did not pass IPE policy
52+
*/
53+
int ipe_bprm_creds_for_exec(struct linux_binprm *bprm)
54+
{
55+
struct ipe_eval_ctx ctx = IPE_EVAL_CTX_INIT;
56+
57+
if (!bprm->is_check)
58+
return 0;
59+
60+
ipe_build_eval_ctx(&ctx, bprm->file, IPE_OP_EXEC,
61+
IPE_HOOK_BPRM_CREDS_FOR_EXEC);
62+
return ipe_evaluate_event(&ctx);
63+
}
64+
3865
/**
3966
* ipe_mmap_file() - ipe security hook function for mmap check.
4067
* @f: File being mmap'd. Can be NULL in the case of anonymous memory.

security/ipe/hooks.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
enum ipe_hook_type {
1515
IPE_HOOK_BPRM_CHECK = 0,
16+
IPE_HOOK_BPRM_CREDS_FOR_EXEC,
1617
IPE_HOOK_MMAP,
1718
IPE_HOOK_MPROTECT,
1819
IPE_HOOK_KERNEL_READ,
@@ -24,6 +25,8 @@ enum ipe_hook_type {
2425

2526
int ipe_bprm_check_security(struct linux_binprm *bprm);
2627

28+
int ipe_bprm_creds_for_exec(struct linux_binprm *bprm);
29+
2730
int ipe_mmap_file(struct file *f, unsigned long reqprot, unsigned long prot,
2831
unsigned long flags);
2932

security/ipe/ipe.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ struct ipe_inode *ipe_inode(const struct inode *inode)
4747

4848
static struct security_hook_list ipe_hooks[] __ro_after_init = {
4949
LSM_HOOK_INIT(bprm_check_security, ipe_bprm_check_security),
50+
LSM_HOOK_INIT(bprm_creds_for_exec, ipe_bprm_creds_for_exec),
5051
LSM_HOOK_INIT(mmap_file, ipe_mmap_file),
5152
LSM_HOOK_INIT(file_mprotect, ipe_file_mprotect),
5253
LSM_HOOK_INIT(kernel_read_file, ipe_kernel_read_file),

0 commit comments

Comments
 (0)