Thomas Weißschuh [Mon, 25 Sep 2023 22:27:22 +0000 (00:27 +0200)]
libblkid: (ntfs) validate that sector_size is a power of two
The NTFS prober reads data based off an offset of the sector size.
If the sector size is unaligned and the read data is cached then other
probers can read unaligned values.
Sector sizes for NTFS actually only make sense as power-of-two so
validate that and as a sideeffect avoid the unaligned reads.
Also add the reproducer from OSS-Fuzz that found this issue.
Karel Zak [Mon, 25 Sep 2023 10:44:46 +0000 (12:44 +0200)]
Merge branch 'login-terminal' of https://github.com/stoeckmann/util-linux
* 'login-terminal' of https://github.com/stoeckmann/util-linux:
login: prevent undefined ioctl and tcsetattr calls
login: use correct terminal fd during setup
Karel Zak [Mon, 25 Sep 2023 10:35:48 +0000 (12:35 +0200)]
Merge branch 'timestamp' of https://github.com/t-8ch/util-linux
* 'timestamp' of https://github.com/t-8ch/util-linux:
lib/timeutils: (parse_timestamp_reference) report errors on overflow
lib/timeutils: print error if timestamp can't be parsed
lib/timeutils: test epoch timestamp
Karel Zak [Mon, 25 Sep 2023 10:22:54 +0000 (12:22 +0200)]
Merge branch 'lsfd--resolve-mqueue-nodev' of https://github.com/masatake/util-linux
* 'lsfd--resolve-mqueue-nodev' of https://github.com/masatake/util-linux:
lsfd: collect the device number for mqueue fs in the initialization stage
tests: (lsfd) show the entry for mqueue in /proc/self/mountinfo
Thomas Weißschuh [Fri, 22 Sep 2023 18:38:13 +0000 (20:38 +0200)]
ci: also use GCC 13 for sanitizer builds
Now that -Werror is not used anymore with -fsanitize the false-postives
are not a problem anymore and we get the better runtime checks of newer
sanitizers.
Thomas Weißschuh [Fri, 22 Sep 2023 09:19:24 +0000 (11:19 +0200)]
ci: don't combine -Werror and -fsanitize
As explained in [0]:
Note that sanitizers tend to increase the rate of false positive
warnings, most notably those around -Wmaybe-uninitialized. We recommend
against combining -Werror and [the use of] sanitizers.
login: prevent undefined ioctl and tcsetattr calls
Do not call tcsetattr if tcgetattr fails, because the content of
tt and ttt is undefined in that case.
Also do not just warn if ioctl fails, but also avoid calling it again
after tty has been re-opened.
I've solved this by setting struct variables to values which cannot be
valid at this point. If they do have these exact values, then the
calls will be prevented.
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
```
Karel Zak [Mon, 18 Sep 2023 10:10:01 +0000 (12:10 +0200)]
Merge branch 'lsfd--monitor-flag-for-poll-syscall' of https://github.com/masatake/util-linux
* 'lsfd--monitor-flag-for-poll-syscall' of https://github.com/masatake/util-linux:
tests: (test_mkfds::mkfds-multiplexing) make the output of ts_skip_subtest visible
tests: (test_mkfds::mkfds-multiplexing) dump /proc/$pid/syscall for debugging
lsfd: (man) write about XMODE.m and classical system calls for multiplexing
tests: (lsfd) add a case testing XMODE.m for classical syscalls for multiplexing
tests: (test_mkfds) add ppoll multiplexer
tests: (test_mkfds) add poll multiplexer
tests: (test_mkfds) add pselect6 and select multiplexers
tests: (test_mkfds) add a new factory "multiplexing"
tests: (test_mkfds) allow to add factory-made fds to the multiplexer as event source
tests: (test_mkfds, refactor) make the function for waiting events plugable
tests: (test_mkfds) include locale headers first to define _GNU_SOURCE
tests: (test_mkfds) use err() when a system call fails
lsfd: (comment) fix a typo
lsfd: mark XMODE.m on fds monitored by select(2) and pselect6(2)
lsfd: mark XMODE.m on fds monitored by poll(2) and ppoll(2)
lsfd: cache the result of checking whether "XMODE" column is enabled or not
procfs: add a helper function to access /proc/$pid/syscall
lsfd: (refactor) make the code for traversing threads reusable
lsfd: collect the device number for mqueue fs in the initialization stage
Though lsfd reads device minor numbers for file-systems having "nodev"
from /proc/$pid/mountinfo, we observed lsfd failed to resolve the
values of SOURCE column for mqueue files on s390 CI/CD env. It seems
that /proc/$pid/mountinfo doesn't provide enough information.
This change makes lsfd open a mqueue file in lsfd's initialization
stage as a new data source for resolving; lsfd can collect an
actually-used minor number from the file descriptor with fstat(2).
Karel Zak [Mon, 18 Sep 2023 09:14:38 +0000 (11:14 +0200)]
Merge branch 'vla-alloca' of https://github.com/t-8ch/util-linux
* 'vla-alloca' of https://github.com/t-8ch/util-linux:
buildsys: warn on usage of alloca()
more: remove usage of alloca()
buildsys: warn on usage of VLAs
lib/mbsedit: remove usage of VLA
lscpu: remove usage of VLA
fdisk: remove usage of VLA
libfdisk: (dos) remove usage of VLA
libblkid: (stratis) remove usage of VLA
lib/path: remove usage of VLA
Some lines in /proc/cpuinfo can be large e.g. flags and can then
truncate them in displaying them
BUFSIZ can vary quite a bit e.g. glibc/linux systems its 8192
but on musl/linux and OSX its 1024, on mingW it is 256, some tests e.g.
x86_64-64cpu-linux6.2.tar.gz has added really long line for cpu flags
line which is greater than 1024 characters and hence this test fails
on musl because lscpu -s reports truncated string
Thomas Weißschuh [Sun, 10 Sep 2023 20:46:00 +0000 (22:46 +0200)]
libblkid: prune unneeded buffers
When a new buffer is cached that is a superset of another existing
buffer the old buffer can be removed as future requests can be satisfied
by the new one.
As probe functions can have local references to buffered data, delay the
cleanup until the probefunc is finished to avoid accessing freed data.
For the bcachefs.img testfile this reduces the final (maximal) cache
from 34338 bytes in 54 buffers
to 24760 bytes in 40 buffers.
Karel Zak [Mon, 11 Sep 2023 13:17:01 +0000 (15:17 +0200)]
scriptreplay: support ctrl+s and ctrl+g
The old scriptreplay supported XON/XOFF flow control. The new
implementation uses cfmakeraw() and it disables it by default. Let's
enable it by IXON iflag.
Fixes: https://github.com/util-linux/util-linux/issues/2480
References: https://github.com/util-linux/util-linux/pull/1101 Signed-off-by: Karel Zak <kzak@redhat.com>
Karel Zak [Mon, 11 Sep 2023 09:07:54 +0000 (11:07 +0200)]
Merge branch 'lsfd--fix-the-way-to-stop-mkfds-1' of https://github.com/masatake/util-linux
* 'lsfd--fix-the-way-to-stop-mkfds-1' of https://github.com/masatake/util-linux:
tests: (lsfd::filter-floating-point-nums) use --raw output to make the case more robust
tests: (lsfd::column-xmode) do rm -f the file for testing before making it
tests: make ts_skip_capability accepts the output of older version of getpcaps
tests: (lsfd::mkfds-unix-dgram) don't depend on the number of whitespaces in the output
tests: (lsfd) avoid race conditions (part 1)
tests: (test_mkfds) monitor stdin by default
tests: make ts_skip_capability accepts the output of older version of getpcaps
In https://git.kernel.org/pub/scm/libs/libcap/libcap.git/commit/?id=8a2ac848a2065641e20a8b50384b68e8781cc6fc,
the default output format of getpcaps command was changed.
ts_skip_capability() assumes only the newer format, a format
introduced in the commit.
Masatake YAMATO [Thu, 31 Aug 2023 18:20:20 +0000 (03:20 +0900)]
tests: (lsfd) avoid race conditions (part 1)
For terminating test_mkfds process, the test cases
used SIGCONT. test_mkfds used pselect for waiting for the signal.
After receiving the signal test_mkfds exited.
There is a race condition in this logic. If a test case sends SIGCONT
to test_mkfds process before the process calls pselect, the signal
may be lost. As the result, test_mkfds keeps waiting forever in pselect.
This change replaces the code sending SIGCONT with writing to the pipe
connecting to the stdin of test_mkfds. test_mkfds also monitors
its stdin in the pselect call. Unlike the signal, the written bytes to
the pipe are queued.
This change doesn't touch tests/ts/lsfd/option-inet and option-summary
test cases. They don't use coproc. So fixing the race condition in the test
cases can be much complicated. I will make a dedicated pull request (part 2)
for them.
Masatake YAMATO [Thu, 31 Aug 2023 15:56:06 +0000 (00:56 +0900)]
tests: (test_mkfds) monitor stdin by default
After making file descriptors as specified in arguments, test_mkfds
waits for an event with pselect. When test_mkfds gets the event, it
exits.
The original code monitored stdin when the test_mkfds process ran in
the foreground. However, monitoring stdin is useful even when it runs
in the background. ts/lsfd/mkfds-* test cases run test_mkfds as a
co-process. So the test cases can terminate their test_mkfds
processes with echo command if the processes monitor stdin.
This change also adds -X/--dont-monitor-stdin option. As the name
shows, with the option, test_mkfds doesn't monitor stdin as before.
Some test cases run test_mkfds directly. In such a case,
tests/functions.sh may connect stdin of test_mkfds to
/dev/null. /dev/null is always ready to be read.
Karel Zak [Thu, 31 Aug 2023 08:41:32 +0000 (10:41 +0200)]
Merge branch 'PR/losetup-json' of github.com:karelzak/util-linux-work
* 'PR/losetup-json' of github.com:karelzak/util-linux-work:
losetup: make --output-all more usable
losetup: add MAJ a MIN for device and backing-file
losetup: fix JSON MAJ:MIN
Karel Zak [Wed, 23 Aug 2023 09:50:37 +0000 (11:50 +0200)]
libmount: fix statx() includes
Using sys/stat.h and linux/stat is too tricky.h together. It seems
better to rely on libc and use sys/stat.h only. Users affected
by old libc must update to use recent util-linux.
Fixes: https://github.com/util-linux/util-linux/issues/2448 Signed-off-by: Karel Zak <kzak@redhat.com>
Daan De Meyer [Sun, 20 Aug 2023 09:42:51 +0000 (11:42 +0200)]
Add new setpgid utility
This program allows running a command in a new process group and
optionally makes the new process group the foreground process group
of the ctty.
This is useful when running programs through wrappers programs (think
bubblewrap, ...) and wanting to make sure that SIGINT is only sent to
the innermost process. This is possible by putting the innermost process
in a new process group and making that process group the foreground process
group of the controlling terminal.
By adding a separate utility to util-linux, we can apply this to any
program even if the program itself doesn't implement this functionality.