Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selinux: Implement userns_create hook

Unprivileged user namespace creation is an intended feature to enable
sandboxing, however this feature is often used to as an initial step to
perform a privilege escalation attack.

This patch implements a new user_namespace { create } access control
permission to restrict which domains allow or deny user namespace
creation. This is necessary for system administrators to quickly protect
their systems while waiting for vulnerability patches to be applied.

This permission can be used in the following way:

allow domA_t domA_t : user_namespace { create };

Signed-off-by: Frederick Lawler <fred@cloudflare.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>

authored by

Frederick Lawler and committed by
Paul Moore
ed5d44d4 d5810139

+11
+9
security/selinux/hooks.c
··· 4221 4221 spin_unlock(&isec->lock); 4222 4222 } 4223 4223 4224 + static int selinux_userns_create(const struct cred *cred) 4225 + { 4226 + u32 sid = current_sid(); 4227 + 4228 + return avc_has_perm(&selinux_state, sid, sid, SECCLASS_USER_NAMESPACE, 4229 + USER_NAMESPACE__CREATE, NULL); 4230 + } 4231 + 4224 4232 /* Returns error only if unable to parse addresses */ 4225 4233 static int selinux_parse_skb_ipv4(struct sk_buff *skb, 4226 4234 struct common_audit_data *ad, u8 *proto) ··· 7119 7111 LSM_HOOK_INIT(task_movememory, selinux_task_movememory), 7120 7112 LSM_HOOK_INIT(task_kill, selinux_task_kill), 7121 7113 LSM_HOOK_INIT(task_to_inode, selinux_task_to_inode), 7114 + LSM_HOOK_INIT(userns_create, selinux_userns_create), 7122 7115 7123 7116 LSM_HOOK_INIT(ipc_permission, selinux_ipc_permission), 7124 7117 LSM_HOOK_INIT(ipc_getsecid, selinux_ipc_getsecid),
+2
security/selinux/include/classmap.h
··· 254 254 { COMMON_FILE_PERMS, NULL } }, 255 255 { "io_uring", 256 256 { "override_creds", "sqpoll", NULL } }, 257 + { "user_namespace", 258 + { "create", NULL } }, 257 259 { NULL } 258 260 }; 259 261