Skip to content

user-accounts: run-passwd: Redirect stderr to stdout in the child

The previous code was prone to race conditions if the child already
started writing to stdout before the dup2 call happened. This has
been detected in postmarketOS[1] and I also reproduced it in Alpine
Linux. Since passwd writes to stderr and linux-pam to stdout, the
redirection was needed. However, linux-pam was failing with
"Conversation error" since an fprintf(stdout, ...) call wasn't
able to write to an already-closed stdout.

This problem is fixed by setting the redirection in the child setup
function and ignoring the stderr pipe. It also fixes a leak, where
the stderr fd was simply ignored and never closed.

[1] https://gitlab.com/postmarketOS/pmaports/-/issues/1449

Added an extra commit to increase debug output, since it simplified debugging. But I am not specially attached to it.

@bberg since you helped finding the solution to the problem in matrix

Merge request reports

Loading