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.
If the systemcall is not available ENOSYS is returned.
Under glibc the statx implementation also has its own fallback logic.
As AT_STATX_DONT_SYNC can't be implemented correctly in that fallback
logic the wrapper will return EINVAL in case the emulation is needed and
AT_STATX_DONT_SYNC is set.
So also use our own fallback in that case.
Fixes: #2409 Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
Karel Zak [Wed, 2 Aug 2023 10:57:37 +0000 (12:57 +0200)]
column: fix -l
The original implementation is complicated and broken.
It's possible to calculate the rest of the string (for the last
column) from the current position rather than calculate it
continuously. Use the last wcstok() result also means that it will
work as expected independently on "greedy" mode (skips repeating
separators.
# printf 'a b c d\n1 2 3 4\n' | ./column -t -o '|' -l3
a|b|c d
1|2|3 4
Pali Rohár [Tue, 1 Aug 2023 21:09:52 +0000 (23:09 +0200)]
libblkid: iso9660: Implement full High Sierra CDROM format support
Specification of High Sierra CDROM format was lost for a longer time, but
now was found again. So this change improves parsing High Sierra CDROM
images and implements everything which is already supported for ISO9660.
High Sierra and ISO9660 are very similar and there are only few differences
in headers. Most visible is that High Sierra has additional 8 bytes at
beginning of each descriptor with Volume Descriptor LBN value, it has more
locations of path table occurrences in Volume descriptor, has shorten
copyright and abstract file ids, bibliographic file id is missing, standard
version is 0 and it does not have timezone offset field in date structure.
Thus positions of some fields are different between High Sierra and ISO9960.
Code in iso9660.c is adjusted to handle both formats, instead implementing
two very similar parsers.
CDROM image of Microsoft Programmers Library 1.0 (MSPL10) from 1988, which
is in High Sierra format, was before this change parsed as:
Masatake YAMATO [Tue, 1 Aug 2023 16:50:38 +0000 (01:50 +0900)]
tests: (lsfd::mkfds-*) alter the L4 ports for avoiding the conflict with option-inet test case
Close #2397
The conflict appears in parallel execution.
This change just mitigates the original issue.
An ideal solution is that finding unused ports if bind(2) is failed.