Files
containerd/pkg
Jose Fernandez 5bec0a3329 sys: fix pidfd leak in UnshareAfterEnterUserns
UnshareAfterEnterUserns() creates a pidfd via os.StartProcess() with
CLONE_PIDFD but fails to close the file descriptor in any code path,
resulting in a file descriptor leak for every container that uses user
namespace isolation.

The leak occurs because:
- The pidfd is created when PidFD field is set in SysProcAttr
- The original defer block only calls PidfdSendSignal() and
  pidfdWaitid()
- No code path calls unix.Close(pidfd) to release the file descriptor

This causes one pidfd leak per container launch when user namespace
isolation is enabled (e.g., Kubernetes pods with hostUsers: false). In
production environments with high container churn, this can exhaust the
system's file descriptor limit.

Fix the leak by adding a defer statement immediately after process
creation that ensures unix.Close(pidfd) is always called, regardless of
which code path is taken. This guarantees cleanup even if the function
returns early due to errors or lack of pidfd support.

This follows the same cleanup pattern already established in
core/mount/mount_idmapped_utils_linux.go:getUsernsFD() which properly
closes its pidfd.

Closes: #12166
Signed-off-by: Jose Fernandez <josef@netflix.com>
[Move SupportsPidFD up to handle dupfd in Go 1.23.{0,1} and simplify backport]
Signed-off-by: Wei Fu <fuweid89@gmail.com>
2025-08-07 12:14:56 -04:00
..
2023-02-10 10:23:59 -07:00
2024-01-17 09:51:26 -08:00
2024-08-26 23:35:24 -07:00
2024-01-25 22:18:45 -08:00
2022-08-04 18:18:33 -07:00
2024-01-25 22:18:45 -08:00
2024-01-25 22:18:45 -08:00
2024-01-17 09:52:12 -08:00
2025-03-19 11:35:45 +02:00
2022-10-12 14:41:01 +02:00
2024-10-26 14:18:53 +02:00
2023-09-22 07:53:23 -07:00
2024-01-25 22:18:45 -08:00
2024-10-03 00:12:50 +00:00
2024-01-17 09:55:30 -08:00
2021-11-16 11:06:40 +08:00
2024-05-02 11:03:00 -07:00