Re: [RFC PATCH v5 20/25] security: Add rootns LSM hooks
From: Jarkko Sakkinen
Date: Sat Nov 21 2026 - 06:47:47 EST
On Sat, Nov 21, 2026 at 02:08:39AM +0200, Jarkko Sakkinen wrote:
> Security modules need visibility into root namespace creation, teardown,
> process entry, and container-wide signal delivery so policies can attach
> per-rootns security state and mediate operations on rootns file
> descriptors.
>
> Add lbs_rootns and rootns->security blob management alongside
> security_rootns_alloc(), security_rootns_free(), security_rootns_clone(),
> and security_rootns_kill().
>
> Co-developed-by: David Howells <dhowells@xxxxxxxxxx>
> Signed-off-by: David Howells <dhowells@xxxxxxxxxx>
> Signed-off-by: Jarkko Sakkinen <jarkko@xxxxxxxxxx>
> ---
> include/linux/lsm_hook_defs.h | 7 +++
> include/linux/lsm_hooks.h | 3 ++
> include/linux/rootns.h | 3 ++
> include/linux/security.h | 30 ++++++++++++
> kernel/rootns.c | 44 +++++++++++++-----
> security/lsm_init.c | 6 +++
> security/security.c | 86 +++++++++++++++++++++++++++++++++++
> 7 files changed, 167 insertions(+), 12 deletions(-)
>
> diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h
> index 87d9d06710cb..2cb90ddedc14 100644
> --- a/include/linux/lsm_hook_defs.h
> +++ b/include/linux/lsm_hook_defs.h
> @@ -480,3 +480,10 @@ LSM_HOOK(int, 0, bdev_alloc_security, struct block_device *bdev)
> LSM_HOOK(void, LSM_RET_VOID, bdev_free_security, struct block_device *bdev)
> LSM_HOOK(int, 0, bdev_setintegrity, struct block_device *bdev,
> enum lsm_integrity_type type, const void *value, size_t size)
> +
> +#ifdef CONFIG_ROOTNS
> +LSM_HOOK(int, 0, rootns_alloc, struct rootns *rootns, unsigned int flags)
> +LSM_HOOK(void, LSM_RET_VOID, rootns_free, struct rootns *rootns)
> +LSM_HOOK(int, 0, rootns_clone, struct rootns *rootns)
> +LSM_HOOK(int, 0, rootns_kill, struct rootns *rootns, int sig)
Rootns objects have a security model:
1. No embryonic state by design. Especially staircase initialization
contributes to this property.
2. Unshare logic is inverted. Right now ROOTNS_SHARE ioctl does not
exist right now but it is (obviously) doable.
3. Dead obvious and transparent LSM hooks. Really hard to get them
wrong.
4. We already know by experience that opaque fd-bound objects with
two-phase state machine (build, live) works. It's what make this
secure and policy-free implementatiion.
The choices how to do things with closures used in SGX driver are
translatable and they are also pretty well reviewed choices, given all
those years... I would put some weight on this too.
Br, Jarkko