AIX: sudo (use_pty) can hang forever in tcsetattr(TCSADRAIN) at command exit, blocking all further sudo on that tty
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 45/100
- Issue-Typ
- Bug
- Klarheit
- Größtenteils klar
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- c
- Bereich
- operating-systems
Rechercherichtung
The hang occurs in sudo_term_restore() called from pty_cleanup() during exec_pty(). Locate the terminal restore code (likely src/pty.c) and review the tcsetattr call with TCSADRAIN. Use the attached sudo_pty_hang_kit.zip to reproduce on AIX and verify the process exits. Done means sudo returns promptly without blocking when the pty master is not read.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Summary
On AIX 7.3, sudo can hang indefinitely at command exit, in sudo_term_restore() -> tcsetattr(TCSADRAIN).
This happens when output is still queued on the user's tty and nobody reads the pty master (for example sshd stops reading after the client connection stalls or is lost). While it hangs, sudo holds its tty lock, so every further sudo by that user on that tty queues behind it.
I do not think sudo is doing anything wrong by POSIX: TCSADRAIN is documented to wait for queued output. But on AIX that wait never ends, and cannot be interrupted, once the master side stops draining. Linux returns immediately in the same situation (see below). I am reporting this because a more defensive terminal restore on exit (non-blocking, or with a time limit) would avoid the hang on AIX, and an operating system fix may take a long time. I have also raised the AIX behaviour with the OS vendor (IBM).
Environment
- AIX 7.3: multiple TLs and SPs but our reproducer is 7300-04-02
sudo1.9.17p2-1 (AIX Toolbox rpm),use_pty(default),sudostarted from ansshsession- Linux comparison: kernel 7.x
Observed stack of the hung process
ioctl(.., 0x5403, ..) (process sleeping in the kernel, not killable with kill -9 while the `pty` master is open)
tcsetattr
tcsetattr_nobg
sudo_term_restore_v1
pty_cleanup.constprop.0
exec_pty
sudo_execute
run_command
main
A second sudo by the same user waits in:
lockf64
sudo_lock_region_v1
sudo_lock_file_v1
sudo_term_copy_v1
exec_pty
Reproducer (attached: sudo_pty_hang_kit.zip)
sudo_pty_hang_kit.zip, README inside
Deterministic, no ssh, no root, about 15 seconds. As a regular user with passwordless sudo:
perl sudo_pty_hang.pl -n 3000 -w 12 -k
It opens a pty (/dev/ptc), starts sudo sh -c '<print 3000 bytes>' with the pty slave as controlling tty, and never
reads the master.
Result: sudo never exits. With -r (master is read) sudo exits after one second.
./run_pty_hang.sh hold leaves the hung sudo frozen for inspection (procstack, truss), release ends it.
Not sudo specific
tcdrain_sim.pl (no sudo, no sshd): fill the output queue of a pty slave, do not read the master, call tcsetattr():
| mode | AIX 7.3 | Linux 7.x |
|---|---|---|
TCSANOW |
returns immediately | returns immediately |
TCSADRAIN |
blocks (still blocked after 8 s, no end) | returns immediately |
TCSAFLUSH |
blocks (still blocked after 8 s, no end) | returns immediately |
A C program with the same logic behaves the same on AIX.
Suggestion
At command exit, sudo could avoid an unbounded wait on AIX, for example by:
- restoring the terminal with
TCSANOWinstead (TCSAFLUSHis no alternative, it blocks on AIX as well), - or draining with a timeout, giving up (with a log message) if the
ttydoes not drain, - or releasing the
ttylock before the potentially blocking restore, so one stuck session does not block all latersudocalls.
I understand that restoring with TCSANOW may lose queued output in some cases, so I am not sure what the best trade-off is. I am happy to test patches on AIX 7.3.
Workaround
Defaults !use_pty avoids the hang (at the cost of use_pty features such as I/O logging).
- Vorherrschende Sprache
- C
- Sterne
- 1.7k
- Forks
- 306
- Ø Merge
- 1 T. 2 Std.
- Gemergte PRs (30 T.)
- 22
Entwicklungsumgebung
Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus sudo-project/sudo
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 42/100
sudo-project/sudo#583 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Signal forwarded to the command is lost when it arrives between fork() and execve() of the commandOffen
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 35/100
sudo-project/sudo#566 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 52/100
sudo-project/sudo#553 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 48/100
sudo-project/sudo#552 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Documentation text overflows container instead of wrappingEvtl. wieder frei @BittuBarnwal7479 hat das vor 130 Tagen übernommen, und es ist kein Pull Request offen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 58/100
sudo-project/sudo#547 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in sudo-project/sudo
Ähnliche Issues
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 70/100
ly05010419/MacNativeGames#1340 ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
Maintainer antworten meist innerhalb von 1 Tag
-
area:stdlib bug found-by:cold-read kind:bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 83/100
InauguralSystems/EigenScript#2197 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Hide the cursorOffen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 63/100
seedds/nxnative#675 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 88/100
Maintainer antworten meist innerhalb von 2 Tagen