Commit Graph

6670 Commits

Author SHA1 Message Date
Daan De Meyer
bc3477fdc5 crash-handler: Call vhangup on /dev/console before spawning crash shell
When pid 1 crashes, the getty unit for the console will happily keep
running which means we end up with two shells competing for the same
tty. Let's call vhangup on /dev/console to kill every other process
attached to the console before we spawn the crash shell. The getty
units have Restart=always but lucky for us, pid 1 just crashed in fire
and flames so it isn't actually able to restart the getty unit.
2024-08-07 21:24:57 +02:00
Cristian Rodríguez
af1a6db58f basic|boot: silence Wunterminated-string-initialization gcc15 warnings
gcc15 has -Wunterminated-string-initialization in -Wextra and
warns about string constants that are not null terminated even though
the functions do do out of bounds access.
Silence the warnings by simply not providing an explicit size.
2024-08-07 00:14:53 +02:00
Yu Watanabe
2e308032f4 basic/linux: update kernel headers from v6.11-rc1 2024-08-04 14:55:32 +09:00
Yu Watanabe
da24dacf34 syscall-list: update syscall tables
This adds fstatat (and its friends), llseek, and uretprobe.
2024-08-04 14:47:30 +09:00
Yu Watanabe
564547d295 Merge pull request #33911 from YHNdnzj/cgroup-setup-cleanup
cgroup-setup/util: several cleanups; make use of cgroup.kill on client request
2024-08-03 06:20:02 +09:00
Yu Watanabe
ec4964692a cgroup-util: fix typo
Follow-up for 0fbb569de1.
2024-08-03 05:48:54 +09:00
Daniel P. Berrangé
6c35e0a51c confidential-virt: add detection for s390x target
The s390x platform provides confidential VMs using the "Secure Execution"
technology, which is also referred to as "Protected Virtualization" or
just "prot virt" in Linux / QEMU.

This can be detected through a simple sysfs attribute.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2024-08-02 16:53:20 +01:00
Daniel P. Berrangé
1c4bd7adcc confidential-virt: split caching of CVM detection into separate method
We have different impls of detect_confidential_virtualization per
architecture. The detection is cached in the x86_64 impl, and as we
add support for more targets, we want to use caching for all. It thus
makes sense to split caching out into an architecture independent
method.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2024-08-02 16:26:00 +01:00
Mike Yuan
2176841b9e cgroup-util: clean up cg_kill() and friends, completely split out cg_kill_kernel_sigkill()
cg_kill_kernel_sigkill() has a narrow use case, and currently
no code really reaches that branch. Let's detach it from
cg_kill_recursive() hence, and call it explicitly later
where appropriate.
2024-08-02 16:36:09 +02:00
Mike Yuan
031860d6cb cgroup-util: drop unused cg_rmdir()
When removing a cgroup, we always want to eliminate subcgroups
first, i.e. use cg_trim(). And cg_rmdir() (along with
CGROUP_REMOVE flag) is simply unused. Kill it.
2024-08-02 16:36:08 +02:00
Mike Yuan
1daf575990 cgroup-util: refactor cg_{ns,freezer,kill}_supported 2024-08-02 16:36:08 +02:00
Mike Yuan
ea25672de5 cgroup-setup: move cg_{,un}install_release_agent from cgroup-util
They're pid1-specific, so move them out of basic/.
2024-08-02 16:36:07 +02:00
Mike Yuan
3386f66200 cgroup-setup: drop unused cg_migrate_callback for cg_attach_everywhere()
While at it, move the typedef from cgroup-util to -setup.
2024-08-02 14:47:39 +02:00
Yu Watanabe
029709f932 socket-util: introduce netlink_socket_get_multicast_groups()
No functional change. Preparation for later commits.
2024-08-02 11:16:33 +09:00
Daan De Meyer
ff5662129a Merge pull request #33885 from DaanDeMeyer/pidref-kthread
Two pidfd fixes
2024-07-31 19:07:35 +02:00
Daan De Meyer
5551426785 Merge pull request #33884 from DaanDeMeyer/log-context
log: Fix size calculation for number of iovecs
2024-07-31 14:23:08 +02:00
Daan De Meyer
ead48ec35c cgroup-util: Don't try to open pidfd for kernel threads
The kernel might start returning -EINVAL when trying to open pidfd's
for kernel threads so let's not try to open pidfd's for kernel threads.
2024-07-31 13:50:16 +02:00
Daan De Meyer
fc83ff3f55 log: Fix size calculation for number of iovecs
Each log context field can expand to up to three iovecs (key, value
and newline) so let's fix the size calculation to take this into
account.
2024-07-31 13:12:55 +02:00
Daan De Meyer
7881f485c9 execute: Drop log level to unit log level in exec_spawn()
All messages logged from exec_spawn() are attributed to the unit
and as such we should set the log level to the unit's max log level
for the duration of the function.
2024-07-31 13:12:55 +02:00
Daniel P. Berrangé
9d7be044ca Fix detection of TDX confidential VM on Azure platform
The original CVM detection logic for TDX assumes that the guest can see
the standard TDX CPUID leaf. This was true in Azure when this code was
originally written, however, current Azure now blocks that leaf in the
paravisor. Instead it is required to use the same Azure specific CPUID
leaf that is used for SEV-SNP detection, which reports the VM isolation
type.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2024-07-30 22:39:20 +02:00
Daan De Meyer
0fbb569de1 cgroup-util: Ignore kernel threads in cg_kill_items()
Similar to the implementation of cgroup.kill in the kernel, let's
skip kernel threads in cg_kill_items() as trying to kill kernel
threads as an unprivileged process will fail with EPERM and doesn't
do anything when running privileged.
2024-07-30 11:53:32 +02:00
Zbigniew Jędrzejewski-Szmek
e520b1258c Merge pull request #30307 from bluca/enforce_inhibitors
logind: always check for inhibitor locks
2024-07-26 13:52:34 +02:00
Luca Boccassi
7020fa8feb Merge pull request #33825 from DaanDeMeyer/chattr
repart: Create disk image file with copy-on-write disabled on btrfs
2024-07-25 14:11:11 +01:00
Luca Boccassi
804874d26a logind: always check for inhibitor locks
Currently inhibitors are bypassed unless an explicit request is made to
check for them, or even in that case when the requestor is root or the
same uid as the holder of the lock.

But in many cases this makes it impractical to rely on inhibitor locks.
For example, in Debian there are several convoluted and archaic
workarounds that divert systemctl/reboot to some hacky custom scripts
to try and enforce blocking accidental reboots, when it's not expected
that the requestor will remember to specify the command line option
to enable checking for active inhibitor locks.

Also in many cases one wants to ensure that locks taken by a user are
respected by actions initiated by that same user.

Change logind so that inhibitors checks are not skipped in these
cases, and systemctl so that locks are checked in order to show a
friendly error message rather than "permission denied".

Add new block-weak and delay-weak modes that keep the previous
behaviour unchanged.
2024-07-25 12:22:36 +01:00
Mike Yuan
268f58076f basic/log: do not treat all negative errnos as synthetic
Currently, IS_SYNTHETIC_ERRNO() evaluates to true for all negative errnos,
because of the two's-complement negative value representation.
Subsequently, ERRNO= is not logged for most of our own code.
Let's fix this, by formatting all synthetic errnos as positive.
Then, treat all negative values as non-synthetic.

While at it, mark the evaluation order explicitly, and remove
unneeded comment.

Fixes #33800
2024-07-25 12:03:59 +02:00
Daan De Meyer
5e49684521 Make read_attr_path() more generic
Let's make this an openat() like function so it can be used in more
scenarios.
2024-07-24 18:58:41 +02:00
Daan De Meyer
1b05ac946a fs-util: Add XO_NOCOW flag
Let's add a flag for xopenat() that immediately makes a file NOCOW
after opening it if it's supported.
2024-07-24 18:58:41 +02:00
Daan De Meyer
32dfe3b63e fs-util: Clean up properly in xopenat_full() on labelling error
If we fail to relabel the file, we should unlink the file or directory
again, so let's make sure we do that.
2024-07-24 18:58:41 +02:00
Daan De Meyer
0dd82dab91 fs-util: Handle dangling symlinks in openat_report_new()
openat() will always resolve symlinks, except if O_NOFOLLOW is passed
or O_CREAT|O_EXCL is passed. This means that if a dangling symlink is
passed to openat_report_new(), the first call to openat() will always
fail with ENOENT and the second call to openat() will always fail with
EEXIST.

Let's catch this case explicitly and fallback to creating the file with
just O_CREAT and assume we're the ones that created the file. We can't
resolve the symlink with chase() because this function is itself called
by chase() so we could end up in weird recursive calls if we'd try to do
so.
2024-07-24 18:58:41 +02:00
Luca Boccassi
0d45d0ec58 Merge pull request #33810 from YHNdnzj/find-executable-simplify
path-util: minor cleanup for find_executable()
2024-07-23 23:08:19 +01:00
Mike Yuan
86a3c1fd95 namespace-util: introduce pidref_namespace_open() 2024-07-23 19:30:54 +02:00
Mike Yuan
30957ced45 namespace-util: explicitly specify namespace_info[]'s size
We do this already in all string lookup tables. This way
it's guaranteed that iterators which ends with _NAMESPACE_TYPE_MAX
wouldn't overrun the array.
2024-07-23 19:30:54 +02:00
Mike Yuan
0e7eda91f4 path-util: simplify final path for find_executable()
Currently, systemd-run ./test.sh would set Description=
to $PWD/./test.sh. This is quite ugly.
2024-07-23 18:48:15 +02:00
Mike Yuan
51b271ead7 path-util: trivial cleanup for find_executable_full() 2024-07-23 18:48:15 +02:00
Mike Yuan
31d76a1702 missing_socket: add SCM_PASSPIDFD and SCM_PIDFD
Preparation for later commits.
2024-07-21 22:50:58 +02:00
Mike Yuan
8dc303d3c8 process-util: modernize pidfd_get_pid() 2024-07-21 22:48:53 +02:00
Mike Yuan
77f709ca84 pidref: move comments that doesn't belong in pidref_copy() to pidref_dup()
Follow-up for 232e66217d
2024-07-21 22:48:53 +02:00
Lennart Poettering
0ea4198f0a terminal-util: add recognizable error if cols/rows of tty are initially not initialized
Various tty types come up with cols/rows not initialized (i.e. set to
zero). Let's detect these cases, and return a better error than EIO,
simply to make things easier to debug.
2024-07-19 11:44:04 +02:00
Lennart Poettering
ad2fa21f83 terminal-util: extend timeout on background color request
I managed to hit the timeout a couple of times inside of slow qemu.
Let's increase it a bit to 1/3s
2024-07-19 11:44:04 +02:00
Lennart Poettering
abe8e99ee6 terminal-util: try to avoid reading more from terminal than we need in get_default_background_color() 2024-07-19 11:44:04 +02:00
Lennart Poettering
2cd19499a0 tree-wide: acquire /dev/console lock around any attempts to reset TTY 2024-07-19 11:44:04 +02:00
Lennart Poettering
dffbe1d152 terminal-util: teach resolve_dev_console() to deal correctly with /dev/console being a symlink
/dev/console is sometimes a symlink in container managers. Let's handle
that correctly, and resolve the symlink, and not consider the data from
/sys/ in that case.
2024-07-19 11:44:04 +02:00
Lennart Poettering
4a24cc859f terminal-util: move lock_dev_console() here
It doesn't really make sense to have that in dev-setup.c, which is
mostly about setting up /dev/, creating device nodes and stuff.

let's move it to the other stuff that deals with /dev/console's
peculiarities.
2024-07-19 11:44:04 +02:00
Lennart Poettering
45d785dfc0 terminal-util: refactor vt_disallocate()
Numerous fixes:

1. use vtnr_from_tty() to parse out VT number from tty path
2. open tty for write only when we want to output just ansi sequences
3. open tty in asynchronous mode, and apply a timeout, just to be safe
4. propagate error from writing (most callers ignore it anyway, might as
   well pass it along correctly)
2024-07-19 11:44:04 +02:00
Lennart Poettering
7147e10c9e terminal-util: move acquire_terminal() and AcquireTerminalFlags back together in header file 2024-07-19 11:44:04 +02:00
Lennart Poettering
061b445828 terminal-util: simplify terminal_set_size_fd() a tiny bit 2024-07-19 11:44:04 +02:00
Lennart Poettering
b7120388f8 terminal-util: split out color macros/helpers into its own header
This is a lot of stuff, and sometimes quite wild, let's turn this into
its own header.

All stuff color-related that just generates sequences is now in
ansi-color.h (no .c file!), and everything more complex that
probes/ineracts with terminals remains in termina-util.[ch]
2024-07-19 11:44:04 +02:00
Lennart Poettering
1ca3924827 terminal-util: remove terminal_vhangup() because apparently unused 2024-07-19 11:44:04 +02:00
Lennart Poettering
ac508b1173 terminal-util: rename return parameters ret_xyz 2024-07-19 11:44:04 +02:00
Lennart Poettering
af1d3a6d92 terminal-util: modernize vt_reset_keyboard() a bit 2024-07-19 11:44:04 +02:00