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.
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.
Karel Zak [Tue, 1 Aug 2023 12:49:48 +0000 (14:49 +0200)]
libmount: cleanup --fake mode
It was originally designed to play nasty games with /etc/mtab (mount
when /etc is read-only and update later when it's write-able).
The --fake is completely useless with the new API due to complexity
where we cannot skip any step, because the next stuff depends on it.
So, it makes more sense skip all functionality where libmount does
anything significant.
This commit add --fake check to hooks logic to skip all hooks as the
hooks are place where libmount implements mount related invasive
operations (create mountpoint, namespaces, create superblock, move,
mount, etc.).
Frankly, --fake without mtab is useless.
Fixes: https://github.com/util-linux/util-linux/issues/2395 Signed-off-by: Karel Zak <kzak@redhat.com>
tests: (lsfd::option-inet) get child-processes' pids via fifo
Close #2399.
The original code assumes the background processes prepare sockets enough
fast. #2399 showed the assumption was wrong; lsfd reported half-cooked
sockets.
To avoid the timing issue, the test case with this change uses a fifo
to receive pids from the child test_mkfds processes. test_mkfds reports
its pid after cooking the sockets. When the option-inet script recives the pid,
we can expect the sockets are ready.
Note: bash's coproc cannot be used here; it supports only one co-process at
once.
Analysed-by: Alexander Kanavin <alex.kanavin@gmail.com> Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Karel Zak [Mon, 31 Jul 2023 10:29:01 +0000 (12:29 +0200)]
Merge branch 'lsfd--handle-newline-in-unix-socket-path' of https://github.com/masatake/util-linux
* 'lsfd--handle-newline-in-unix-socket-path' of https://github.com/masatake/util-linux:
lsfd: (test) add a case for testing a unix socket including newline characters in its path name
lsfd: re-fill unix socket paths with sockdiag netlink interface
lsfd: add comment listing functions names importing via #include
lsfd: include common headers in lsfd.h
lsfd: include system header files first
lsfd: fix a misleading parameter name
lsfd: add const modifier
Karel Zak [Mon, 31 Jul 2023 10:13:24 +0000 (12:13 +0200)]
Merge branch 'lsfd--bpf-prog' of https://github.com/masatake/util-linux
* 'lsfd--bpf-prog' of https://github.com/masatake/util-linux:
test: (lsfd) add a case for testing BPF-PROG.TYPE and BPF-PROG.TYPE.RAW columns
test: (mkfds::bpf-prog) new factory
lsfd: add BPF-PROG.TYPE, BPF-PROG.TYPE.RAW, and BPF-PROG.ID columns
The fincore tests call ts_log_both inside an output redirection of both stdout
and stderr, leading to the ts_log_both output ending up twice in both stdout
and stderr.
Call ts_log_both before setting up the output redirection.
Signed-off-by: Chris Hofstaedtler <zeha@debian.org>
Thomas Weißschuh [Wed, 26 Jul 2023 14:32:59 +0000 (16:32 +0200)]
chrt: (tests) increase deadline test parameters
Since kernel commit b4098bfc5efb ("sched/deadline: Impose global limits on sched_attr::sched_period")
the value for dl_period has a lower bound of 100us.
Adjust the test parameters so the test can work on newer kernels.
Unlike the original work, this commit keeps /proc related code.
Unlike /proc interface, the sockdiag information source doesn't provide
enough information for filling struct unix_xinfo::st member. So this
commit uses /proc interface for filling the most of all unix_xinfo
members as before.
On the other hande, as discussed in
https://github.com/util-linux/util-linux/pull/2067, the /proc
interface in unreliable if a unix path name includes newline
characters. This commit uses the sockdiag interface to compensate
for the weakness of the /proc interface.