** Description changed:

+ [ Impact ]
+ 
+  * On 26.04, with use_pty (the default), suspending an editor that the
+ command under sudo starts as a child (sudo visudo, sudo sudo -e FILE)
+ and resuming it leaves the editor stopped. Run "sudo visudo" or "sudo
+ sudo -e FILE", suspend the editor, run fg, and the editor never comes
+ back. Ctrl-C still ends it. Other programs that sudo's command starts as
+ a child and that the user suspends with Ctrl-Z behave the same. A plain
+ "sudo nano FILE" is not affected, because there the editor is the
+ command itself.
+ 
+  * Cause: on fg, the sudo-rs monitor resumes the command with
+ kill(command_pid, SIGCONT). That reaches the command (visudo, or the
+ inner sudo) but not the editor, its child in the same process group,
+ which stays in state T+.
+ 
+  * Fix: upstream PR 1530 (commit 1c9a1eb2, in 0.2.14 and later) changes
+ the three kill() calls in MonitorClosure::send_signal
+ (src/exec/use_pty/monitor.rs) to killpg(command_pid, ...), as sudo.ws
+ does. The whole group gets SIGCONT, so Ctrl-Z then fg resumes the editor
+ again. The same change fixes LP: #2150073, which has the full
+ background.
+ 
+ [ Test Plan ]
+ 
+ Run this on a test machine or VM with a clean Ubuntu 26.04 install,
+ where /usr/bin/sudo is sudo-rs (the default) and /usr/bin/editor is nano
+ (the default). Use a real terminal (the local console, a desktop
+ terminal or "ssh -t") and a user that may run sudo. Open two terminals,
+ A and B, as that user.
+ 
+ Steps:
+ 
+  a. Do the setup below in terminals A and B.
+  b. Run tests 1 to 5 with 0.2.13-0ubuntu1.2 to see the bug.
+  c. Install the update from -proposed (below).
+  d. Run tests 1 to 5 again in the same terminals.
+ 
+ Setup, in terminal A. First run this line on its own. It may ask for
+ your password:
+ 
+     sudo -v
+ 
+ sudo-rs keeps the password for 15 minutes, per terminal. If the tests
+ take longer, run "sudo -v" again before the next test, so that no
+ password prompt lands inside a test. Then run:
+ 
+     sudo --version
+     printf 'test\n' | sudo tee /etc/lp2160212-test
+ 
+ "sudo --version" prints sudo-rs 0.2.13-0ubuntu1.2 before the update.
+ 
+ Setup, in terminal B. Run "sudo -v" there too. To look for a stuck
+ process, run this in terminal B. It lists every process in state T:
+ 
+     ps -eo pid,ppid,stat,wchan:32,args | awk '$3 ~ /^T/'
+ 
+ nano suspends with Ctrl-T and then Ctrl-Z. With vim, press Ctrl-Z.
+ 
+ Bug tests, in terminal A:
+ 
+  1. The report's second case:
+ 
+         sudo visudo
+ 
+     Press Ctrl-T and then Ctrl-Z. The shell prints "Stopped" and the
+ prompt. Run fg. Expected: nano draws its screen again and takes keys.
+ Ctrl-X closes it, visudo prints "visudo: /tmp/sudoers-XXXXXX/sudoers
+ unchanged" (with a random name in place of XXXXXX), and the prompt comes
+ back.
+ 
+  2. The report's first case:
+ 
+         sudo sudo -e /etc/lp2160212-test
+ 
+     Press Ctrl-T and then Ctrl-Z, then run fg. Expected: nano comes
+ back. Ctrl-X closes it, sudo prints "sudo: /etc/lp2160212-test
+ unchanged", and the prompt comes back.
+ 
+  3. A child of the command that reads the terminal:
+ 
+         sudo sh -c 'sh -c "read v && echo got-\$v"'
+ 
+     Wait a second and press Ctrl-Z. The shell prints "Stopped". Run fg,
+ type hello and press Enter. Expected: got-hello, then the prompt.
+ 
+ With 0.2.13-0ubuntu1.2 tests 1 to 3 hang after fg. The screen stays as
+ it is, keys do nothing, and terminal B lists the editor
+ (/usr/bin/editor) or "sh -c read v" in state T+. In test 2 terminal B
+ also lists the inner "sudo -e /etc/lp2160212-test" in state T+. To get
+ terminal A back, run "sudo kill -CONT PID" in terminal B for each PID
+ listed. The editor then takes keys and Ctrl-X closes it.
+ 
+ With 0.2.13-0ubuntu1.3 tests 1 to 3 pass and terminal B lists nothing
+ after fg.
+ 
+ Regression tests, in terminal A:
+ 
+  4. Ctrl-Z and fg while the command itself reads:
+ 
+         sudo sh -c 'read v && echo got-$v'
+ 
+     Press Ctrl-Z, run fg, type hello and press Enter. Expected on both
+ versions: got-hello.
+ 
+  5. Jobs of a root shell keep their state:
+ 
+         sudo -s
+ 
+     In the root shell:
+ 
+         sleep 300 &
+         kill -STOP %1
+         suspend
+ 
+     At the user prompt, run fg. Back in the root shell:
+ 
+         jobs -l
+ 
+     Expected on both versions: sleep 300 is still listed as "Stopped
+ (signal)". Clean up with "kill -KILL %1" and "exit".
+ 
+ Clean up at the end with "sudo rm /etc/lp2160212-test".
+ 
+ Install the update: enable -proposed as
+ https://ubuntu.com/project/docs/SRU/reference/sru-verification/
+ describes, then run:
+ 
+     sudo apt install -t resolute-proposed sudo-rs
+     apt policy sudo-rs
+     sudo --version
+ 
+ "sudo --version" must print sudo-rs 0.2.13-0ubuntu1.3. Run "sudo -v"
+ again in both terminals before step d.
+ 
+ [ Where problems could occur ]
+ 
+  * The upload changes how the monitor process of the use_pty path
+ delivers signals to the command. If the change is wrong, it would show
+ as commands under sudo on a terminal that do not come back after Ctrl-Z
+ and fg, that hang, or that get interrupted or killed when they did not
+ before.
+ 
+  * Signals that sudo relays (SIGINT, SIGQUIT, SIGTSTP, SIGTERM, SIGHUP,
+ SIGUSR1, SIGUSR2) now reach every process in the command's process
+ group, not only the command. A "kill -HUP" or "kill -USR1" sent to sudo
+ now also hits helper children in that group, and the default action of
+ SIGHUP, SIGUSR1 and SIGUSR2 is to terminate. This is how sudo.ws (24.04)
+ has always relayed signals.
+ 
+  * Ctrl-C: with no pipe, Ctrl-C already reached the whole group through
+ the pty. With stdout or stdin piped, the user's terminal stays cooked
+ until the first SIGTTOU or SIGTTIN stop, and until then sudo relays the
+ SIGINT from Ctrl-C. Before, only the command got it, so an apt-get or
+ dpkg run under "sudo ./script | tee log" did not get it. Now the whole
+ group gets it, as with sudo.ws, and Ctrl-C there now also reaches apt-
+ get or dpkg under the script.
+ 
+  * SIGCONT now reaches group members that were not stopped, or that
+ something else stopped on purpose. Programs with a SIGCONT handler, such
+ as shells, editors, pagers and curses programs, run it, which for an
+ editor means a redraw.
+ 
+  * Not changed: processes in other groups or sessions, such as the jobs
+ of a root shell under sudo -s (test 5). With Defaults !use_pty, or with
+ no terminal, sudo-rs takes src/exec/no_pty.rs, which this upload does
+ not touch.
+ 
+  * The same change has shipped in upstream 0.2.14 and 0.2.15, and in
+ Ubuntu since 0.2.14-1ubuntu2 in 26.10.
+ 
+ [ Other Info ]
+ 
+  * Upstream: issue 1527 (this bug), PR 1530, commit 
1c9a1eb2d4b746938338ff011c8b20c545188196, first released in 0.2.14. The 
upstream issue was closed by PR 1530.
+    https://github.com/trifectatechfoundation/sudo-rs/pull/1530
+ 
+  * The same upload fixes LP: #2150073 and LP: #2146860. The debdiff, the
+ patch details and the full test record are on LP: #2150073. Upstream's
+ ubuntu-raccoon-backport branch for 26.04 is at 0.2.13-0ubuntu1.2 and
+ does not have PR 1530.
+ 
+  * Fixed in later releases: 26.10 (stonking) has the fix since
+ 0.2.14-1ubuntu2 and 0.2.14-1ubuntu4.1 in stonking-updates, and
+ tenacious, the current development series, has 0.2.14-1ubuntu4.1. So no
+ 26.10 task is needed. noble has rust-sudo-rs 0.2.2-1 in universe, which
+ is not the default sudo there. It has the same kill() code, but it was
+ not tested and no noble task is proposed.
+ 
+  * Testing done: tests 1 and 2 ran in fresh ubuntu:26.04 containers on a
+ pty, typed into an interactive bash, as root and as a NOPASSWD user,
+ with nano as /usr/bin/editor, on three .deb builds: the archive
+ 0.2.13-0ubuntu1.2, a build with only the PR 1530 patch, and
+ 0.2.13-0ubuntu1.3 with both patches of this upload. Both tests hang on
+ 0.2.13-0ubuntu1.2 after fg, with the editor in T+ (in test 2 also the
+ inner "sudo -e" child), and kill -CONT on the listed PIDs brought the
+ editor back. Both pass on the two other builds, ending with "visudo:
+ /tmp/sudoers-XXXXXX/sudoers unchanged" and "sudo: /etc/FILE unchanged".
+ Tests 3 to 5 ran in a typed run of the plan as the NOPASSWD user: test 3
+ hangs on 0.2.13-0ubuntu1.2 with "sh -c read v" in T+ and passes on
+ 0.2.13-0ubuntu1.3, and tests 4 and 5 pass on both. As a control, "sudo
+ nano FILE" with Ctrl-T Ctrl-Z, fg and Ctrl-X passes on 0.2.13-0ubuntu1.2
+ and on 0.2.13-0ubuntu1.3. All of it ran once more on .deb packages built
+ from the attached debdiff: test 1 on the final build, and the rest on a
+ build whose debdiff differed only in changelog and DEP-3 text and whose
+ sudo, su and visudo binaries are byte identical. The results were the
+ same. Every run used .deb packages. The containers ran on a 6.18 kernel,
+ not on a 26.04 install with its 7.0 kernel.
+ 
+  * Ctrl-C check, in the same containers: a script whose child traps INT,
+ Ctrl-C 2 seconds after the start. Under "sudo ./int-check.sh | cat" the
+ child never got SIGINT on 0.2.13-0ubuntu1.2 and got it on
+ 0.2.13-0ubuntu1.3. With no pipe, it got SIGINT on both. The full record
+ is on LP: #2150073.
+ 
+  * The autopkgtest (debian/tests/run-cargo-tests.sh) runs cargo test, so
+ unit tests only. Upstream's compliance tests, which drive sudo on a
+ terminal, live in test-framework/, which is not in the crates.io tarball
+ the package builds from. No autopkgtest is added.
+ 
+ [ Original Description ]
+ 
  (Tracking bug from upstream:
  https://github.com/trifectatechfoundation/sudo-rs/issues/1527)
  
  In some combinations, resuming a suspended child process doesn't work.
  
  ## To Reproduce
  
  Make sure Defaults use_pty is turned on, then run
  
  $ sudo sudo -e /etc/file
  
  or
  
  $ sudo visudo
  
  and suspend the process by typing ^Z, then resume it by using fg. The
  process isn't "stuck" (Ctrl-C can break out of it).
  
  ## Expected behavior
  
  The editor is resumed.

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/2160212

Title:
  SIGCONT doesn't seem to propagate all the way through in some cases

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/rust-sudo-rs/+bug/2160212/+subscriptions


-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to