]> git.ipfire.org Git - thirdparty/util-linux.git/commit
pty-session: defer raw mode until after signals are blocked
authorKarel Zak <kzak@redhat.com>
Tue, 28 Jul 2026 12:16:31 +0000 (14:16 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 28 Jul 2026 12:16:31 +0000 (14:16 +0200)
commit288b503e6f2f02fcfda10ff718e85b2367460cf0
treed6ebd4e8718ea87dbbd14e1d83acc4784f088efc
parent2d05ed224ee5cb72c578ee70f08f9c28ae6c5222
pty-session: defer raw mode until after signals are blocked

ul_pty_setup() switches the user's terminal to raw mode before
ul_pty_signals_setup() blocks signals. A terminating signal delivered
in this window kills the process without reaching ul_pty_cleanup(),
leaving the terminal in raw mode.

Move the raw-mode tcsetattr() out of ul_pty_setup() into a new
ul_pty_terminal_setup() function, to be called after
ul_pty_signals_setup(). This ensures signals are already directed
to signalfd when raw mode is activated, closing the race window.

The setup sequence is now:
  ul_pty_setup()          -- open pty, save terminal attrs
  <app-specific work>     -- e.g. utempter (needs SIGCHLD unblocked)
  ul_pty_signals_setup()  -- block signals, create signalfd
  ul_pty_terminal_setup() -- set raw mode (signals already blocked)
  fork()

Addresses: https://github.com/util-linux/util-linux/issues/4499
Signed-off-by: Karel Zak <kzak@redhat.com>
include/pty-session.h
lib/pty-session.c
login-utils/su-common.c
term-utils/script.c
term-utils/scriptlive.c