History

audit: add support for fcaps v3

V3 namespaced file capabilities were introduced in commit 8db6c34f1dbc ("Introduce v3 namespaced file capabilities") Add support for these by adding the "frootid" field to the existing fcaps fields in the NAME and BPRM_FCAPS records. Please see github issue https://github.com/linux-audit/audit-kernel/issues/103

Richard Guy Briggs committed 7 years ago

Commit 2fec30e1 parent 4b7d2485 files · +14 −4Browse files

Unified · Split

5 files
  1. include/linux/capability.h +3 −2
  2. kernel/audit.c +4 −2
  3. kernel/audit.h +1 −0
  4. kernel/auditsc.c +4 −0
  5. security/commoncap.c +2 −0
include/linux/capability.h+3−2
@@ -14,7 +14,7 @@ · 13 unmodified lines
1414 #define _LINUX_CAPABILITY_H
1515
1616 #include <uapi/linux/capability.h>
17−
17+#include <linux/uidgid.h>
1818
1919 #define _KERNEL_CAPABILITY_VERSION _LINUX_CAPABILITY_VERSION_3
2020 #define _KERNEL_CAPABILITY_U32S _LINUX_CAPABILITY_U32S_3
@@ -25,11 +25,12 @@ typedef struct kernel_cap_struct { · 4 unmodified lines
2525 __u32 cap[_KERNEL_CAPABILITY_U32S];
2626 } kernel_cap_t;
2727
28−/* exact same as vfs_cap_data but in cpu endian and always filled completely */
28+/* same as vfs_ns_cap_data but in cpu endian and always filled completely */
2929 struct cpu_vfs_cap_data {
3030 __u32 magic_etc;
3131 kernel_cap_t permitted;
3232 kernel_cap_t inheritable;
33+ kuid_t rootid;
3334 };
3435
3536 #define _USER_CAP_HEADER_SIZE (sizeof(struct __user_cap_header_struct))
kernel/audit.c+4−2
@@ -2084,8 +2084,9 @@ static void audit_log_fcaps(struct audit_buffer *ab, struct audit_names *name) · 2083 unmodified lines
20842084 {
20852085 audit_log_cap(ab, "cap_fp", &name->fcap.permitted);
20862086 audit_log_cap(ab, "cap_fi", &name->fcap.inheritable);
2087− audit_log_format(ab, " cap_fe=%d cap_fver=%x",
2088− name->fcap.fE, name->fcap_ver);
2087+ audit_log_format(ab, " cap_fe=%d cap_fver=%x cap_frootid=%d",
2088+ name->fcap.fE, name->fcap_ver,
2089+ from_kuid(&init_user_ns, name->fcap.rootid));
20892090 }
20902091
20912092 static inline int audit_copy_fcaps(struct audit_names *name,
@@ -2104,6 +2105,7 @@ static inline int audit_copy_fcaps(struct audit_names *name, · 12 unmodified lines
21042105 name->fcap.permitted = caps.permitted;
21052106 name->fcap.inheritable = caps.inheritable;
21062107 name->fcap.fE = !!(caps.magic_etc & VFS_CAP_FLAGS_EFFECTIVE);
2108+ name->fcap.rootid = caps.rootid;
21072109 name->fcap_ver = (caps.magic_etc & VFS_CAP_REVISION_MASK) >>
21082110 VFS_CAP_REVISION_SHIFT;
21092111
kernel/audit.h+1−0
@@ -69,6 +69,7 @@ struct audit_cap_data { · 68 unmodified lines
6969 kernel_cap_t effective; /* effective set of process */
7070 };
7171 kernel_cap_t ambient;
72+ kuid_t rootid;
7273 };
7374
7475 /* When fs/namei.c:getname() is called, we store the pointer in name and bump
kernel/auditsc.c+4−0
@@ -1358,6 +1358,9 @@ static void audit_log_exit(void) · 1357 unmodified lines
13581358 audit_log_cap(ab, "pi", &axs->new_pcap.inheritable);
13591359 audit_log_cap(ab, "pe", &axs->new_pcap.effective);
13601360 audit_log_cap(ab, "pa", &axs->new_pcap.ambient);
1361+ audit_log_format(ab, " frootid=%d",
1362+ from_kuid(&init_user_ns,
1363+ axs->fcap.rootid));
13611364 break; }
13621365
13631366 }
@@ -2271,6 +2274,7 @@ int __audit_log_bprm_fcaps(struct linux_binprm *bprm, · 907 unmodified lines
22712274 ax->fcap.permitted = vcaps.permitted;
22722275 ax->fcap.inheritable = vcaps.inheritable;
22732276 ax->fcap.fE = !!(vcaps.magic_etc & VFS_CAP_FLAGS_EFFECTIVE);
2277+ ax->fcap.rootid = vcaps.rootid;
22742278 ax->fcap_ver = (vcaps.magic_etc & VFS_CAP_REVISION_MASK) >> VFS_CAP_REVISION_SHIFT;
22752279
22762280 ax->old_pcap.permitted = old->cap_permitted;
security/commoncap.c+2−0
@@ -643,6 +643,8 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data · 642 unmodified lines
643643 cpu_caps->permitted.cap[CAP_LAST_U32] &= CAP_LAST_U32_VALID_MASK;
644644 cpu_caps->inheritable.cap[CAP_LAST_U32] &= CAP_LAST_U32_VALID_MASK;
645645
646+ cpu_caps->rootid = rootkuid;
647+
646648 return 0;
647649 }
648650

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t