@@ -208,6 +208,11 @@ static inline bool checkpoint_restore_ns_capable(struct user_namespace *ns)
ns_capable(ns, CAP_SYS_ADMIN);
}
+static inline bool block_admin_capable(void)
+{
+ return capable(CAP_BLOCK_ADMIN) || capable(CAP_SYS_ADMIN);
+}
+
/* audit system wants to get cap info from files as well */
int get_vfs_caps_from_disk(struct mnt_idmap *idmap,
const struct dentry *dentry,
@@ -417,7 +417,12 @@ struct vfs_ns_cap_data {
#define CAP_CHECKPOINT_RESTORE 40
-#define CAP_LAST_CAP CAP_CHECKPOINT_RESTORE
+/*
+ * Allow Persistent Reservations operations for block device
+ */
+#define CAP_BLOCK_ADMIN 41
+
+#define CAP_LAST_CAP CAP_BLOCK_ADMIN
#define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
@@ -28,9 +28,9 @@
#define COMMON_CAP2_PERMS "mac_override", "mac_admin", "syslog", \
"wake_alarm", "block_suspend", "audit_read", "perfmon", "bpf", \
- "checkpoint_restore"
+ "checkpoint_restore", "block_admin"
-#if CAP_LAST_CAP > CAP_CHECKPOINT_RESTORE
+#if CAP_LAST_CAP > CAP_BLOCK_ADMIN
#error New capability defined, please update COMMON_CAP2_PERMS.
#endif
Separated fine-grained capability CAP_BLOCK_ADMIN from CAP_SYS_ADMIN. For backward compatibility, the CAP_BLOCK_ADMIN capability is included within CAP_SYS_ADMIN. Some database products rely on shared storage to complete the write-once-read-multiple and write-multiple-read-multiple functions. When HA occurs, they rely on the PR (Persistent Reservations) protocol provided by the storage layer to manage block device permissions to ensure data correctness. CAP_SYS_ADMIN is required in the PR protocol implementation of existing block devices in the Linux kernel, which has too many sensitive permissions, which may lead to risks such as container escape. The kernel needs to provide more fine-grained permission management like CAP_NET_ADMIN to avoid online products directly relying on root to run. CAP_BLOCK_ADMIN can also provide support for other block device operations that require CAP_SYS_ADMIN capabilities in the future, ensuring that applications run with least privilege. Signed-off-by: Tianjia Zhang <tianjia.zhang@linux.alibaba.com> --- include/linux/capability.h | 5 +++++ include/uapi/linux/capability.h | 7 ++++++- security/selinux/include/classmap.h | 4 ++-- 3 files changed, 13 insertions(+), 3 deletions(-)