[PATCH v2 03/25] capability: add static asserts for comapatibility of vfs_cap_data and vfs_ns_cap_data

From: Seth Forshee (DigitalOcean)
Date: Wed Feb 21 2024 - 16:26:36 EST


Capability code depends on vfs_ns_cap_data being an extension of
vfs_cap_data, so verify this at compile time.

Suggested-by: Christian Brauner <brauner@xxxxxxxxxx>
Signed-off-by: Seth Forshee (DigitalOcean) <sforshee@xxxxxxxxxx>
---
include/uapi/linux/capability.h | 13 +++++++++++++
1 file changed, 13 insertions(+)

diff --git a/include/uapi/linux/capability.h b/include/uapi/linux/capability.h
index 5bb906098697..0fd75aab9754 100644
--- a/include/uapi/linux/capability.h
+++ b/include/uapi/linux/capability.h
@@ -16,6 +16,10 @@

#include <linux/types.h>

+#ifdef __KERNEL__
+#include <linux/build_bug.h>
+#endif
+
/* User-level do most of the mapping between kernel and user
capabilities based on the version tag given by the kernel. The
kernel might be somewhat backwards compatible, but don't bet on
@@ -100,6 +104,15 @@ struct vfs_ns_cap_data {
#define _LINUX_CAPABILITY_VERSION _LINUX_CAPABILITY_VERSION_1
#define _LINUX_CAPABILITY_U32S _LINUX_CAPABILITY_U32S_1

+#else
+
+static_assert(offsetof(struct vfs_cap_data, magic_etc) ==
+ offsetof(struct vfs_ns_cap_data, magic_etc));
+static_assert(offsetof(struct vfs_cap_data, data) ==
+ offsetof(struct vfs_ns_cap_data, data));
+static_assert(sizeof(struct vfs_cap_data) ==
+ offsetof(struct vfs_ns_cap_data, rootid));
+
#endif



--
2.43.0