]> git.ipfire.org Git - thirdparty/util-linux.git/commit
login: use correct terminal fd during setup
authorTobias Stoeckmann <tobias@stoeckmann.org>
Thu, 21 Sep 2023 18:15:46 +0000 (20:15 +0200)
committerTobias Stoeckmann <tobias@stoeckmann.org>
Thu, 21 Sep 2023 18:23:14 +0000 (20:23 +0200)
commite361ef380fa2673e1de0f50d1f362b99e42cd0bb
tree815aa2bddd3d8df107418a35a0fb7f1101974bb7
parent1e0ad14b3ac08d855cda6de346a65f9b834e00db
login: use correct terminal fd during setup

The function get_terminal_name iterates through standard file
descriptors until it finds a terminal. This means that it's not
guaranteed that STDIN_FILENO (i.e. 0) is actually a terminal.

Do not modify permissions on possible files. Instead, retrieve
the file descriptor which was used by get_terminal_name as well.

Proof of Concept (as root):

1. Create a temporary file with a mode different than TTYPERM.
```
install -m 700 /dev/null /tmp/test
ls -l /tmp/test
-rwx------ 1 root root 0 Sep 21 20:15 /tmp/test
```

2. Run login within a terminal with adjusted stdin.
```
login < /tmp/test
host login:
            Hangup
```

3. Check permissions of input file.
```
ls -l /tmp/test
-rw------- 1 root root 0 Sep 21 20:15 /tmp/test
```

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
login-utils/login.c