Re: [PATCH] pidfd: restrict pidfd_getfd() to the caller's pid namespace
From: Jiwoo Kim
Date: Thu Nov 19 2026 - 08:55:50 EST
On Thu, 2026-11-19 at 14:42 +0100, Alexander Mikhalitsyn wrote:
> It it an interesting point, because pid namespace itself it not a
> security boundary. While user namespace and capabilities are mechanisms
> to manage permissions.
Hi Alex,
thanks for looking at this.
Agreed, and the patch does not try to make it one. I followed the rule
Christian suggested in [1], requiring pid_vnr(pid) != 0 for operations
that grant access to additional resources of the target, which
ee8323fdc827 then applied to the namespace ioctls. pidfd_getfd() hands
out one of the target's open files, so it looked like it belongs to the
same group.
> Currently, you can do something like this on your machine:
[...]
> and this will actually print hello in the Terminal 0, while the process
> doing that lives in nested pid namespace. But this is not a problem
> because this guy is a root:
Right. As far as I can see this also works for an unprivileged task of
the same uid, as long as it can reach the outer task through a procfs
instance of the outer pid namespace. So pidfd_getfd() currently behaves
like procfs here, and the patch would make it stricter than procfs, in
line with the pidfd ioctls and PIDFD_GET_INFO instead.
The case I had in mind is the one Jann described in [2]: a task in a
child pid namespace that gets a pidfd for an outer task over a socket.
When it has no procfs view of the outer task, as in a container with its
own procfs, that pidfd is its only handle to it. There, the ioctls refuse
the pidfd with -EREMOTE, while pidfd_getfd() returns the target's file.
> So please understand me right, I'm not saying that your point is not
> valid, but I'm not sure what was the intention behind pid_getfd() API
> in the first place and we might want to have semantics and model close
> to the one procfs has.
Understood. If pidfd_getfd() should keep following the procfs model, I'm
fine with dropping this patch; the inconsistency would then be on the
ioctl side. I'll leave that to Christian.
> To conclude, it looks like we have a little bit of inconsistencies
> around here :-) [ But please, don't go and change anything in procfs as
> we might break some tricky use-cases like CRIU and SCM_RIGHTS users. ]
No plans to touch procfs.
[1] https://lore.kernel.org/all/20260925-gewischt-auftrag-tierzucht-c153cb3f9f74@brauner/
[2] https://lore.kernel.org/all/CAG48ez1T5-tUHVK_iHsgUtWa-inVdrZxA3E-ZCW0iENJvasKfg@xxxxxxxxxxxxxx/
Thanks,
Jiwoo Kim