Article View: linux.kernel.netdev
Article #7412[PATCH 1/8] lsm: always call the namespace_free hook
From: Christian Brauner
Date: Mon, 26 Oct 2026 09:57
Date: Mon, 26 Oct 2026 09:57
59 lines
10706 bytes
10706 bytes
security_namespace_free() returns early if ns->ns_security is NULL and
skips the namespace_free hook. But ns->ns_security is only allocated if
an LSM requests a namespace blob via lbs_ns and currently no LSM does.
So the namespace_free hook is never called at all.
Landlock only uses namespace_init and namespace_install so it doesn't
care. But the bpf LSM attaches to every hook and a program attached to
namespace_free never runs. We want to use it in systemd-nsresourced to
get notified when a user namespace goes away. Right now it has to kprobe
retire_userns_sysctls() for that.
Note that a bpf program can't work around this. The size of the
namespace blob is fixed at boot and the bpf LSM doesn't request one.
And security_namespace_init() allocates the blob before the
namespace_init hooks are called anyway.
The check isn't needed. __ns_common_free() is only ever called after
__ns_common_init() succeeded and security_namespace_init() only calls
security_namespace_free() after the blob has been allocated. So if an
LSM requests a namespace blob it is always there when the hook runs.
Call the hook unconditionally like security_sb_free(),
security_file_free() and security_bpf_map_free() do.
The bpf LSM attaches programs to its bpf_lsm_*() stubs so fentry on the
stubs shows what a bpf LSM program sees. Booted with lsm.debug, which
prints "LSM: blob(ns) size 0", and created 100 user and uts namespaces:
bpftrace -e 'fentry:bpf_lsm_namespace_init { @init = count(); }
fentry:bpf_lsm_namespace_free { @free = count(); }' &
for i in $(seq 100); do unshare -Uu true; done
before: @init: 200 @free: 0
after: @init: 200 @free: 200
Fixes: f675d2e95569 ("lsm: add LSM blob and hooks for namespaces")
Cc: <stable@kernel.org> # mainline only
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
---
security/security.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/security/security.c b/security/security.c
index f6583d507395..1e76c097b28d 100644
--- a/security/security.c
+++ b/security/security.c
@@ -3412,9 +3412,6 @@ int security_namespace_init(struct ns_common *ns)
*/
void security_namespace_free(struct ns_common *ns)
{
- if (!ns->ns_security)
- return;
-
call_void_hook(namespace_free, ns);
kfree(ns->ns_security);
--
2.53.0
Technical Details
Message-ID:
<20261026-work-security-namespace_free-v1-1-ffa3ebbf71bd@kernel.org>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-351807-linux-kernel-netdev=dewy.ruReferences:
<20261026-work-security-namespace_free-v1-0-ffa3ebbf71bd@kernel.org>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-351807-linux-kernel-netdev=dewy.ru From: brauner@kernel.org (Christian Brauner) Newsgroups: linux.kernel.netdev Subject: [PATCH 1/8] lsm: always call the namespace_free hook Date: Mon, 26 Oct 2026 10:57:09 +0100 Organization: Usenet Network Message-ID: <20261026-work-security-namespace_free-v1-1-ffa3ebbf71bd@kernel.org> References: <20261026-work-security-namespace_free-v1-0-ffa3ebbf71bd@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Injection-Info: usenet.network; logging-data="1276311"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:RpQG3go8Xz8oQDVpoO9rtM9O3mY= sha256:D/ijz36JpdsgmpsHPwhh+Y8O9cCJiQAC6RWnjAtMKQk= sha1:El26nt50AwRf35oyyZOVHlocU74= sha256:XvuNx2USrJ+xDIj5kY6hQ7jvfhxhtNTx0BbGzyyCknc= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 53CEE125B98; Mon, 26 Oct 2026 12:59:46 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.739 X-Spam-Status: No, score=-3.739 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.339, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id CorPiV6Il-hC; Mon, 26 Oct 2026 12:59:43 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-351807-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4]) by mail.dewy.ru (Postfix) with ESMTPS id 9E07F125B96; Mon, 26 Oct 2026 12:59:33 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sin.lore.kernel.org (Postfix) with ESMTP id 4E22225EAB; Mon, 26 Oct 2026 09:57:38 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1793008651; b=GbVugLTGC4TW/LCvEDUuNNVs4tTwAPBQj/dtcrLS0NJEqsJqMjzkFO5JSX3b33b9Owon /ScZFKxOvXFBJuHESrPO9s6sl8rRof2EhKPTOWSdYI3VxO4w+ImA2u7+uevLTKC77ntBb P6Owfn/awpcmgtYP5xf1B2pyyI2lIg2CB+sXnO33tnwuNetYTis+WOPjmpBMtBuG+norm ab/XLLAiHj9opg8vPc/sN7/S58fntW5YpJtbgtDtepJPvi+3zHM9m+57X/+EnD3F23BiH fVVwY/OCDkdI70hPmsvGGn6hF1FIzebVHy0N3VerITde81Ld3uAvJzOELjNGCens/sg== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793008651; h=X-Original-To:Received:Received:DKIM-Signature:From:Date:Subject: X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe: List-Unsubscribe:List-Owner:Precedence:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=vZbI+36cuLWKSblKMENitfEJ+yoA6aEpBQf4/oO9DlE=; b=gr9db3N48OgLMo3SsGWnOl1Tcf+td0tiQMVwxjczlx2D/+wdoLByd3ndG+zj5eO9eNF+ IFnr+7KavG92lahk/eDX1FKLXKeqClUI0dKKN8vjJwYuILDDDb8wMTau+s1Lz07yX574l yS/YkuQNHMY5fLpVv0VfklF4sQhesPO4qRXT/XLSVdJrgkfFktNoHGkiP2sCg2zvQkMfV cxRO2+t/Dfj2tC8pKCca5y7vO13tWeM0nNQv6l56I7TGZi8ttDosYEWGymuyT7OYUOzUE FXQfBoQXLB09FvBHnhLuA7aFQLKX5JFue3aMHIxuGKZV/Azj2YbhTVUR+eLRsYMN7BA== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=o0Sq3nJa; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9427F606A32A; Mon, 26 Oct 2026 09:57:31 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=o0Sq3nJa X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793008650; b=SFI4gzH+S+pfZJTepDLgx7NEMse3I3Q8GywJ62m1qyJ8Vmk8lM88B0Wzhs5hHdVD1YbN QGVN+Mjs+msiwRPKYJpSutPgmVwJsZ0wH67DjDEiuoTA2JlRjm5xh8iznmAn9jT/Btx4R wkEZPS3wC47LnUBQXqN38ZcvmbARSygu3xmR0XnEfsW07OJR9h4bMSQ6/f4/BRq0su5mT bL79L+VaqlF2unTBY0S3Gd9PubFzutHjkTiA0MLr+9vgsC+QBZuMI7U8ofBovpmWWYVTa rOuSmLILprhHyd7woDSWdkil+ZXTQvo2gT1YIRar9abw443dPHMx4VZYlXdlw/vfbpg== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793008650; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=vZbI+36cuLWKSblKMENitfEJ+yoA6aEpBQf4/oO9DlE=; b=mwAqnBODCUonBlxs2hnBIE6zpbvHUOPWFiR+lx5vGLqx0D86MsrVoLKw0TYLG6Nw7tel il3VZYmMXkTWaui/xx981q2qPTeJghdubzmiBIkiZPLy7e9c0duejNjjKY1JiR5mtdqio t5JI6m/pCnbI82kuJWQk0HZwc28oJjtKvN8Y5GJfaNoO5uWADmsAfI+i0wSQSIVdm2uBg FDYauXAQCxnBVU4mb6aMKm0HUA2cdpGUfP8+ONxTlg5ESp2qXnuS7Lhvz5hldWRrZNEr3 TOpKOGSwRZKxeCGGH4vzWKJPJcjsOaZhoI20pXH99Am3KRNpKwUIlhIGF/e25scXXnw== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=o0Sq3nJa; arc=none smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 778FA606A31A; Mon, 26 Oct 2026 09:57:30 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id DBCF11F01829; Mon, 26 Oct 2026 09:57:27 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1793008650; bh=vZbI+36cuLWKSblKMENitfEJ+yoA6aEpBQf4/oO9DlE=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=o0Sq3nJaIGTrjslbLGLcqnd8GPwnDlz0xCnvjLEp0i/i+axxAaa035NKi395WU1Xg hDRVsuKGFDY2xbAsWfPHhhMUD+tmWCaGPykq6pdC4Jv4CeiwtNrQWXl15NqOYWFUGz kVRrjJWt9BCAfaqEd2Fxkz7FDmeS3LY60h66pvafTuDyTJaljvKsvPN8BJ/5CflJja BM8jHg/Em2FadQNsECWj6rWK8zTGh7w6lnh65LE2xpkG+hhcg9XMiOqj/a3F0p7Y9b OzHrg72jVKoAGT+iqyNNyLA58AIx1hvy50oRqPVigC305acGqMwORQ6ze9gyA2BChR 1UJwGe1/aVDKg== X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list X-In-Reply-To: <20261026-work-security-namespace_free-v1-0-ffa3ebbf71bd@kernel.org> X-Cc: linux-security-module@vger.kernel.org, Alexei Starovoitov <ast@kernel.org>, Daniel Borkmann <daniel@iogearbox.net>, Paul Moore <paul@paul-moore.com>, netdev@vger.kernel.org, "Christian Brauner (Amutable)" <brauner@kernel.org>, stable@kernel.org X-Mailer: b4 0.17-dev-ce4c1 X-Developer-Signature: v=1; a=openpgp-sha256; l=2360; i=brauner@kernel.org; h=from:subject:message-id; bh=C2BO3VYPrmNUuuCqz/uwcSrR57rLhf95j9OE/k19Z48=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMWTdV2HKM6t3aJrDJvJ0gWz+3FfXjLVifxb81lUQOB1/c uNLlXuzOkpZGMS4GGTFFFkc2k3C5ZbzVGw2ytSAmcPKBDKEgYtTACaSXcLIsMejKkgs42SX19mI LT8DHmR19y9fpGErbcz580FnEWNHACPDsp479mV/mX2CXY+V3PvKeeqbbPy6Pxfy8+L4ZDpPla7 mBgA= X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624