Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stop accidental leakage of /dev/null fd to child procs #68

Merged
merged 1 commit into from
Sep 10, 2024

Conversation

smemsh
Copy link
Contributor

@smemsh smemsh commented Sep 10, 2024

There was a file descriptor leak introduced by previous commit 1d025fb which opens /dev/null and duplicates it onto the standard input descriptor so child processes do not inherit the tty where X started as their standard input. This PR is a trivial patch to close the leak.

It was noticed like so:

 $ lvm
File descriptor 4 (/dev/null) leaked on lvm invocation. Parent PID 470913: /bin/bash
  WARNING: Running as a non-root user. Functionality may be unavailable.
lvm> ^D

 $ lsa /proc/$$/fd
lrwx------ 1 1001 666 64 20240909004440 0 -> /dev/pts/20
lrwx------ 1 1001 666 64 20240909004440 1 -> /dev/pts/20
lrwx------ 1 1001 666 64 20240909004440 2 -> /dev/pts/20
lrwx------ 1 1001 666 64 20240909004440 255 -> /dev/pts/20
lr-x------ 1 1001 666 64 20240909004440 4 -> /dev/null

the fd 4 is the one from the open("/dev/null") call held by sdorfehs:

 $ lsa /proc/`pgrep -P1 sdorfehs`/fd
lr-x------ 1 1001 666 64 20240909180255 0 -> /dev/null
l-wx------ 1 1001 666 64 20240909180255 1 -> pipe:[11682]
l-wx------ 1 1001 666 64 20240909180255 2 -> pipe:[11682]
lrwx------ 1 1001 666 64 20240909180255 3 -> socket:[12584]
lr-x------ 1 1001 666 64 20240909180255 4 -> /dev/null
lr-x------ 1 1001 666 64 20240909180255 5 -> /home/scott/.config/sdorfehs/bar|
lrwx------ 1 1001 666 64 20240909180255 6 -> socket:[12630]

The patch closes the /dev/null after duplicating, so it won't propagate.

We didn't want to leak the initial startup stdin -- which is the tty
where X started -- to all child procs, so we opened /dev/null and
duplicated it onto fd 1.  but then we forgot to close the temporary fd
so it leaks to child procs.
@jcs jcs merged commit ee2a18f into jcs:master Sep 10, 2024
1 check passed
@smemsh smemsh deleted the devnull-fdleak branch September 10, 2024 23:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants