aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Guy Briggs <rgb@redhat.com>2013-10-30 18:05:24 -0400
committerEric Paris <eparis@redhat.com>2013-11-05 11:15:03 -0500
commit9410d228a4cf434305306746bb799fb7acdd8648 (patch)
tree93dc6f756af3c2557f2e1377bad52582fdd9fe19
parentd9cfea91e97d5d19f9d69beaa844f5fe56a6adc6 (diff)
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().
-rw-r--r--fs/exec.c5
-rw-r--r--include/linux/audit.h9
-rw-r--r--kernel/audit.h1
-rw-r--r--kernel/auditsc.c4
4 files changed, 4 insertions, 15 deletions
diff --git a/fs/exec.c b/fs/exec.c
index fd774c7cb483..c5c24f2fc44a 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1383,10 +1383,6 @@ int search_binary_handler(struct linux_binprm *bprm)
1383 if (retval) 1383 if (retval)
1384 return retval; 1384 return retval;
1385 1385
1386 retval = audit_bprm(bprm);
1387 if (retval)
1388 return retval;
1389
1390 /* Need to fetch pid before load_binary changes it */ 1386 /* Need to fetch pid before load_binary changes it */
1391 old_pid = current->pid; 1387 old_pid = current->pid;
1392 rcu_read_lock(); 1388 rcu_read_lock();
@@ -1408,6 +1404,7 @@ int search_binary_handler(struct linux_binprm *bprm)
1408 bprm->recursion_depth = depth; 1404 bprm->recursion_depth = depth;
1409 if (retval >= 0) { 1405 if (retval >= 0) {
1410 if (depth == 0) { 1406 if (depth == 0) {
1407 audit_bprm(bprm);
1411 trace_sched_process_exec(current, old_pid, bprm); 1408 trace_sched_process_exec(current, old_pid, bprm);
1412 ptrace_event(PTRACE_EVENT_EXEC, old_vpid); 1409 ptrace_event(PTRACE_EVENT_EXEC, old_vpid);
1413 } 1410 }
diff --git a/include/linux/audit.h b/include/linux/audit.h
index 08b38bf13eb9..a40641954c29 100644
--- a/include/linux/audit.h
+++ b/include/linux/audit.h
@@ -238,11 +238,10 @@ static inline void audit_ipc_set_perm(unsigned long qbytes, uid_t uid, gid_t gid
238 if (unlikely(!audit_dummy_context())) 238 if (unlikely(!audit_dummy_context()))
239 __audit_ipc_set_perm(qbytes, uid, gid, mode); 239 __audit_ipc_set_perm(qbytes, uid, gid, mode);
240} 240}
241static inline int audit_bprm(struct linux_binprm *bprm) 241static inline void audit_bprm(struct linux_binprm *bprm)
242{ 242{
243 if (unlikely(!audit_dummy_context())) 243 if (unlikely(!audit_dummy_context()))
244 __audit_bprm(bprm); 244 __audit_bprm(bprm);
245 return 0;
246} 245}
247static inline int audit_socketcall(int nargs, unsigned long *args) 246static inline int audit_socketcall(int nargs, unsigned long *args)
248{ 247{
@@ -369,10 +368,8 @@ static inline void audit_ipc_obj(struct kern_ipc_perm *ipcp)
369static inline void audit_ipc_set_perm(unsigned long qbytes, uid_t uid, 368static inline void audit_ipc_set_perm(unsigned long qbytes, uid_t uid,
370 gid_t gid, umode_t mode) 369 gid_t gid, umode_t mode)
371{ } 370{ }
372static inline int audit_bprm(struct linux_binprm *bprm) 371static inline void audit_bprm(struct linux_binprm *bprm)
373{ 372{ }
374 return 0;
375}
376static inline int audit_socketcall(int nargs, unsigned long *args) 373static inline int audit_socketcall(int nargs, unsigned long *args)
377{ 374{
378 return 0; 375 return 0;
diff --git a/kernel/audit.h b/kernel/audit.h
index e7b94ab66c49..b779642b29af 100644
--- a/kernel/audit.h
+++ b/kernel/audit.h
@@ -199,7 +199,6 @@ struct audit_context {
199 } mmap; 199 } mmap;
200 struct { 200 struct {
201 int argc; 201 int argc;
202 struct mm_struct *mm;
203 } execve; 202 } execve;
204 }; 203 };
205 int fds[2]; 204 int fds[2];
diff --git a/kernel/auditsc.c b/kernel/auditsc.c
index 425a8939be1a..dfc5d6745ee5 100644
--- a/kernel/auditsc.c
+++ b/kernel/auditsc.c
@@ -1145,9 +1145,6 @@ static void audit_log_execve_info(struct audit_context *context,
1145 const char __user *p; 1145 const char __user *p;
1146 char *buf; 1146 char *buf;
1147 1147
1148 if (context->execve.mm != current->mm)
1149 return; /* execve failed, no additional info */
1150
1151 p = (const char __user *)current->mm->arg_start; 1148 p = (const char __user *)current->mm->arg_start;
1152 1149
1153 audit_log_format(*ab, "argc=%d", context->execve.argc); 1150 audit_log_format(*ab, "argc=%d", context->execve.argc);
@@ -2144,7 +2141,6 @@ void __audit_bprm(struct linux_binprm *bprm)
2144 2141
2145 context->type = AUDIT_EXECVE; 2142 context->type = AUDIT_EXECVE;
2146 context->execve.argc = bprm->argc; 2143 context->execve.argc = bprm->argc;
2147 context->execve.mm = bprm->mm;
2148} 2144}
2149 2145
2150 2146