opencontainers / opencontainers/runc
`--preserve-fds` leaks runc's own file descriptors when fewer FDs are actually passed
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 13.5k
- Forks
- 2.3k
- Avg merge
- 2d 8h
- Merged PRs (30d)
- 30
Description
Description
runc run --preserve-fds=N does not verify that the caller actually passed N file
descriptors. If fewer (or none) are passed, runc passes whatever happens to occupy
those descriptor numbers at that point in its own execution. Those are runc's own
internal file descriptors, and they end up in the container's init process.
Steps to reproduce the issue
- Start a container with
--preserve-fdswithout passing any file descriptors:
sudo runc run --preserve-fds=3 test_container
- Inspect the descriptors of the container's init process from the host:
sudo ls -l /proc/$(sudo runc state test_container | grep -o '"pid": [0-9]*' | grep -o '[0-9]*')/fd/
Describe the results you received and expected
Received: The container process inherits file descriptors belonging to runc.
With our setup on a default rootful configuration, these resolved to /sys/fs/cgroup
and to /sys/fs/cgroup/user.slice/user-<uid>.slice/session-<id>.scope/cpu.max.
No warning or error is emitted.
Expected: runc should detect and report when fewer file descriptors are given than stated in --preserve-fds. E.g.:
file descriptor 3 is not available - the preserve-fds option requires that file descriptors must be passed
What version of runc are you using?
runc version 1.5.1
spec: 1.3.0
go: go1.26.5-X:nodwarf5
libseccomp: 2.6.0
libpathrs: 0.2.6
Host OS information
NAME="Arch Linux"
PRETTY_NAME="Arch Linux"
ID=arch
BUILD_ID=rolling
ANSI_COLOR="38;2;23;147;209"
HOME_URL="https://archlinux.org/"
DOCUMENTATION_URL="https://wiki.archlinux.org/"
SUPPORT_URL="https://bbs.archlinux.org/"
BUG_REPORT_URL="https://gitlab.archlinux.org/groups/archlinux/-/issues"
PRIVACY_POLICY_URL="https://terms.archlinux.org/docs/privacy-policy/"
LOGO=archlinux-logo
Host kernel information
Linux 6.18.50-2-lts
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the runc run --preserve-fds handling and reproduce the issue using --preserve-fds=3 without passing descriptors. Trace how the requested descriptor numbers are selected before container startup; done means missing descriptors produce an error such as “file descriptor 3 is not available” instead of leaking runc's internal descriptors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100