sudo-project / sudo

Utility to execute a command as another user
https://www.sudo.ws
Other
1.16k stars 208 forks source link

use_pty option causes terminal to stop working correctly after running simple script #237

Closed holme-r closed 1 year ago

holme-r commented 1 year ago

After running the following innocuous looking shell script, the terminal stops working correctly and I have to type 'reset' to recover it:

#!/bin/bash
sudo sleep 1 &
python3 -c 'print("hi")'

I ran the script as a non-root user without sudo (i.e. just ./my-script, not sudo ./my-script) On a fresh install of Ubuntu 22.10, after running the script, the terminal stops echoing characters that you type. On Ubuntu 22.04, carriage returns don't result in correct placement of characters (you see zig zag lines of text instead of columns).

I managed to fix the issue by turning off the use-pty option in /etc/sudoers

On Ubuntu 22.10: Sudo version 1.9.11p3 Sudoers policy plugin version 1.9.11p3 Sudoers file grammar version 48 Sudoers I/O plugin version 1.9.11p3 Sudoers audit plugin version 1.9.11p3

millert commented 1 year ago

The problem is that sudo cannot easily tell that the command is being run in the background when it is run from a shell script where there is no job control. A workaround is to add set -m to the script which will result in sudo being run in its own (background) process group. I'm testing a new heuristic to handle this case that will hopefully make it into sudo 1.9.13.

millert commented 1 year ago

This should be fixed in sudo 1.9.13.

hartwork commented 1 year ago

I managed to fix the issue by turning off the use_pty option in /etc/sudoers

For anyone coming here later, please note that turning off use_pty could expose you to privilege escalation via TIOCSTI or TIOCLINUX based command injection, depending e.g. on how your kernel is configured. ttyjack can be used to see that in action.