AIX: sudo (use_pty) can hang forever in tcsetattr(TCSADRAIN) at command exit, blocking all further sudo on that tty
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 45/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 技术栈
- c
调研方向
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.
由索引模型根据 Issue 内容生成。
描述
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).
- 主要语言
- C
- 星标
- 1.7k
- 派生
- 306
- 平均合并
- 1 天 8 小时
- 30 天内合并 PR
- 24
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
sudo-project/sudo 的其他 Issue
-
难度 4/5 3-5 天 新手友好度 42/100
sudo-project/sudo#583 ·
维护者通常 1 天内回复
-
Signal forwarded to the command is lost when it arrives between fork() and execve() of the command未关闭
难度 4/5 3-5 天 新手友好度 35/100
sudo-project/sudo#566 ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 52/100
sudo-project/sudo#553 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 48/100
sudo-project/sudo#552 ·
维护者通常 1 天内回复
-
Documentation text overflows container instead of wrapping可能重新可做 @BittuBarnwal7479 于 134 天前认领,目前没有进行中的 PR。 未关闭
难度 2/5 1-3 小时 新手友好度 58/100
sudo-project/sudo#547 · 1 条评论 ·
维护者通常 1 天内回复
查看 sudo-project/sudo 的全部 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 62/100
pocoproject/poco#5626 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
FujiNetWIFI/fujinet-lib#272 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
facebookincubator/muse-gadget-sdk#301 ·
维护者通常 2 天内回复
-
luaebpf: the by-example page's intro names two outcomes of a lowering and omits the stop with the default verdict可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭documentation severity: low
难度 1/5 1 小时以内 新手友好度 88/100
luainkernel/lunatik#2231 ·
维护者通常 1 天内回复
-
enhancement
难度 2/5 1-3 小时 新手友好度 70/100
Revivedx/SavageWindRecomp#402 ·
维护者通常 1 天内回复