linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] pidfs: never refuse ppid == 0 in PIDFD_GET_INFO
@ 2025-06-04 15:03 Mike Yuan
  2025-06-04 20:50 ` Christian Brauner
  0 siblings, 1 reply; 2+ messages in thread
From: Mike Yuan @ 2025-06-04 15:03 UTC (permalink / raw)
  To: linux-fsdevel
  Cc: Mike Yuan, linux-kernel, Christian Brauner, Luca Boccassi, stable

In systemd we spotted an issue after switching to ioctl(PIDFD_GET_INFO)
for obtaining pid number the pidfd refers to, that for processes
with a parent from outer pidns PIDFD_GET_INFO unexpectedly yields
-ESRCH [1]. It turned out that there's an arbitrary check blocking
this, which is not really sensible given getppid() happily returns
0 for such processes. Just drop the spurious check and userspace
ought to handle ppid == 0 properly everywhere.

[1] https://github.com/systemd/systemd/issues/37715

Fixes: cdda1f26e74b ("pidfd: add ioctl to retrieve pid info")
Signed-off-by: Mike Yuan <me@yhndnzj.com>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Luca Boccassi <luca.boccassi@gmail.com>
Cc: <stable@vger.kernel.org>
---
 fs/pidfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/pidfs.c b/fs/pidfs.c
index c1f0a067be40..69919be1c9d8 100644
--- a/fs/pidfs.c
+++ b/fs/pidfs.c
@@ -366,7 +366,7 @@ static long pidfd_info(struct file *file, unsigned int cmd, unsigned long arg)
 	kinfo.pid = task_pid_vnr(task);
 	kinfo.mask |= PIDFD_INFO_PID;
 
-	if (kinfo.pid == 0 || kinfo.tgid == 0 || (kinfo.ppid == 0 && kinfo.pid != 1))
+	if (kinfo.pid == 0 || kinfo.tgid == 0)
 		return -ESRCH;
 
 copy_out:

base-commit: 5abc7438f1e9d62e91ad775cc83c9594c48d2282
-- 
2.49.0



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] pidfs: never refuse ppid == 0 in PIDFD_GET_INFO
  2025-06-04 15:03 [PATCH] pidfs: never refuse ppid == 0 in PIDFD_GET_INFO Mike Yuan
@ 2025-06-04 20:50 ` Christian Brauner
  0 siblings, 0 replies; 2+ messages in thread
From: Christian Brauner @ 2025-06-04 20:50 UTC (permalink / raw)
  To: linux-fsdevel, Mike Yuan
  Cc: Christian Brauner, linux-kernel, Luca Boccassi, stable

On Wed, 04 Jun 2025 15:03:42 +0000, Mike Yuan wrote:
> In systemd we spotted an issue after switching to ioctl(PIDFD_GET_INFO)
> for obtaining pid number the pidfd refers to, that for processes
> with a parent from outer pidns PIDFD_GET_INFO unexpectedly yields
> -ESRCH [1]. It turned out that there's an arbitrary check blocking
> this, which is not really sensible given getppid() happily returns
> 0 for such processes. Just drop the spurious check and userspace
> ought to handle ppid == 0 properly everywhere.
> 
> [...]

The original motivation has likely been to exclude calling
PIDFD_GET_INFO for kthreads. But it's questionable whether that's a
sensible restriction given that we allow to retrieve information about
kthreads via /proc/<pid>/status already.

---

Applied to the vfs.fixes branch of the vfs/vfs.git tree.
Patches in the vfs.fixes branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a
new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the
patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs.fixes

[1/1] pidfs: never refuse ppid == 0 in PIDFD_GET_INFO
      https://git.kernel.org/vfs/vfs/c/b55eb6eb2a74

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-06-04 20:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-04 15:03 [PATCH] pidfs: never refuse ppid == 0 in PIDFD_GET_INFO Mike Yuan
2025-06-04 20:50 ` Christian Brauner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).