Skip to content

service/pam: fail cleanly when the subprocess cannot fork - #1278

Open
alvarosth wants to merge 1 commit into
quickshell-mirror:masterfrom
alvarosth:pam-fork-failure
Open

alvarosth wants to merge 1 commit into
quickshell-mirror:masterfrom
alvarosth:pam-fork-failure

Conversation

@alvarosth

Copy link
Copy Markdown

Describe your changes

Fixes #1275.

On fork failure, close the four pipe fds, free the three strings and return 0, so start() reports InternalError through its existing failure path.

Cleanup handlers now require childPid > 0 before calling kill() or waitpid().

Details and decisions

Returning 0 matches the existing pipe() failure path. The positive-PID guard adds defence in depth against passing -1 to kill() or waitpid().

This fix does not depend on #1256.

Testing with an LD_PRELOAD shim forcing fork failure, with stdin as /dev/null and as an open pipe, showed no kill(-1), waitpid(-1) or leaked pipe fds. Normal authentication is unaffected. clang-format and clang-tidy (tidyfox) are clean.

Open concerns

#1256 adds a third pipe. Whichever PR merges second will need to close that pipe on fork failure too.

The existing leak when the second pipe() fails is left out to keep this fix minimal.

@outfoxxed
outfoxxed force-pushed the master branch 2 times, most recently from bf6302e to 9b0f339 Compare October 22, 2026 06:48
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.

PAM: failed fork() leads to kill(-1, SIGKILL), terminating the user session

1 participant