From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5010E606A322 for ; Sat, 5 Dec 2026 04:10:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=aGb8U9QR Received: by kanga.kvack.org (Postfix) id 17CA16B05B3; Fri, 4 Dec 2026 23:09:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 12CF26B05B6; Fri, 4 Dec 2026 23:09:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 01CEF6B05BD; Fri, 4 Dec 2026 23:09:54 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id C63F16B05B3 for ; Fri, 4 Dec 2026 23:09:54 -0500 (EST) Received: from smtpin03.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 4121B1401B7 for ; Sat, 5 Dec 2026 04:09:54 +0000 (UTC) X-FDA: 85508601108.03.2EE2D93 Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by imf09.hostedemail.com (Postfix) with ESMTP id 7D1A9140006 for ; Sat, 5 Dec 2026 04:09:52 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=aGb8U9QR; spf=pass (imf09.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796443792; b=nDHpsx+zsxXKp15xLQnwsWXe8b9l9luXIy5BkMAfGtBA3Xk2jx5jJsm1J+WbWQ8OhEZnzN XAlHe0+lap5WVpvo2y0PHh5hZxlzmilXqgFRCYexUObwyUaMPs8yChPUxwDvHVL24Ux5+h Ea/Kzzpps3Q1nZiWI1Hrd0ccqN9yGhw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796443792; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=nS72HqmWuOHcNIChopvh+UB4TGThXyl9DqTr9jaDQKU=; b=HyVKCG+mLlfvP8US5ya0iZZ2XBh5LsgCifcP51nU7yX6PZbQw2XFIrUcyrNSLX40tl2LCn 1xyGmFieOxjuXZJx/JrZGsh3FnbGTYwPhDP7F1m3V/iQomuhzW9RTlELIIDWJib4JrrS1s mKIpxM3F19HvvErxrHpBD8MsAt4E6/o= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=aGb8U9QR; spf=pass (imf09.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id B345445420; Sat, 5 Dec 2026 04:09:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B78D11F00A07; Sat, 5 Dec 2026 04:09:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796443791; bh=nS72HqmWuOHcNIChopvh+UB4TGThXyl9DqTr9jaDQKU=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=aGb8U9QRkElPHHEGLCPYMQ1dy1bBs92Gbq7w3WTL6YCXW0tyzA8u1fQiU3Qge9Pa1 QVORd6nHwV5myVYvKEFKOtVk2HbrQfzPun3JxxRKvCaKkj85XR+55+f8eyYV+yWsxQ /bZAoerQ33Tg0u87whwzRxhvEWSkjydHPQVOwiqfNObuP7ckICVhGU7ZIpz9la1cr3 d5m9QkcLHbuTXVsRj0uNrWsxE2k0SxnDGrU1u+/YzhxJGH50Ii3oGwCxon94MP9pgn FSMhjmmeC98DUqlD4lyShTq69KilLBYq8KzUZZZUCisiflg+8h98JiYL1I2EgAJer8 XCmes091KCruw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [RFC PATCH v10 22/28] security: Add run LSM hooks Reply-To: sashiko-reviews@lists.linux.dev To: "Jarkko Sakkinen" Cc: bpf@vger.kernel.org, linux-mm@kvack.org, linux-security-module@vger.kernel.org, "Aleksa Sarai" , "Alexander Mikhalitsyn" , "Alexander Viro" , "Alexei Starovoitov" , "Andrew Morton" , "Andrii Nakryiko" , "Andy Lutomirski" , "Arnd Bergmann" , "Baolin Wang" , "Ben Segall" , "Christian Brauner" , "Daniel Borkmann" , "David Hildenbrand" , "David Howells" , "David Woodhouse" , "Davidlohr Bueso" , "Dietmar Eggemann" , "Eduard Zingerman" , "Emil Tsalapatis" , "Eric Biggers" , "Georgia Garcia" , "Giuseppe Scrivano" , =?utf-8?b?R8O8bnRoZXIgTm9hY2s=?= , "Hugh Dickins" , "Ihor Solodrai" , "Ingo Molnar" , "James Morris" , "Jan Kara" , "Jason Gunthorpe" , "Jeff Layton" , "Jiri Olsa" , "John Johansen" , "Jonathan Corbet" , "Josef Bacik" , "Juri Lelli" , "Kees Cook" , "K Prateek Nayak" , "KP Singh" , "Kumar Kartikeya Dwivedi" , "Lennart Poettering" , "Liam R. Howlett" , "Manfred Spraul" , "Martin KaFai Lau" , "Matt Bobrowski" , "Mel Gorman" , "Michal Hocko" , =?utf-8?b?TWlja2HDq2wgU2FsYcO8bg==?= , "Mike Rapoport" , "Neal Gompa" , "Oleg Nesterov" , "Paul Moore" , "Pavel Tikhomirov" , "Peter Zijlstra" , "Randy Dunlap" , "Serge E. Hallyn" , "Serge Hallyn" , "Shuah Khan" , "Song Liu" , "Stephen Smalley" , "Steven Rostedt" , "Valentin Schneider" , "Vincent Guittot" , "Yonghong Song" , "Zygmunt Krynicki" In-Reply-To: <20261205032633.1702772-23-jarkko@kernel.org> References: <20261205032633.1702772-1-jarkko@kernel.org> <20261205032633.1702772-23-jarkko@kernel.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 04:09:48 +0000 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 7D1A9140006 X-Rspam-User: X-Stat-Signature: 7o57eu1scc6ajrmo8jbappee8en3bf6u X-Spam-Status: No, score=-11.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-HE-Tag: 1796443792-547566 X-HE-Meta: U2FsdGVkX19jRCO1QNbmuFusdPokV8wTTCWzTXIdlqJEzUJCqcYgUDIBW4AIMhxWkvzsUqhit5r+HNzYmy6iTNkE2j20aopttKCiITRsTfxGfCleyNs9RNXt8P+vfWfJWiMVMrVyL3PpJ+0ApmiwwHWKzsViOG5dECpr7R9ytZ+VMNSU0aT0p1Q6BgWhcueGFdUGvi8l95wj3dPQAmfJ/rbkNtetR+449sWsUCPMINqEKrUkqfOUlsMbNck+lWT8F35YGzpCqDnwQ++rYXhMqOniMvLF3K8vo04fyIcPVFS6KXNSs7IlHaVrB1BsQaKIdMyozQU/DDdYjmXcVMr6vW2mWkzOO3zvDWbNL7NLU0KkQMYCFyEuW9S5f4Kc5H7+1EMcO+SL5BiFvBL6ibz0xOFpDb2w+V5kdZnrp466N/wm/3/p83VOCHqPs3pM95BnRjBNUQB9RTf9Ve9KnCzP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0MXObrk6nzzpHciZef/5a5k83t1b/JQRYRtVzhkbjVBxmf5Ow396cciMJ+EBEVSpgfhwsvZMcAf5JFyxQ2hUP2KDSszLy+8yg83KSBaVHr/2yelB9Ogr97y1wdiMxo1tr3RoHAi8BnPb0KFIoy6pFHWpS5QcZQ/0nUpIZQ+QNxGLccafczPztRlQWl0r02c3ZQkOwSmvcSi8DRduRikTAVqXsNM3tLlT63VfOvrTtcXtJDc8/P8FP+lQq0aLjdLRzXa63Cm2jitdrC+5LRrlJtmZRGTnFSjwqSD4IFVa5Nm7o2yfzzIPgkWu4zGCS7Zef9z06MH8Ag/jwul4+Ed9RGYtypGzzoMOfZfVfCHwolBDw+3uXRhVFV1Vc8= Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Archived-By: Thank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [Medium] runfd: security_runfd_share() called unlocked before RUNFD_INIT check - [Medium] security: missing runfd LSM hooks in fsconfig_set_run() and runfd_get_nsfd() - [Medium] runfd: missing release-acquire ordering before security_runfd_kill() - [Low] security: lbs_runfd is inconsistently guarded with CONFIG_RUNFD -- commit 2754d34d973b3ec1aa8ac75b9845bfd1828fbbc7 Author: Jarkko Sakkinen security: Add run LSM hooks This commit adds lbs_runfd blob management and five LSM hooks (runfd_alloc, runfd_free, runfd_share, runfd_clone, and runfd_kill) to mediate run creation, teardown, namespace sharing, process entry, and run-wide signal delivery. > diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h > index 005a350681c33..e2ec296712695 100644 > --- a/include/linux/lsm_hook_defs.h > +++ b/include/linux/lsm_hook_defs.h > @@ -480,3 +480,11 @@ LSM_HOOK(int, 0, bdev_alloc_security, struct block_d= evice *bdev) > LSM_HOOK(void, LSM_RET_VOID, bdev_free_security, struct block_device *bd= ev) > LSM_HOOK(int, 0, bdev_setintegrity, struct block_device *bdev, > enum lsm_integrity_type type, const void *value, size_t size) > + > +#ifdef CONFIG_RUNFD > +LSM_HOOK(int, 0, runfd_alloc, struct run *run, unsigned int flags) > +LSM_HOOK(void, LSM_RET_VOID, runfd_free, struct run *run) > +LSM_HOOK(int, 0, runfd_share, struct run *run, struct ns_common *ns) > +LSM_HOOK(int, 0, runfd_clone, struct run *run) > +LSM_HOOK(int, 0, runfd_kill, struct run *run, int sig) > +#endif /* CONFIG_RUNFD */ [Severity: Medium] Should this hook set also cover fsconfig(FSCONFIG_SET_RUN) and ioctl(RUNFD_GET_NSFD)? vfs_fsconfig_locked() dispatches FSCONFIG_SET_RUN directly to fsconfig_set_run(), bypassing vfs_parse_fs_param() and security_fs_context_parse_param(). A caller holding a run_fd can bind an fs_context to the run's user, net, mount, PID, or IPC namespaces and instantiate superblocks via FSCONFIG_CMD_CREATE without hitting any per-run run->security policy or Landlock namespace-use restriction. Likewise, runfd_get_nsfd() returns an nsfs descriptor for any member namespace via open_namespace() without a runfd hook. Since security_file_ioctl() and security_file_open() do not receive struct run, a caller can bypass a runfd_clone denial by extracting the namespace fds and entering them with setns(), or by modifying run->user_ns via NS_SET_IDMAP or run->ns->mnt_ns via move_mount(MOVE_MOUNT_T_MNTNS). > diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h > index 13621e9e233e6..b4134b5a6ac79 100644 > --- a/include/linux/lsm_hooks.h > +++ b/include/linux/lsm_hooks.h > @@ -121,6 +121,9 @@ struct lsm_blob_sizes { > unsigned int lbs_bpf_map; > unsigned int lbs_bpf_prog; > unsigned int lbs_bpf_token; > +#ifdef CONFIG_RUNFD > + unsigned int lbs_runfd; > +#endif > }; [Severity: Low] Could lbs_runfd be defined unconditionally here and in security/lsm_init.c (lsm_prepare() and security_init())? All other optional subsystem blob sizes in struct lsm_blob_sizes (such as lbs_ib, lbs_key, lbs_perf_event, and lbs_bpf_*) are unconditional so LSMs can initialize their blob size tables without adding CONFIG_RUNFD guards. [ ... ] > diff --git a/kernel/runfd.c b/kernel/runfd.c > index 6296b2eab12fa..843f7f52fa955 100644 > --- a/kernel/runfd.c > +++ b/kernel/runfd.c [ ... ] > @@ -174,6 +182,10 @@ static long runfd_share_nsfd(struct run *c, unsigned= long arg) > if (!runfd_may_use_ns(ns)) > return -EPERM; > =20 > + ret =3D security_runfd_share(c, ns); > + if (ret) > + return ret; > + > scoped_guard(spinlock, &c->lock) { > if (c->state !=3D RUNFD_INIT) > return -EBUSY; [Severity: Medium] Can calling security_runfd_share() before checking c->state and without serialization cause wrong error returns and races against concurrent runfd_share_nsfd() and runfd_prepare_fork() calls? If c->state is already RUNFD_FORKING, RUNFD_RUNNING, or RUNFD_DEAD, a denying LSM returns -EPERM and logs a spurious denial instead of -EBUSY, while a stateful LSM can mutate c->security for a share that is rejected. Because c->lock is a spinlock and cannot be held across a sleepable hook, concurrent callers can also interleave: CPU0 CPU1 runfd_share_nsfd(c, ns1) runfd_share_nsfd(c, ns2) security_runfd_share(c, ns1) security_runfd_share(c, ns2) /* sleeps / reads c->ns */ spin_lock(&c->lock) old_ns =3D c->ns->net_ns c->ns->net_ns =3D ns2 spin_unlock(&c->lock) __ns_ref_active_put(old_ns) old_ns->ops->put(old_ns) ... reads old_ns <-- use-after-free The same lack of serialization allows two concurrent shares to apply in the opposite order from what LSMs observed, and lets security_runfd_share() run concurrently with runfd_prepare_fork() calling security_runfd_clone(). [ ... ] > @@ -331,6 +344,10 @@ int runfd_send_signal(struct file *file, int sig, > if (READ_ONCE(run->state) !=3D RUNFD_RUNNING) > return -ESRCH; > =20 > + ret =3D security_runfd_kill(run, sig); > + if (ret) > + return ret; > + > scoped_guard(rcu) { > read_lock(&tasklist_lock); > idr_for_each_entry(&pid_ns->idr, pid, nr) { [Severity: Medium] Can security_runfd_kill() observe a NULL run->init_pid or a stale released run->ns member on weakly ordered architectures? runfd_copy() publishes both fields with relaxed stores under c->lock: kernel/runfd.c:runfd_copy() { ... WRITE_ONCE(c->init_pid, get_pid(pid)); WRITE_ONCE(c->state, RUNFD_RUNNING); } Because runfd_send_signal() checks run->state locklessly with READ_ONCE(), there is no release-acquire ordering with runfd_copy() or prior runfd_share_nsfd() namespace swaps. A runfd_kill hook inspecting run->init_pid or run->ns->* without run->lock (such as a BPF LSM program) can read NULL or a namespace pointer that runfd_share_nsfd() has already dropped via old_ns->ops->put(old_ns). Pairing smp_store_release(&c->state, RUNFD_RUNNING) in runfd_copy() with smp_load_acquire(&run->state) here would order those updates before the hook runs. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261205032633.1702= 772-1-jarkko@kernel.org?part=3D22