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
Unified · Split
| @@ -14,7 +14,7 @@ · 13 unmodified lines | ||
| 14 | 14 | #define _LINUX_CAPABILITY_H |
| 15 | 15 | |
| 16 | 16 | #include <uapi/linux/capability.h> |
| 17 | − | |
| 17 | +#include <linux/uidgid.h> | |
| 18 | 18 | |
| 19 | 19 | #define _KERNEL_CAPABILITY_VERSION _LINUX_CAPABILITY_VERSION_3 |
| 20 | 20 | #define _KERNEL_CAPABILITY_U32S _LINUX_CAPABILITY_U32S_3 |
| @@ -25,11 +25,12 @@ typedef struct kernel_cap_struct { · 4 unmodified lines | ||
| 25 | 25 | __u32 cap[_KERNEL_CAPABILITY_U32S]; |
| 26 | 26 | } kernel_cap_t; |
| 27 | 27 | |
| 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 */ | |
| 29 | 29 | struct cpu_vfs_cap_data { |
| 30 | 30 | __u32 magic_etc; |
| 31 | 31 | kernel_cap_t permitted; |
| 32 | 32 | kernel_cap_t inheritable; |
| 33 | + kuid_t rootid; | |
| 33 | 34 | }; |
| 34 | 35 | |
| 35 | 36 | #define _USER_CAP_HEADER_SIZE (sizeof(struct __user_cap_header_struct)) |
| @@ -2084,8 +2084,9 @@ static void audit_log_fcaps(struct audit_buffer *ab, struct audit_names *name) · 2083 unmodified lines | ||
| 2084 | 2084 | { |
| 2085 | 2085 | audit_log_cap(ab, "cap_fp", &name->fcap.permitted); |
| 2086 | 2086 | 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)); | |
| 2089 | 2090 | } |
| 2090 | 2091 | |
| 2091 | 2092 | 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 | ||
| 2104 | 2105 | name->fcap.permitted = caps.permitted; |
| 2105 | 2106 | name->fcap.inheritable = caps.inheritable; |
| 2106 | 2107 | name->fcap.fE = !!(caps.magic_etc & VFS_CAP_FLAGS_EFFECTIVE); |
| 2108 | + name->fcap.rootid = caps.rootid; | |
| 2107 | 2109 | name->fcap_ver = (caps.magic_etc & VFS_CAP_REVISION_MASK) >> |
| 2108 | 2110 | VFS_CAP_REVISION_SHIFT; |
| 2109 | 2111 | |
| @@ -69,6 +69,7 @@ struct audit_cap_data { · 68 unmodified lines | ||
| 69 | 69 | kernel_cap_t effective; /* effective set of process */ |
| 70 | 70 | }; |
| 71 | 71 | kernel_cap_t ambient; |
| 72 | + kuid_t rootid; | |
| 72 | 73 | }; |
| 73 | 74 | |
| 74 | 75 | /* When fs/namei.c:getname() is called, we store the pointer in name and bump |
| @@ -1358,6 +1358,9 @@ static void audit_log_exit(void) · 1357 unmodified lines | ||
| 1358 | 1358 | audit_log_cap(ab, "pi", &axs->new_pcap.inheritable); |
| 1359 | 1359 | audit_log_cap(ab, "pe", &axs->new_pcap.effective); |
| 1360 | 1360 | 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)); | |
| 1361 | 1364 | break; } |
| 1362 | 1365 | |
| 1363 | 1366 | } |
| @@ -2271,6 +2274,7 @@ int __audit_log_bprm_fcaps(struct linux_binprm *bprm, · 907 unmodified lines | ||
| 2271 | 2274 | ax->fcap.permitted = vcaps.permitted; |
| 2272 | 2275 | ax->fcap.inheritable = vcaps.inheritable; |
| 2273 | 2276 | ax->fcap.fE = !!(vcaps.magic_etc & VFS_CAP_FLAGS_EFFECTIVE); |
| 2277 | + ax->fcap.rootid = vcaps.rootid; | |
| 2274 | 2278 | ax->fcap_ver = (vcaps.magic_etc & VFS_CAP_REVISION_MASK) >> VFS_CAP_REVISION_SHIFT; |
| 2275 | 2279 | |
| 2276 | 2280 | ax->old_pcap.permitted = old->cap_permitted; |
| @@ -643,6 +643,8 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data · 642 unmodified lines | ||
| 643 | 643 | cpu_caps->permitted.cap[CAP_LAST_U32] &= CAP_LAST_U32_VALID_MASK; |
| 644 | 644 | cpu_caps->inheritable.cap[CAP_LAST_U32] &= CAP_LAST_U32_VALID_MASK; |
| 645 | 645 | |
| 646 | + cpu_caps->rootid = rootkuid; | |
| 647 | + | |
| 646 | 648 | return 0; |
| 647 | 649 | } |
| 648 | 650 | |