quickshell icon indicating copy to clipboard operation
quickshell copied to clipboard

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

Open alvarosth opened this issue 1 month ago • 0 comments

A failed fork() during PAM authentication leaves childPid set to -1. Error handling then calls kill(-1, SIGKILL), which can terminate the compositor, terminals, and other processes the user can signal, ending the session and losing unsaved work.

Cause

Confirmed on master 11ca60b:

  • subprocess.cpp logs the fork failure and returns -1.
  • conversation.cpp only treats 0 as failure, so it accepts -1 as the child PID and arms a notifier on the default input fd, 0 (stdin).
  • abort() and internalError() check childPid != 0, then call kill(-1, SIGKILL) and waitpid(-1). The latter can also reap an unrelated child.

With stdin set to /dev/null (as under DMS), this happens immediately after start(). With an open pipe, it happens on abort. Fork failure can occur when process/thread limits are reached or memory is exhausted. The failure path also leaks four pipe fds and three duplicated strings.

Verification

I reproduced this safely using an LD_PRELOAD shim that makes fork() fail with EAGAIN and logs non-positive-PID kill calls instead of executing them. It recorded kill(-1, SIGKILL) and waitpid(-1). Authentication with a successful fork does not trigger this.

Suggested fix

Clean up and return 0 on fork failure so start() reports InternalError, and require childPid > 0 in both cleanup handlers.

This code has been present since commit e89035b (2024-06-18). I found no existing report or fix in open or closed issues/PRs; #1256 does not touch this path.

alvarosth avatar Oct 07 '26 07:10 alvarosth