Skip to content

Commit 2fec30e

Browse files
rgbriggspcmoore
authored andcommitted
audit: add support for fcaps v3
V3 namespaced file capabilities were introduced in commit 8db6c34 ("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 linux-audit/audit-kernel#103 Signed-off-by: Richard Guy Briggs <rgb@redhat.com> Acked-by: Serge Hallyn <serge@hallyn.com> [PM: comment tweak to fit an 80 char line width] Signed-off-by: Paul Moore <paul@paul-moore.com>
1 parent 4b7d248 commit 2fec30e

5 files changed

Lines changed: 14 additions & 4 deletions

File tree

‎include/linux/capability.h‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
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 {
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‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2084,8 +2084,9 @@ static void audit_log_fcaps(struct audit_buffer *ab, struct audit_names *name)
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,
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‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ struct audit_cap_data {
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‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,6 +1358,9 @@ static void audit_log_exit(void)
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,
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‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,8 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
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

0 commit comments

Comments
 (0)