Netdev List
 help / color / mirror / Atom feed
* [PATCH net 0/2] net: fix a pidfd leak with a short SO_PEERPIDFD optlen
@ 2026-11-17 15:25 Christian Brauner
  2026-11-17 15:25 ` [PATCH net 1/2] net: don't leak pidfds through " Christian Brauner
  2026-11-17 15:25 ` [PATCH net 2/2] selftests/net: check that a short SO_PEERPIDFD optlen fails Christian Brauner
  0 siblings, 2 replies; 5+ messages in thread
From: Christian Brauner @ 2026-11-17 15:25 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
  Cc: Simon Horman, Kuniyuki Iwashima, Alexander Mikhalitsyn, netdev,
	linux-fsdevel, Christian Brauner (Amutable), stable, Sashiko

SO_PEERPIDFD caps optlen at sizeof(int) but never rejects a shorter one.
With an optlen of 0 to 3 getsockopt() still installs a pidfd and copies
only part of the fd number to userspace, or none of it. The caller can't
close an fd it doesn't know about, so the pidfd sticks around until the
process exits.

That's been the case since SO_PEERPIDFD went in for v6.5. When I moved
the code into a helper for SO_PEERPIDFD_THREAD in v7.4-rc1 I kept the
bug, so the new option has it too.

So just fail with EINVAL before we prepare the pidfd. SCM_PIDFD already
does the equivalent and sets MSG_CTRUNC before it allocates anything.
The second patch adds a selftest.

Note that before v7.4 the code still lives inline in sk_getsockopt(). So
the fix won't apply to the stable trees as is but the change there is
the same.

Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
---
Christian Brauner (2):
      net: don't leak pidfds through a short SO_PEERPIDFD optlen
      selftests/net: check that a short SO_PEERPIDFD optlen fails

 net/core/sock.c                                 |  6 ++-
 tools/testing/selftests/net/af_unix/scm_pidfd.c | 51 +++++++++++++++++++++++++
 2 files changed, 55 insertions(+), 2 deletions(-)
---
base-commit: 666539eecdf4db623f5e3c3e55cf9f2dfad24aa4
change-id: 20261117-work-net-peerpidfd_short_optlen-91a1806c0d6d


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

end of thread, other threads:[~2026-11-17 16:39 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-17 15:25 [PATCH net 0/2] net: fix a pidfd leak with a short SO_PEERPIDFD optlen Christian Brauner
2026-11-17 15:25 ` [PATCH net 1/2] net: don't leak pidfds through " Christian Brauner
2026-11-17 16:39   ` Alexander Mikhalitsyn
2026-11-17 15:25 ` [PATCH net 2/2] selftests/net: check that a short SO_PEERPIDFD optlen fails Christian Brauner
2026-11-17 16:39   ` Alexander Mikhalitsyn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox