diff options
author | Richard Guy Briggs <rgb@redhat.com> | 2013-10-30 17:56:13 -0400 |
---|---|---|
committer | Eric Paris <eparis@redhat.com> | 2013-11-05 11:09:36 -0500 |
commit | d9cfea91e97d5d19f9d69beaa844f5fe56a6adc6 (patch) | |
tree | 057dfc9534cdb15ac38b440057dff35e131a1d42 /kernel/auditsc.c | |
parent | 9462dc59817580419ef1f2504e32f861c290f251 (diff) |
audit: move audit_aux_data_execve contents into audit_context union
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, so just update it. Move the the contents of
audit_aux_data_execve into the union in audit_context, removing dependence on a
kmalloc along the way.
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>
Diffstat (limited to 'kernel/auditsc.c')
-rw-r--r-- | kernel/auditsc.c | 41 |
1 files changed, 12 insertions, 29 deletions
diff --git a/kernel/auditsc.c b/kernel/auditsc.c index 11078f32d13e..425a8939be1a 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c | |||
@@ -95,12 +95,6 @@ struct audit_aux_data { | |||
95 | /* Number of target pids per aux struct. */ | 95 | /* Number of target pids per aux struct. */ |
96 | #define AUDIT_AUX_PIDS 16 | 96 | #define AUDIT_AUX_PIDS 16 |
97 | 97 | ||
98 | struct audit_aux_data_execve { | ||
99 | struct audit_aux_data d; | ||
100 | int argc; | ||
101 | struct mm_struct *mm; | ||
102 | }; | ||
103 | |||
104 | struct audit_aux_data_pids { | 98 | struct audit_aux_data_pids { |
105 | struct audit_aux_data d; | 99 | struct audit_aux_data d; |
106 | pid_t target_pid[AUDIT_AUX_PIDS]; | 100 | pid_t target_pid[AUDIT_AUX_PIDS]; |
@@ -1144,20 +1138,19 @@ static int audit_log_single_execve_arg(struct audit_context *context, | |||
1144 | } | 1138 | } |
1145 | 1139 | ||
1146 | static void audit_log_execve_info(struct audit_context *context, | 1140 | static void audit_log_execve_info(struct audit_context *context, |
1147 | struct audit_buffer **ab, | 1141 | struct audit_buffer **ab) |
1148 | struct audit_aux_data_execve *axi) | ||
1149 | { | 1142 | { |
1150 | int i, len; | 1143 | int i, len; |
1151 | size_t len_sent = 0; | 1144 | size_t len_sent = 0; |
1152 | const char __user *p; | 1145 | const char __user *p; |
1153 | char *buf; | 1146 | char *buf; |
1154 | 1147 | ||
1155 | if (axi->mm != current->mm) | 1148 | if (context->execve.mm != current->mm) |
1156 | return; /* execve failed, no additional info */ | 1149 | return; /* execve failed, no additional info */ |
1157 | 1150 | ||
1158 | p = (const char __user *)axi->mm->arg_start; | 1151 | p = (const char __user *)current->mm->arg_start; |
1159 | 1152 | ||
1160 | audit_log_format(*ab, "argc=%d", axi->argc); | 1153 | audit_log_format(*ab, "argc=%d", context->execve.argc); |
1161 | 1154 | ||
1162 | /* | 1155 | /* |
1163 | * we need some kernel buffer to hold the userspace args. Just | 1156 | * we need some kernel buffer to hold the userspace args. Just |
@@ -1171,7 +1164,7 @@ static void audit_log_execve_info(struct audit_context *context, | |||
1171 | return; | 1164 | return; |
1172 | } | 1165 | } |
1173 | 1166 | ||
1174 | for (i = 0; i < axi->argc; i++) { | 1167 | for (i = 0; i < context->execve.argc; i++) { |
1175 | len = audit_log_single_execve_arg(context, ab, i, | 1168 | len = audit_log_single_execve_arg(context, ab, i, |
1176 | &len_sent, p, buf); | 1169 | &len_sent, p, buf); |
1177 | if (len <= 0) | 1170 | if (len <= 0) |
@@ -1274,6 +1267,9 @@ static void show_special(struct audit_context *context, int *call_panic) | |||
1274 | audit_log_format(ab, "fd=%d flags=0x%x", context->mmap.fd, | 1267 | audit_log_format(ab, "fd=%d flags=0x%x", context->mmap.fd, |
1275 | context->mmap.flags); | 1268 | context->mmap.flags); |
1276 | break; } | 1269 | break; } |
1270 | case AUDIT_EXECVE: { | ||
1271 | audit_log_execve_info(context, &ab); | ||
1272 | break; } | ||
1277 | } | 1273 | } |
1278 | audit_log_end(ab); | 1274 | audit_log_end(ab); |
1279 | } | 1275 | } |
@@ -1320,11 +1316,6 @@ static void audit_log_exit(struct audit_context *context, struct task_struct *ts | |||
1320 | 1316 | ||
1321 | switch (aux->type) { | 1317 | switch (aux->type) { |
1322 | 1318 | ||
1323 | case AUDIT_EXECVE: { | ||
1324 | struct audit_aux_data_execve *axi = (void *)aux; | ||
1325 | audit_log_execve_info(context, &ab, axi); | ||
1326 | break; } | ||
1327 | |||
1328 | case AUDIT_BPRM_FCAPS: { | 1319 | case AUDIT_BPRM_FCAPS: { |
1329 | struct audit_aux_data_bprm_fcaps *axs = (void *)aux; | 1320 | struct audit_aux_data_bprm_fcaps *axs = (void *)aux; |
1330 | audit_log_format(ab, "fver=%x", axs->fcap_ver); | 1321 | audit_log_format(ab, "fver=%x", axs->fcap_ver); |
@@ -2147,21 +2138,13 @@ void __audit_ipc_set_perm(unsigned long qbytes, uid_t uid, gid_t gid, umode_t mo | |||
2147 | context->ipc.has_perm = 1; | 2138 | context->ipc.has_perm = 1; |
2148 | } | 2139 | } |
2149 | 2140 | ||
2150 | int __audit_bprm(struct linux_binprm *bprm) | 2141 | void __audit_bprm(struct linux_binprm *bprm) |
2151 | { | 2142 | { |
2152 | struct audit_aux_data_execve *ax; | ||
2153 | struct audit_context *context = current->audit_context; | 2143 | struct audit_context *context = current->audit_context; |
2154 | 2144 | ||
2155 | ax = kmalloc(sizeof(*ax), GFP_KERNEL); | 2145 | context->type = AUDIT_EXECVE; |
2156 | if (!ax) | 2146 | context->execve.argc = bprm->argc; |
2157 | return -ENOMEM; | 2147 | context->execve.mm = bprm->mm; |
2158 | |||
2159 | ax->argc = bprm->argc; | ||
2160 | ax->mm = bprm->mm; | ||
2161 | ax->d.type = AUDIT_EXECVE; | ||
2162 | ax->d.next = context->aux; | ||
2163 | context->aux = (void *)ax; | ||
2164 | return 0; | ||
2165 | } | 2148 | } |
2166 | 2149 | ||
2167 | 2150 | ||