The bpf LSM marks the arguments of all hooks as trusted unless the hook is listed in untrusted_lsm_hooks. That list was added in commit c0c852dd1876 ("bpf: Do not mark certain LSM hook arguments as trusted") for hooks that are called on objects that are only partially set up or that are already on their way out. The namespace_init and namespace_free hooks are exactly that but they aren't listed. namespace_init is called from __ns_common_init() before the namespace has been set up. It isn't in the namespace trees yet and for all types but network namespaces even the owning user namespace isn't set yet. If any LSM rejects the namespace or if anything after ns_common_init() fails the namespace is freed right away without looking at its reference count. namespace_free is called from __ns_common_free() when the namespace is torn down or when its initialization failed. Currently there's no kfunc that takes a namespace. But once there is one, e.g., for namespace local storage, a program could take a reference to or create storage on a namespace that is about to be freed. So don't mark the arguments of these hooks as trusted. namespace_install is called with a reference to a fully set up namespace and stays trusted. Fixes: f675d2e95569 ("lsm: add LSM blob and hooks for namespaces") Cc: # mainline only Acked-by: Alexei Starovoitov Acked-by: Daniel Borkmann Tested-by: Daniel Borkmann Signed-off-by: Christian Brauner (Amutable) --- kernel/bpf/bpf_lsm.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/bpf/bpf_lsm.c b/kernel/bpf/bpf_lsm.c index f58dce888ff4..468e63dbd922 100644 --- a/kernel/bpf/bpf_lsm.c +++ b/kernel/bpf/bpf_lsm.c @@ -411,6 +411,8 @@ BTF_ID(func, bpf_lsm_bpf_map_free) BTF_ID(func, bpf_lsm_bpf_prog_free) BTF_ID(func, bpf_lsm_file_alloc_security) BTF_ID(func, bpf_lsm_file_free_security) +BTF_ID(func, bpf_lsm_namespace_init) +BTF_ID(func, bpf_lsm_namespace_free) #ifdef CONFIG_SECURITY_NETWORK BTF_ID(func, bpf_lsm_sk_alloc_security) BTF_ID(func, bpf_lsm_sk_free_security) -- 2.53.0