Commit e68b75a027bb94066576139ee33676264f867b87
Committed by
James Morris
1 parent
3fc689e96c
Exists in
master
and in
4 other branches
When the capset syscall is used it is not possible for audit to record the
actual capbilities being added/removed. This patch adds a new record type which emits the target pid and the eff, inh, and perm cap sets. example output if you audit capset syscalls would be: type=SYSCALL msg=audit(1225743140.465:76): arch=c000003e syscall=126 success=yes exit=0 a0=17f2014 a1=17f201c a2=80000000 a3=7fff2ab7f060 items=0 ppid=2160 pid=2223 auid=0 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts0 ses=1 comm="setcap" exe="/usr/sbin/setcap" subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key=(null) type=UNKNOWN[1322] msg=audit(1225743140.465:76): pid=0 cap_pi=ffffffffffffffff cap_pp=ffffffffffffffff cap_pe=ffffffffffffffff Signed-off-by: Eric Paris <eparis@redhat.com> Acked-by: Serge Hallyn <serue@us.ibm.com> Signed-off-by: James Morris <jmorris@namei.org>
Showing 3 changed files with 63 additions and 0 deletions Side-by-side Diff
include/linux/audit.h
... | ... | @@ -100,6 +100,7 @@ |
100 | 100 | #define AUDIT_TTY 1319 /* Input on an administrative TTY */ |
101 | 101 | #define AUDIT_EOE 1320 /* End of multi-record event */ |
102 | 102 | #define AUDIT_BPRM_FCAPS 1321 /* Information about fcaps increasing perms */ |
103 | +#define AUDIT_CAPSET 1322 /* Record showing argument to sys_capset */ | |
103 | 104 | |
104 | 105 | #define AUDIT_AVC 1400 /* SE Linux avc denial or grant */ |
105 | 106 | #define AUDIT_SELINUX_ERR 1401 /* Internal SE Linux Errors */ |
... | ... | @@ -454,6 +455,7 @@ |
454 | 455 | extern int __audit_mq_notify(mqd_t mqdes, const struct sigevent __user *u_notification); |
455 | 456 | extern int __audit_mq_getsetattr(mqd_t mqdes, struct mq_attr *mqstat); |
456 | 457 | extern void __audit_log_bprm_fcaps(struct linux_binprm *bprm, kernel_cap_t *pP, kernel_cap_t *pE); |
458 | +extern int __audit_log_capset(pid_t pid, kernel_cap_t *eff, kernel_cap_t *inh, kernel_cap_t *perm); | |
457 | 459 | |
458 | 460 | static inline int audit_ipc_obj(struct kern_ipc_perm *ipcp) |
459 | 461 | { |
... | ... | @@ -526,6 +528,13 @@ |
526 | 528 | __audit_log_bprm_fcaps(bprm, pP, pE); |
527 | 529 | } |
528 | 530 | |
531 | +static inline int audit_log_capset(pid_t pid, kernel_cap_t *eff, kernel_cap_t *inh, kernel_cap_t *perm) | |
532 | +{ | |
533 | + if (unlikely(!audit_dummy_context())) | |
534 | + return __audit_log_capset(pid, eff, inh, perm); | |
535 | + return 0; | |
536 | +} | |
537 | + | |
529 | 538 | extern int audit_n_rules; |
530 | 539 | extern int audit_signals; |
531 | 540 | #else |
... | ... | @@ -558,6 +567,7 @@ |
558 | 567 | #define audit_mq_notify(d,n) ({ 0; }) |
559 | 568 | #define audit_mq_getsetattr(d,s) ({ 0; }) |
560 | 569 | #define audit_log_bprm_fcaps(b, p, e) do { ; } while (0) |
570 | +#define audit_log_capset(pid, e, i, p) ({ 0; }) | |
561 | 571 | #define audit_ptrace(t) ((void)0) |
562 | 572 | #define audit_n_rules 0 |
563 | 573 | #define audit_signals 0 |
kernel/auditsc.c
... | ... | @@ -204,6 +204,12 @@ |
204 | 204 | struct audit_cap_data new_pcap; |
205 | 205 | }; |
206 | 206 | |
207 | +struct audit_aux_data_capset { | |
208 | + struct audit_aux_data d; | |
209 | + pid_t pid; | |
210 | + struct audit_cap_data cap; | |
211 | +}; | |
212 | + | |
207 | 213 | struct audit_tree_refs { |
208 | 214 | struct audit_tree_refs *next; |
209 | 215 | struct audit_chunk *c[31]; |
... | ... | @@ -1397,6 +1403,14 @@ |
1397 | 1403 | audit_log_cap(ab, "new_pe", &axs->new_pcap.effective); |
1398 | 1404 | break; } |
1399 | 1405 | |
1406 | + case AUDIT_CAPSET: { | |
1407 | + struct audit_aux_data_capset *axs = (void *)aux; | |
1408 | + audit_log_format(ab, "pid=%d", axs->pid); | |
1409 | + audit_log_cap(ab, "cap_pi", &axs->cap.inheritable); | |
1410 | + audit_log_cap(ab, "cap_pp", &axs->cap.permitted); | |
1411 | + audit_log_cap(ab, "cap_pe", &axs->cap.effective); | |
1412 | + break; } | |
1413 | + | |
1400 | 1414 | } |
1401 | 1415 | audit_log_end(ab); |
1402 | 1416 | } |
... | ... | @@ -2567,6 +2581,40 @@ |
2567 | 2581 | ax->new_pcap.permitted = current->cap_permitted; |
2568 | 2582 | ax->new_pcap.inheritable = current->cap_inheritable; |
2569 | 2583 | ax->new_pcap.effective = current->cap_effective; |
2584 | +} | |
2585 | + | |
2586 | +/** | |
2587 | + * __audit_log_capset - store information about the arguments to the capset syscall | |
2588 | + * @pid target pid of the capset call | |
2589 | + * @eff effective cap set | |
2590 | + * @inh inheritible cap set | |
2591 | + * @perm permited cap set | |
2592 | + * | |
2593 | + * Record the aguments userspace sent to sys_capset for later printing by the | |
2594 | + * audit system if applicable | |
2595 | + */ | |
2596 | +int __audit_log_capset(pid_t pid, kernel_cap_t *eff, kernel_cap_t *inh, kernel_cap_t *perm) | |
2597 | +{ | |
2598 | + struct audit_aux_data_capset *ax; | |
2599 | + struct audit_context *context = current->audit_context; | |
2600 | + | |
2601 | + if (likely(!audit_enabled || !context || context->dummy)) | |
2602 | + return 0; | |
2603 | + | |
2604 | + ax = kmalloc(sizeof(*ax), GFP_KERNEL); | |
2605 | + if (!ax) | |
2606 | + return -ENOMEM; | |
2607 | + | |
2608 | + ax->d.type = AUDIT_CAPSET; | |
2609 | + ax->d.next = context->aux; | |
2610 | + context->aux = (void *)ax; | |
2611 | + | |
2612 | + ax->pid = pid; | |
2613 | + ax->cap.effective = *eff; | |
2614 | + ax->cap.inheritable = *eff; | |
2615 | + ax->cap.permitted = *perm; | |
2616 | + | |
2617 | + return 0; | |
2570 | 2618 | } |
2571 | 2619 | |
2572 | 2620 | /** |
kernel/capability.c
... | ... | @@ -7,6 +7,7 @@ |
7 | 7 | * 30 May 2002: Cleanup, Robert M. Love <rml@tech9.net> |
8 | 8 | */ |
9 | 9 | |
10 | +#include <linux/audit.h> | |
10 | 11 | #include <linux/capability.h> |
11 | 12 | #include <linux/mm.h> |
12 | 13 | #include <linux/module.h> |
... | ... | @@ -467,6 +468,10 @@ |
467 | 468 | inheritable.cap[i] = 0; |
468 | 469 | i++; |
469 | 470 | } |
471 | + | |
472 | + ret = audit_log_capset(pid, &effective, &inheritable, &permitted); | |
473 | + if (ret) | |
474 | + return ret; | |
470 | 475 | |
471 | 476 | if (pid && (pid != task_pid_vnr(current))) |
472 | 477 | ret = do_sys_capset_other_tasks(pid, &effective, &inheritable, |