Skip to content

Commit 9410d22

Browse files
rgbriggseparis
authored andcommitted
audit: call audit_bprm() only once to add AUDIT_EXECVE information
Move the audit_bprm() call from search_binary_handler() to exec_binprm(). This allows us to get rid of the mm member of struct audit_aux_data_execve since bprm->mm will equal current->mm. This also mitigates the issue that ->argc could be modified by the load_binary() call in search_binary_handler(). audit_bprm() was being called to add an AUDIT_EXECVE record to the audit context every time search_binary_handler() was recursively called. Only one reference is necessary. Reported-by: Oleg Nesterov <onestero@redhat.com> Cc: Eric Paris <eparis@redhat.com> Signed-off-by: Richard Guy Briggs <rgb@redhat.com> Signed-off-by: Eric Paris <eparis@redhat.com> --- This patch is against 3.11, but was developed on Oleg's post-3.11 patches that introduce exec_binprm().
1 parent d9cfea9 commit 9410d22

4 files changed

Lines changed: 4 additions & 15 deletions

File tree

‎fs/exec.c‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,10 +1383,6 @@ int search_binary_handler(struct linux_binprm *bprm)
13831383
if (retval)
13841384
return retval;
13851385

1386-
retval = audit_bprm(bprm);
1387-
if (retval)
1388-
return retval;
1389-
13901386
/* Need to fetch pid before load_binary changes it */
13911387
old_pid = current->pid;
13921388
rcu_read_lock();
@@ -1408,6 +1404,7 @@ int search_binary_handler(struct linux_binprm *bprm)
14081404
bprm->recursion_depth = depth;
14091405
if (retval >= 0) {
14101406
if (depth == 0) {
1407+
audit_bprm(bprm);
14111408
trace_sched_process_exec(current, old_pid, bprm);
14121409
ptrace_event(PTRACE_EVENT_EXEC, old_vpid);
14131410
}

‎include/linux/audit.h‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,10 @@ static inline void audit_ipc_set_perm(unsigned long qbytes, uid_t uid, gid_t gid
238238
if (unlikely(!audit_dummy_context()))
239239
__audit_ipc_set_perm(qbytes, uid, gid, mode);
240240
}
241-
static inline int audit_bprm(struct linux_binprm *bprm)
241+
static inline void audit_bprm(struct linux_binprm *bprm)
242242
{
243243
if (unlikely(!audit_dummy_context()))
244244
__audit_bprm(bprm);
245-
return 0;
246245
}
247246
static inline int audit_socketcall(int nargs, unsigned long *args)
248247
{
@@ -369,10 +368,8 @@ static inline void audit_ipc_obj(struct kern_ipc_perm *ipcp)
369368
static inline void audit_ipc_set_perm(unsigned long qbytes, uid_t uid,
370369
gid_t gid, umode_t mode)
371370
{ }
372-
static inline int audit_bprm(struct linux_binprm *bprm)
373-
{
374-
return 0;
375-
}
371+
static inline void audit_bprm(struct linux_binprm *bprm)
372+
{ }
376373
static inline int audit_socketcall(int nargs, unsigned long *args)
377374
{
378375
return 0;

‎kernel/audit.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,6 @@ struct audit_context {
199199
} mmap;
200200
struct {
201201
int argc;
202-
struct mm_struct *mm;
203202
} execve;
204203
};
205204
int fds[2];

‎kernel/auditsc.c‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,9 +1145,6 @@ static void audit_log_execve_info(struct audit_context *context,
11451145
const char __user *p;
11461146
char *buf;
11471147

1148-
if (context->execve.mm != current->mm)
1149-
return; /* execve failed, no additional info */
1150-
11511148
p = (const char __user *)current->mm->arg_start;
11521149

11531150
audit_log_format(*ab, "argc=%d", context->execve.argc);
@@ -2144,7 +2141,6 @@ void __audit_bprm(struct linux_binprm *bprm)
21442141

21452142
context->type = AUDIT_EXECVE;
21462143
context->execve.argc = bprm->argc;
2147-
context->execve.mm = bprm->mm;
21482144
}
21492145

21502146

0 commit comments

Comments
 (0)