From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796443792; b=rYQoRELLezTIhLVGsRKx/boKuVFt8FiSI2JRkqeOVqZOK4ZnYd6qPQ38xXMGKnQBrZuE vafJ2G0DL7QwE/SjfDpa3bt4FMH9gFqIS3tX8jzJ/uIDkGTRF9BJbXYswQaqZ5HLSldBp V7cmyI0yZ5GquQqXqWyFwlfaJ2q/i/KlpgtB8SZZ5t1EVQLYsrLuIbrRGgmrcsPsWuy5A o5w6EGqT8xj3OswlBJtVqcr0+iL+KOSumMew4yCSq3OFSFO7OXO6e3INYCvY3h7JC3/cp hcEfoXXUzJWQ1m2DuMAZeMMCwM6rf48G6FpGZaU0gB5KltBYZun8L3QNVsHtbZ712hA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796443792; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=nS72HqmWuOHcNIChopvh+UB4TGThXyl9DqTr9jaDQKU=; b=ZagQfAAyp56E4ge0nXS/nuHU6YoxyFd8CYak+Zphcho/gJLbaU3hzgEHFC5vfJ9jwXSf B3Dpd/j1iHzf9+lZBBV/Qs5oIkLOPzFV/g5u7YcSkQ6daB/KF9cYK/Wytx7axW+R2eR1g P/6V8d0DxalEM1mguj5dqfBChHmA6s+o2HNAeTU/2aibX15U5uDKENsbyNfXE7+0QztK6 VLwUpN85sA9pYzhfGEvMrMIgPUlGhIz+UEPV5FyF8zPkMqX3E7YWLnnXIZci16WJzdPyf 3hSLNURIkQgWWu9Isyq0u8bAtpz4KBL6OI/xWwd/7HmOV6BiWXTRFVo18wCMmL8q2Rg== 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=aGb8U9QR; arc=none smtp.remote-ip=100.103.45.18 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 1107B606A33A; Sat, 5 Dec 2026 04:09:51 +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 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-Mailing-List: bpf@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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