Stanislav Brabec [Wed, 28 Feb 2024 14:06:14 +0000 (15:06 +0100)]
setterm: Document behavior of redirection
Debugging an error of setterm, I realized that setterm --powerdown operates
on stdout but setterm --powersave operates on stdin. Such unexpected
behavior should be documented.
I prefer a less accurate generic "always redirect both stdin and stdout"
over recommending of the correct I/O stream for each option separately.
Karel Zak [Thu, 29 Feb 2024 08:50:59 +0000 (09:50 +0100)]
Merge branch 'lsfd--btrfs' of https://github.com/masatake/util-linux
* 'lsfd--btrfs' of https://github.com/masatake/util-linux:
tests: (lsfd::mkfds-inotify-btrfs) test INOTIFY.INODES cooked output
lsfd: extend nodev table to decode "btrfs" on SOURCE column
lsfd: (refactor) rename a member of struct proc
lsfd: (refactor) rename a local variable and a parameter
lsfd: (refactor) split the function processing mountinfo file
lsfd: (refactor) store a mnt_namespace object to struct process
lsfd: (refactor) use a binary tree as the implementation for mnt_namespaces
lsfd: read /proc/$pid/ns/mnt earlier
lsfd: (refactor) rename add_nodevs to read_mountinfo
lsfd: make the way to read /proc/$pid/mountinfo robust
lsfd: (cosmetic) normalize whitespaces
Karel Zak [Tue, 27 Feb 2024 17:38:02 +0000 (18:38 +0100)]
hexdump: check blocksize when display data
hexdump(1) stores input to buffer and apply format unit when prints
the output. The unit can move pointer which points to the buffer, but
code does not check for limits.
Fixes: https://github.com/util-linux/util-linux/issues/2806 Signed-off-by: Karel Zak <kzak@redhat.com>
Karel Zak [Mon, 26 Feb 2024 11:44:10 +0000 (12:44 +0100)]
libmount: report kernel message from new API
This is a very minimalistic implementation for v2.40 designed to print
error messages from the kernel. It exclusively displays errors, and
the patch does not introduce any new library interface for this
purpose. Instead, it simply replaces hardcoded messages within
libmount with kernel messages.
It's worth noting that the final implementation will necessitate
per-hook error handling in libmount and likely a new library API to
access other types of messages (warnings, notices, etc.).
Jan Kara [Wed, 21 Feb 2024 17:30:50 +0000 (18:30 +0100)]
libmount: don't hold write fd to mounted device
Avoid holding writeable fd to a loop device that is being mounted. In
the hardened configurations (CONFIG_BLK_DEV_WRITE_MOUNTED = n) the
kernel wants to make sure nobody else has the block device writeably
open when mounting so this makes the mount fail.
Reported-by: JunChao Sun <sunjunchao2870@gmail.com> Signed-off-by: Jan Kara <jack@suse.cz> Acked-by: Christian Brauner <brauner@kernel.org>
Masatake YAMATO [Fri, 5 Jan 2024 05:31:46 +0000 (14:31 +0900)]
lsfd: extend nodev table to decode "btrfs" on SOURCE column
When filling SOURCE column, lsfd decodes the name of the device where the
file object is. If the file object is sourced from a file system, lsfd
fills the column with the file system's name.
As #2349 and #2308, if the file system is btrfs, lsfd couldn't decode
the name correctly. This change and its preceding changes fix this bug.
"devnum offset" causes the trouble. On btrfs, the device number
reported by stat syscall and proc fs are different.
For the details of "devnum offset", see "Mechanism behind the
devnum offset". About the way to fix it, see "How to adjust the output of lsfd".
Without this change:
$ ./lsfd -Q '(ASSOC == "exe")' -p $$
COMMAND PID USER ASSOC XMODE TYPE SOURCE MNTID INODE NAME
zsh 19318 yamato exe ------ REG 0:38 0 589767 /usr/bin/zsh
With this change:
$ ./lsfd -Q '(ASSOC == "exe")' -p $$
COMMAND PID USER ASSOC XMODE TYPE SOURCE MNTID INODE NAME
zsh 19318 yamato exe ------ REG btrfs 0 589767 /usr/bin/zsh
Mechanisum behind the devnum offset
-----------------------------------
Both stat command and the inotify field in fdinfo refer to an inode.
filename_lookup(https://elixir.bootlin.com/linux/v6.2.9/source/fs/namei.c#L2495)
is the function getting the inode for a given file
name. filename_lookup returns a struct path. Via path->detnry->inode,
the caller of filename_lookup can get the inode.
stat command calls statx system call. statx calls filename_lookup
eventually.
inotify_add_watch system call takes a file name. The inotify_add_watch
calls the filename_lookup eventually for getting the inode for the
file name. The inode number that inotify_add_watch gets via
filename_lookup is printed in the inotify field in fdinfo.
The device number, the subject of this issue, can be obtained via
path->detnry->inode->i_sb->s_dev. Both the stat command and the
inotify field in fdinfo use the filename_lookup for getting path. If
they use the same function, why don't the device numbers match? I
monitored the device numbers obtained via
path->detnry->inode->i_sb->s_dev by inserting a systemtap probe to
filename_lookup. I saw the numbers matched.
However, the number monitored via systemtap did not match the number
printed by the stat command. statx system call doesn't use
path->detnry->inode->i_sb->s_dev , the value obtained via
filename_lookup, directly. statx calls vfs_statx. vfs_statx calls
vfs_getattr after calling the filename_lookup for filling struct
kstat. vfs_getattr calls inode->i_op->getattr, a file system specific
method for filling struct kstat if it is available. btrfs has an
implementation for the method,
btrfs_getattr(https://elixir.bootlin.com/linux/v6.2.9/source/fs/btrfs/inode.c#L9007):
stat->dev = BTRFS_I(inode)->root->anon_dev;
The dev member is overwritten with btrfs specific value.
How to adjust the output of lsfd
--------------------------------
lsfd already reads mountinfo files.
1. Get the "rawnum" and mount point
The device numbers in a mountinfo file are raw; btrfs is not
considered. Let's call the number "rawnum" here. When reading the
mountinfo file, lsfd can know the mount points of btrfs.
By calling "stat" system call for the mount point getting in the
step 1, lsdf can know the device number the btrfs customizes with
its getattr method. Let's call the device number "cookednum".
Karel Zak [Thu, 22 Feb 2024 09:26:15 +0000 (10:26 +0100)]
Merge branch 'enosys/dump' of https://github.com/t-8ch/util-linux
* 'enosys/dump' of https://github.com/t-8ch/util-linux:
setpriv: (tests) add seccomp test
setpriv: add support for seccomp filters
enosys: add functionality to dump filter
include: introduce seccomp.h
Karel Zak [Wed, 21 Feb 2024 09:13:50 +0000 (10:13 +0100)]
docs: cleanup public domain license texts
The absence of an official 'Public domain' definition is the reason
why, for example, the Fedora distribution aggregates all variants from
various projects to make them reviewable.
This commit unifies the 'Public domain' statements to make it simple.
Karel Zak [Tue, 20 Feb 2024 11:26:33 +0000 (12:26 +0100)]
more: fix poll() use
The more(1) command utilizes signalfd() to monitor signals and reads
commands from the user via stderr (as stdin is typically used for
piping and not for user interaction).
However, the current more_poll() implementation ignores stderr. As a result,
more(1) waits on read(stderr) while completely ignoring signals. This issue
becomes evident when using commands like:
grep foo /path/file | more
In such cases, it's only possible to exit 'more' by pressing 'q';
CTRL+C does not work.
Changes:
- Refactor more_poll() code:
- Introduce an enum to access pfd[] items instead of using magical constants.
- Implement a while() loop to handle EAGAIN or POLLHUP.
- Ignore stdin after POLLHUP (indicating that the pipe's peer closed).
- Ensure stderr is also checked.
- Use return codes akin to classic poll().
Note: I have doubts regarding the usability of stdin in more_poll(),
as the function is primarily used to wait for user input (via stderr)
and to monitor signals. Nevertheless, it is retained for potential use
in detecting when the pipe's peer (or the entire session) has been
terminated (see commit 68e14d3d5f4116ad3aca0e392d008645ea90cf70).
Milan Broz [Fri, 16 Feb 2024 15:44:12 +0000 (16:44 +0100)]
libblkid: Check offset in LUKS2 header
LUKS2 binary header contains offset field that describes where
the header should be located.
If this offset is not correct, blkid should tread this header
as invalid.
This patch fixes problem when both swap and LUKS headers are
present (LUKS header was swapped out) and detected LUKS header
is at a wrong offset.
As LUKS has higher priority, it confuses detection.
Karel Zak [Wed, 14 Feb 2024 13:46:26 +0000 (14:46 +0100)]
Merge branch 'lslogins-lastlog2' of https://github.com/schubi2/util-linux
* 'lslogins-lastlog2' of https://github.com/schubi2/util-linux:
added build option login-lastlogin
added sqlite3 to packit
added sqlite3 to debian build
fixed time
unifiy test output
cleanup tests
cleanup tests
fixed time-stamp
creating lastlog2 database in the tests
check test output
cleanup; Added testcase for lslogins and lastlog2 DB
lslogins: Add support for lastlog2
Unfortunately, this new feature introduces a regression. We need a
better solution (probably mount options option to enable the feature)
rather than enable it by default.
"Fetching and setting the value of errno is async-signal-safe
provided that the signal handler saves errno on entry and
restores its value before returning."
save and restore errno on cases where it is needed.
Karel Zak [Thu, 8 Feb 2024 11:42:51 +0000 (12:42 +0100)]
fsck: warn if fsck.<type> not found and device is specified
The fsck(8) command prints an error for certain 'required'
filesystems, such as extN, if the corresponding fsck.<type> helper is
not found. However, for other filesystems, it silently ignores the
device. While this behavior is acceptable for the -A option, if a user
explicitly specifies the device on the command line, it is probably a
good idea to be more verbose and issue a warning that the device will
be ignored. The warning is enabled only for interactive mode (only one
device specified or -s).
Note that some filesystems do not have an fsck utility, so caution is
needed when issuing such warnings to prevent the generation of a large
number of unwanted entries in system logs, etc."
Reported-by: наб <nabijaczleweli@nabijaczleweli.xyz> Signed-off-by: Karel Zak <kzak@redhat.com>
Fabian Vogt [Wed, 7 Feb 2024 10:29:26 +0000 (11:29 +0100)]
lastlog2: Fix various issues with meson
- Make sure @usrbin_execdir@ is actually replaced
- pam_lastlog2.so is always a shared library that's dlopen()ed,
so use shared_module and do not generate a pkgconfig module
Karel Zak [Mon, 5 Feb 2024 11:07:49 +0000 (12:07 +0100)]
Merge branch 'lsfd--error' of https://github.com/masatake/util-linux
* 'lsfd--error' of https://github.com/masatake/util-linux:
tests: (lsfd) add a case testing ERROR type appeared in TYPE column
tests: (test_mkfds::mmap) new factory
lsfd: add --_drop-prvilege option for testing purpose
lsfd: add ERROR as a new type
lsfd: (refactor) make the steps for new_file consistent
lsfd: (refactor) add abst_class as super class of file_class
lsfd: (refactor) simplify the step to make a file struct
lsfd: (refactor) simplify the step to copy a file struct if the result of its stat is reusable
lsfd: (refactor) flatten bit fields in struct file
lsfd: fix typos of a function name
Karel Zak [Mon, 5 Feb 2024 10:55:39 +0000 (11:55 +0100)]
Merge branch 'meson/lastlog2' of https://github.com/t-8ch/util-linux
* 'meson/lastlog2' of https://github.com/t-8ch/util-linux:
meson: only build liblastlog when enabled
meson: create dedicated config for pam_lastlog2
meson: use a dependency object for sqlite3
meson: use a dependency object for liblastlog2