summaryrefslogtreecommitdiff
path: root/include/linux/stackprotector.h
diff options
context:
space:
mode:
authorChristian Brauner <brauner@kernel.org>2026-10-29 17:40:59 +0100
committerChristian Brauner <brauner@kernel.org>2026-11-11 12:26:08 +0100
commit08471914d6bb24493b75bb03701548133d617878 (patch)
tree92335cd8bddc27b6a43e74846153f57dbde9fd8f /include/linux/stackprotector.h
parentea8c4b37b8809da104c4a871bb81d20465bf67b2 (diff)
ns: allocate the namespace id before the namespace_init hook
Currently the namespace id is allocated only after __ns_common_init() has called the namespace_init LSM hook. Most namespace types allocate it in ns_tree_add() right before the namespace is added to the namespace trees. So the namespace_init hook always sees an id of zero. The namespace id is the only identifier of a namespace that is never recycled. A bpf LSM wants to use it to track a namespace from namespace_init until namespace_free, e.g., by using it as the key into a map that associates data with the namespace. The inode number doesn't work for that as it is quickly recycled. So allocate the id in __ns_common_init() before calling the namespace_init hook. Every namespace then has its id by the time it is added to the namespace trees. The initial namespaces still get their fixed ids, either statically from NS_COMMON_INIT() or for init_net from ns_common_init(). So ns_tree_add() doesn't need to allocate an id anymore. Ids are still handed out in creation order so mnt_ns_loop() keeps working. Mount and ipc namespaces already allocated their id right after ns_common_init() anyway. If creating the namespace fails after the id has been allocated the id is simply never used. Landlock logs the namespace id when it denies the use of a namespace. For a denied namespace creation that used to be zero. Now it's the id that was allocated for the new namespace. That namespace never becomes visible to userspace but it's the same id that other LSMs see in namespace_init. Update the Landlock documentation and selftests accordingly. The selftests can't know the id of a namespace whose creation was denied so they only check that it isn't zero. While at it, drop ns_tree_gen_id() as it has no users left. Reproducer, 100 user and uts namespaces: bpftrace -e 'fentry:bpf_lsm_namespace_init { @[args.ns->ns_id ? "set" : "zero"] = count(); }' & for i in $(seq 100); do unshare -Uu true; done before: @[zero]: 200 after: @[set]: 200 Fixes: f675d2e95569 ("lsm: add LSM blob and hooks for namespaces") Cc: stable@kernel.org # mainline only Link: https://patch.msgid.link/20261029-work-security-namespace_free-v2-4-65591dbba7b3@kernel.org Reviewed-by: Mickaël Salaün <mic@digikod.net> # Landlock changes Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Diffstat (limited to 'include/linux/stackprotector.h')
0 files changed, 0 insertions, 0 deletions