Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

AIX: sudo (use_pty) can hang forever in tcsetattr(TCSADRAIN) at command exit, blocking all further sudo on that tty

Đã đóng
#581 4 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
45/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
c
Lĩnh vực
operating-systems

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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
  • sudo 1.9.17p2-1 (AIX Toolbox rpm), use_pty (default), sudo started from an ssh session
  • 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 TCSANOW instead (TCSAFLUSH is no alternative, it blocks on AIX as well),
  • or draining with a timeout, giving up (with a log message) if the tty does not drain,
  • or releasing the tty lock before the potentially blocking restore, so one stuck session does not block all later sudo calls.

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).

Ngôn ngữ chính
C
Star
1.7k
Fork
306
Merge trung bình
1 ngày 8 giờ
Pull request đã merge (30 ngày)
24

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của sudo-project/sudo

Tất cả issue của sudo-project/sudo

Issue tương tự

Thêm issue về C

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.