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.
Thomas Weißschuh [Tue, 29 Aug 2023 10:06:54 +0000 (12:06 +0200)]
libblkid: protect shared buffers against modifications
The cached buffers are shared between multiple probers.
To avoid (potentially security-sensitive) interdependencies between
probers make let the kernel enforce the write-protection.
Karel Zak [Wed, 23 Aug 2023 09:36:45 +0000 (11:36 +0200)]
uuidgen: mark some options mutually exclusive
* types cannot be mixed (--time, --random, --md5 and --sha1)
* --count makes sense only for --time and --random
* --name and --namespace makes sense only for --md5 and --sha1
Karel Zak [Wed, 23 Aug 2023 09:21:22 +0000 (11:21 +0200)]
uuidgen: add option --count
This is mostly for testing purpose or performance tuning. The new
option allows generate multiple UUIDs using the enhanced capability of
the libuuid to cache time-based UUIDs.
Trag Date [Wed, 23 Aug 2023 01:44:27 +0000 (04:44 +0300)]
last(1): Document -T option for tab-separated output
This commit updates the last(1) man page to include the new -T option, which allows for tab-separated output. This addition to the documentation ensures users are aware of this new functionality and can utilize it to enhance their awk parsing.
Trag Date [Wed, 23 Aug 2023 01:43:04 +0000 (04:43 +0300)]
last: Add -T option for tab-separated output
This commit introduces a -T option to the last command, allowing for tab-separated output. This change significantly improves the usability of last in conjunction with awk, enabling more efficient and intuitive parsing of command output.
Pali Rohár [Tue, 22 Aug 2023 19:21:37 +0000 (21:21 +0200)]
Fix detection of UDF filesystem
OSTA UDF standard is "profile" of the ISO/IEC 13346 and ECMA-167 standard.
Fix UDF detection and check for "*OSTA UDF Compliant" domain id which
distinguish UDF from all other ISO/IEC 13346 and ECMA-167 filesystems.
Qais Yousef [Sat, 19 Aug 2023 17:32:41 +0000 (18:32 +0100)]
uclampset: Remove validation logic
While experimenting with a potential extension to uclamp; I realized
I had to modify uclampset to be able to use this extension, which is not
scalable.
Since the syscall will do checks anyway, drop the validation logic and
let the kernel do its work without duplication that can potentially get
stale.
Use more magic value for NOT_SET define. We do have uclamp_set_set flag
to verify if the value is valid anyway, so this is extra paranoia.
Filipe Manana [Thu, 17 Aug 2023 09:20:13 +0000 (10:20 +0100)]
libmount: Fix regression when mounting with atime
A regression was introduced in v2.39 that causes mounting with the atime
option to fail:
$ mkfs.ext4 -F /dev/sdi
$ mount -o atime /dev/sdi /mnt/sdi
mount: /mnt/sdi: not mount point or bad option.
dmesg(1) may have more information after failed mount system call.
The failure comes from the mount_setattr(2) call returning -EINVAL. This
is because we pass an invalid value for the attr_clr argument. From a
strace capture we have:
We can't pass MOUNT_ATTR_NOATIME to mount_setattr(2) through the attr_clr
argument because all atime options are exclusive, so in order to set atime
one has to pass MOUNT_ATTR__ATIME to attr_clr and leave attr_set as
MOUNT_ATTR_RELATIME (which is defined as a value of 0).
This can be read from the man page for mount_setattr(2) and also from the
kernel source:
$ cat fs/namespace.c
static int build_mount_kattr(const struct mount_attr *attr, size_t usize,
struct mount_kattr *kattr, unsigned int flags)
{
(...)
/*
* Since the MOUNT_ATTR_<atime> values are an enum, not a bitmap,
* users wanting to transition to a different atime setting cannot
* simply specify the atime setting in @attr_set, but must also
* specify MOUNT_ATTR__ATIME in the @attr_clr field.
* So ensure that MOUNT_ATTR__ATIME can't be partially set in
* @attr_clr and that @attr_set can't have any atime bits set if
* MOUNT_ATTR__ATIME isn't set in @attr_clr.
*/
if (attr->attr_clr & MOUNT_ATTR__ATIME) {
if ((attr->attr_clr & MOUNT_ATTR__ATIME) != MOUNT_ATTR__ATIME)
return -EINVAL;
/*
* Clear all previous time settings as they are mutually
* exclusive.
*/
kattr->attr_clr |= MNT_RELATIME | MNT_NOATIME;
switch (attr->attr_set & MOUNT_ATTR__ATIME) {
case MOUNT_ATTR_RELATIME:
kattr->attr_set |= MNT_RELATIME;
break;
case MOUNT_ATTR_NOATIME:
kattr->attr_set |= MNT_NOATIME;
break;
case MOUNT_ATTR_STRICTATIME:
break;
default:
return -EINVAL;
}
(...)
So fix this by setting attr_clr MOUNT_ATTR__ATIME if we want to clear any
atime related option.
Signed-off-by: Filipe Manana <fdmanana@kernel.org>
Karel Zak [Wed, 16 Aug 2023 07:29:50 +0000 (09:29 +0200)]
Merge branch 'logind' of https://github.com/thkukuk/util-linux
* 'logind' of https://github.com/thkukuk/util-linux:
write: query logind for list of users with tty (#2088)
agetty: use sd_get_sessions() for number of users (#2088)
wall: query logind for list of users with tty (#2088)
Karel Zak [Wed, 16 Aug 2023 07:23:01 +0000 (09:23 +0200)]
Merge branch 'enosys/ioctl' of https://github.com/t-8ch/util-linux
* 'enosys/ioctl' of https://github.com/t-8ch/util-linux:
enosys: avoid warnings when no aliases are found
enosys: don't validate that numbers are found from headers
enosys: add support for ioctl blocking
enosys: store blocked syscalls in list instead of array
enosys: build BPF dynamically
enosys: list syscall numbers
Thomas Weißschuh [Tue, 15 Aug 2023 19:25:44 +0000 (21:25 +0200)]
libblkid: limit read buffer size
Many probers read data from disk bounded by some field from the probed
disk itself.
The probers should validate the read length before using.
Add a fallback that kicks in when the proper does not check the length
epxlicitly.
See #2427 Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
Karel Zak [Mon, 14 Aug 2023 11:09:51 +0000 (13:09 +0200)]
Merge branch 'master' of https://github.com/apprehensions/util-linux
* 'master' of https://github.com/apprehensions/util-linux:
tools/all_syscalls: use pipefail
meson: run tests if with option program-tests
meson: use meson features instead of bash
tools/all_syscalls: use sh and replace awk with grep & sed
Karel Zak [Mon, 14 Aug 2023 10:02:47 +0000 (12:02 +0200)]
Merge branch 'verity' of https://github.com/bluca/util-linux
* 'verity' of https://github.com/bluca/util-linux:
verity: modernize example in manpage
verity: use <roothash>-verity as the device mapper name instead of libmnt_<image>
Luca Boccassi [Thu, 10 Aug 2023 23:19:16 +0000 (00:19 +0100)]
verity: modernize example in manpage
These days it's no longer necessary to create the verity hash device
with dd, and to transcribe the roothash by hand. Update the example,
also using the file extensions that are used by systemd for verity
autodiscovery (e.g.: RootImage=img.raw will automatically use
img.verity and img.roothash from the same directory, if present).
Luca Boccassi [Thu, 10 Aug 2023 23:18:22 +0000 (00:18 +0100)]
verity: use <roothash>-verity as the device mapper name instead of libmnt_<image>
If the roothash is the same among two volumes, then the images are guaranteed
to be equivalent. The filename of the image on the other hand does not imply
that the images are equivalent.
In systemd we open verity devices as '<roothash>-verity', so that we know for
sure we can reuse them. Do the same here, so that we are a bit more confident
that images can be reused before the safety check, and also so that we can
take advantage of the kernel refcounting together with images used by systemd,
as setting up verity is expensive.
Colin Gillespie [Wed, 9 Aug 2023 08:28:07 +0000 (18:28 +1000)]
libblkid: (bcachefs) fix not detecting large superblocks
Probing does not detect bcachefs filesystems with a superblock larger
than 4KiB. Bcachefs superblocks grow in size and can become much larger
than this.
Increase the superblock maximum size limit to 1MiB.
Validate the superblock isn't larger than the maximum size defined in
the superblocks layout section.
Karel Zak [Wed, 9 Aug 2023 09:26:28 +0000 (11:26 +0200)]
zramctl: add hint about supported algorithms
It seems the current list of the algorithms is confusing for
end-users, because it's inaccurate in many cases. Let's explain why
the list cannot be "perfect".
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=2203324 Signed-off-by: Karel Zak <kzak@redhat.com>
Karel Zak [Thu, 3 Aug 2023 11:06:30 +0000 (13:06 +0200)]
libmount: improve EPERM interpretation
In some cases mount(2)/open_tree(2) returns EPERM for root user. In
this case libmount reports it as "mount point is not a directory".
It does not makes sense for bind mount where target could be a
regular file.
This patch is not ideal, the error handler is generic, but semantic
for new mount API and mount(2) is different. For example now it checks
for regular file, but the new API supports bind over symlinks, so
proper fix will require lstat() and S_ISLNK(), etc. We need to move
error messages to hook_mount.c and mount_mount_legacy.c to make it
more specific.
Fixes: https://github.com/util-linux/util-linux/issues/2413 Signed-off-by: Karel Zak <kzak@redhat.com>
Karel Zak [Thu, 3 Aug 2023 10:39:19 +0000 (12:39 +0200)]
libmount: ifdef statx() call
In this case the statx() is use to get mount ID. It's optional and not
required. Let's #ifdef the statx() call and also check for stx_mnt_id
struct member.
Fixes: https://github.com/util-linux/util-linux/issues/2415 Signed-off-by: Karel Zak <kzak@redhat.com>
Karel Zak [Thu, 3 Aug 2023 10:09:29 +0000 (12:09 +0200)]
Merge branch 'highsierra' of https://github.com/pali/util-linux
* 'highsierra' of https://github.com/pali/util-linux:
libblkid: iso9660: Implement full High Sierra CDROM format support
libblkid: iso9660: Define all fields in iso_volume_descriptor according to ECMA-119 4th edition spec
Karel Zak [Thu, 3 Aug 2023 10:08:43 +0000 (12:08 +0200)]
Merge branch 'mkfds--INET-alter-the-ports' of https://github.com/masatake/util-linux
* 'mkfds--INET-alter-the-ports' of https://github.com/masatake/util-linux:
tests: (lsfd::mkfds-*) alter the L4 ports for avoiding the conflict with option-inet test case
Karel Zak [Thu, 3 Aug 2023 10:07:55 +0000 (12:07 +0200)]
Merge branch 'tests--TESTS_COMPONENTS' of https://github.com/masatake/util-linux
* 'tests--TESTS_COMPONENTS' of https://github.com/masatake/util-linux:
tests,autotools: add TESTS_COMPONENTS macro for specfying test components from make cmdline
Karel Zak [Thu, 3 Aug 2023 10:07:33 +0000 (12:07 +0200)]
Merge branch 'lsfds--dont-run-unix-stream-test-on-qemu-user' of https://github.com/masatake/util-linux
* 'lsfds--dont-run-unix-stream-test-on-qemu-user' of https://github.com/masatake/util-linux:
tests: (lsfd) don't run the unix-stream testcase including newlines in the path on qemu-user
lsfd: (refactor) unify the invocations of sysfs_get_byteorder()
Markus Mayer [Tue, 1 Aug 2023 20:08:24 +0000 (13:08 -0700)]
include: define pidfd syscalls if needed
If the kernel headers are too old to provide the pidfd syscall numbers,
let's define them ourselves. This can be helpful while cross-compiling.
The runtime environment may provide a kernel that is new enough to
handle the calls, even if the toolchain doesn't.
Markus Mayer [Tue, 1 Aug 2023 19:59:27 +0000 (12:59 -0700)]
libmount: check for struct statx
Let's ensure struct statx exists before we try to use it. Checking for
the existence of linux/stat.h is not sufficient. This is because
[uapi/]linux/stat.h has existed since Linux 3.7, however struct statx
was only introduced with Linux 4.11.
The problem arises if one happens ot be using kernel headers from within
the aforementioned range, such as Linux 4.9.
CC libmount/src/la-utils.lo
In file included from libmount/src/utils.c:31:
./include/fileutils.h:100:33: warning: declaration of 'struct statx' will not
be visible outside of this function [-Wvisibility]
unsigned int mask, struct statx *stx)
^
libmount/src/utils.c:117:16: error: variable has incomplete type 'struct statx'
struct statx stx = { 0 };
^
libmount/src/utils.c:117:10: note: forward declaration of 'struct statx'
struct statx stx = { 0 };
^
libmount/src/utils.c:125:5: error: use of undeclared identifier 'STATX_TYPE'
STATX_TYPE
^
libmount/src/utils.c:126:8: error: use of undeclared identifier 'STATX_MODE'
| STATX_MODE
^
libmount/src/utils.c:127:8: error: use of undeclared identifier 'STATX_INO'
| STATX_INO,
^
1 warning and 4 errors generated.
make[4]: *** [Makefile:11269: libmount/src/la-utils.lo] Error 1
Checking for the presence of struct statx explicitly avoids this
problem.
Markus Mayer [Tue, 1 Aug 2023 19:59:26 +0000 (12:59 -0700)]
libmount: check for linux/mount.h
Check that linux/mount.h is present before using features that rely on
it.
It is necessary to check for the presence of linux/mount.h explicitly.
Simply relying on the presence of several syscalls (e.g. SYS_move_mount,
SYS_open_tree) does not work reliably, at least not in a cross-compiling
environment.
The syscall definitions are provided by the C library. Meanwhile,
linux/mount.h is provided by the kernel. This opens the possibility for
discrepancies.
A problem arises if the C library (e.g. musl-1.2.3) defines all "mount
fd API" syscalls (and HAVE_MOUNTFD_API becomes true), but the kernel
headers are old enough to not provide linux/mount.h. The resulting error
looks as follows. This example is using an LLVM-13 cross-compiler from
x86_64 to aarch64 with musl-1.2.3 as the C library.
CC libmount/src/la-hooks.lo
In file included from libmount/src/hooks.c:30:
./include/mount-api-utils.h:11:10: fatal error: 'linux/mount.h' file not found
^~~~~~~~~~~~~~~
1 error generated.
make[4]: *** [Makefile:11185: libmount/src/la-hooks.lo] Error 1
To prevent this condition, we add a check to configure that will test
for the presence of linux/mount.h in addition to testing for the mount
fd API. Only if both conditions are met can we actually use the mount
fd API.