Commit Graph
1000 Commits
Author SHA1 Message Date
Zbigniew Jędrzejewski-Szmek bb44fd0734 various: use _NEG_ macros to reduce indentation
No functional change intended.
2023-08-16 12:52:56 +02:00
Dmitry V. Levin 5cfc190520 nspawn,shared: cleanup use of ERRNO_IS_SECCOMP_FATAL()
Given that ERRNO_IS_SECCOMP_FATAL() also matches positive values,
make sure this macro is not called with arguments that do not have
errno semantics.

In this case the arguments passed to ERRNO_IS_SECCOMP_FATAL() are the
values returned by external libseccomp function seccomp_load() which is
not expected to return any positive values, but let's be consistent
anyway and move ERRNO_IS_SECCOMP_FATAL() invocations to the branches
where the return values are known to be negative.
2023-07-28 12:28:35 +00:00
Dmitry V. Levin 92a702b114 nspawn: cleanup use of ERRNO_IS_NOT_SUPPORTED()
Given that ERRNO_IS_NOT_SUPPORTED() also matches positive values,
make sure this macro is not called with arguments that do not have
errno semantics.

In this case the argument passed to ERRNO_IS_NOT_SUPPORTED() is the
value returned by remount_idmap() which is not expected to return
any positive values, but let's be consistent anyway and move the
ERRNO_IS_NOT_SUPPORTED() invocation to the branch where
the return value is known to be negative.
2023-07-28 12:28:35 +00:00
Zbigniew Jędrzejewski-Szmek da89046643 tree-wide: "<n>bit" → "<n>-bit"
In some places, "<n> bits" is used when more appropriate.
2023-07-02 11:10:12 +01:00
Lennart Poettering 8c3fe1b5b5 process-util: add simple wrapper around PR_SET_CHILD_SUBREAPER
Let's a simple helper that knows how to deal with PID == 1.
2023-06-23 10:05:16 +02:00
Lennart Poettering 19b761a097 tree-wide: getpid() → getpid_cached()
This doesn't really matter, but let's be systematic and prefer
getpid_cached() in our codebase.
2023-06-22 17:07:59 -06:00
Daan De Meyer fab4ef7262 btrfs-util: Add btrfs_subvol_snapshot_at() 2023-06-06 14:44:02 +02:00
Luca Boccassi af262e5fa2 nspawn: restore cross-architecture booting
The check added by 4c27749b8c breaks
booting an arm64 image on x86 using qemu-bin-fmt, so remove it.
Without it, the image built with mkosi --architecture=aarch64
boots fine in nspawn.
2023-05-26 17:00:58 +02:00
David Tardon 7f8a85e6d8 tree-wide: convert more resolve1.Manager calls to BusLocator 2023-05-24 08:33:22 +02:00
Frantisek Sumsal 825210d4e5 nspawn: avoid NULL pointer dereference
When merging the settings we take the pointer to the array of extra
devices, but don't reset the array counter to zero. This later leads to
a NULL pointer dereference, where device_node_array_free() attempts to
loop over a NULL pointer:

+ systemd-nspawn --oci-bundle=/var/lib/machines/testsuite-13.oci-bundle.Npo
 ../src/nspawn/nspawn-settings.c:118:29: runtime error: member access within null pointer of type 'struct DeviceNode'
     #0 0x4b91ee in device_node_array_free ../src/nspawn/nspawn-settings.c:118
     #1 0x4ba42a in settings_free ../src/nspawn/nspawn-settings.c:161
     #2 0x410b79 in settings_freep ../src/nspawn/nspawn-settings.h:249
     #3 0x446ce8 in load_oci_bundle ../src/nspawn/nspawn.c:4733
     #4 0x44ff42 in run ../src/nspawn/nspawn.c:5476
     #5 0x455296 in main ../src/nspawn/nspawn.c:5919
     #6 0x7f0cb7a4a50f in __libc_start_call_main (/lib64/libc.so.6+0x2750f)
     #7 0x7f0cb7a4a5c8 in __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x275c8)
     #8 0x40d284 in _start (/usr/bin/systemd-nspawn+0x40d284)
 SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../src/nspawn/nspawn-settings.c:118:29 in

Also, add an appropriate assert to catch such issues in the future.
2023-05-16 11:27:10 +02:00
Frantisek Sumsal fee9f7b5c7 nspawn: simplify error handling 2023-05-14 19:32:07 +02:00
Daan De Meyer d404c8d887 nspawn: Don't follow /etc/resolv.conf symlinks
When we're checking if /etc/resolv.conf exists so we can bind mount
on top of it, we care about whether the symlink itself exists if
/etc/resolv.conf exists and not the file it points to, so add
CHASE_NOFOLLOW to make sure we check existence of the symlink and
not the file it points to.
2023-04-24 18:14:12 +02:00
David Tardon 088d71f8ed tree-wide: use TAKE_STRUCT 2023-04-14 10:15:44 +02:00
Yu Watanabe 06e78680e3 image-policy: introduce parse_image_policy_argument() helper
Addresses
https://github.com/systemd/systemd/pull/25608/commits/84be0c710d9d562f6d2cf986cc2a8ff4c98a138b#r1060130312,
https://github.com/systemd/systemd/pull/25608/commits/84be0c710d9d562f6d2cf986cc2a8ff4c98a138b#r1067927293, and
https://github.com/systemd/systemd/pull/25608/commits/84be0c710d9d562f6d2cf986cc2a8ff4c98a138b#r1067926416.

Follow-up for 84be0c710d.
2023-04-13 11:17:28 +02:00
Thierry Martin 2f091b1b49 nspawn: container network interface naming
systemd-nspawn now optionally supports colon-separated pair of
host interface name and container interface name for --network-macvlan, --network-ipvlan and --network-interface options.
Also supported in .nspawn configuration files (i.e Interface=, MACVLAN=, IPVLAN= parameters).

man page changed for ntwk interface naming
2023-04-12 14:28:43 +02:00
Lennart Poettering 3af48a86d9 Merge pull request #25608 from poettering/dissect-moar
dissect: add dissection policies
2023-04-12 13:46:08 +02:00
Zbigniew Jędrzejewski-Szmek ddd43f31e3 Merge pull request #26887 from yuwata/proc-cmdline-filter-arguments
proc-cmdline: filter PID1 arguments on container
2023-04-07 10:55:30 +02:00
Lennart Poettering 84be0c710d tree-wide: hook up image dissection policy logic everywhere 2023-04-05 20:45:30 +02:00
Yu Watanabe 319477f1b6 nspawn: ignore NULL machine ID in the container
Previously, when the NULL (all zero) machine ID is configured in the
container, nspawn refused to execute.

Now id128_get_machine() is used, so NULL machine ID is refused with
-ENOMEDIUM, and fallback to specified UUID or randomly generated one.
2023-04-05 00:52:56 +09:00
Yu Watanabe 17f9d6d806 Revert "sd-id128: make id128_read() optionally take root directory"
This reverts commit 830e52caa2.
2023-04-04 11:46:18 +09:00
Yu Watanabe ef9c12b157 tree-wide: reset optind to 0 when GNU extensions in optstring are used
Otherwise, if getopt() and friends are used before parse_argv(), then
the GNU extensions may be ignored.

This should not change any behavior at least now, as we usually use
getopt_long() only once per invocation. But in the next commit,
getopt_long() will be used for other arrays, hence this change will
become necessary.
2023-03-29 10:34:41 +09:00
Yu Watanabe 830e52caa2 sd-id128: make id128_read() optionally take root directory 2023-03-27 11:05:25 +02:00
Daan De Meyer f461a28da7 chase-symlinks: Rename chase_symlinks() to chase()
Chasing symlinks is a core function that's used in a lot of places
so it deservers a less verbose names so let's rename it to chase()
and chaseat().

We also slightly change the pattern used for the chaseat() helpers
so we get chase_and_openat() and similar.
2023-03-24 13:43:51 +01:00
Daan De Meyer a3b00f91bb core: Settle log target if we're going to be closing all fds
Whenever we're going to close all file descriptors, we tend to close
the log and set it into open when needed mode. When this is done with
the logging target set to LOG_TARGET_AUTO, we run into issues because
for every logging call, we'll check if stderr is connected to the
journal to determine where to send the logging message. This check
obviously stops working when we close stderr, so we settle the log
target before we do that so that we keep using the same logging
target even after stderr is closed.
2023-03-22 13:20:08 +01:00
Daan De Meyer 7c2f5495e2 copy: Move chattr arguments to full function signatures
These are almost never used, so let's move them to the _full()
functions signatures.
2023-03-21 20:53:09 +01:00
Frantisek Sumsal 1da3cb8141 tree-wide: simplify x ? x : y to x ?: y where applicable 2023-03-18 14:23:11 +01:00
Lennart Poettering 75f8173247 nspawn: disconnect mounts propagation from host on our container dir
@brauner noticed that in invoked containers the root directory is set to
still receive mounts from the host. We should disable that, and
guarantee we live in our own world, because that's what an
(nspawn-style) container *is* after all: a whole new world.

This hence mounts the container subtree to MS_PRIVATE after getting the
root dir in place. Note that this will later be set to MS_SHARED again.
The MS_PRIVATE disconnects mounts from the host, the MS_SHARED then
establishes a new peer group for mount propagation events, so that
payload service managers (such as systemd) can take benefit of
propagation further down the tree.
2023-03-03 12:17:42 +01:00
Lennart Poettering 11875a98e4 nspawn: drop unused arg 2023-03-02 20:54:31 +01:00
Luca Boccassi f05f2334ee Merge pull request #26632 from poettering/dissect-arch-nspawn
dissect: determine arch from DDI and use it for nspawn
2023-03-01 22:53:16 +00:00
Lennart Poettering 1406bd66e4 tree-wide: error handling modernizations 2023-03-01 22:52:55 +00:00
Lennart Poettering 4c27749b8c nspawn: fix DDI arch → personality() propagation
Since quite a while the propagation from the DDI arch into the
personality() wasn't hooked up anymore. Let's fix that: when the DDI has
a determined arch, automatically propagate this into the personality.
2023-03-01 17:08:28 +01:00
Lennart Poettering 988851b6f9 nspawn: hook up memory pressure + sigrtmin+18 2023-03-01 09:43:23 +01:00
Dmitry V. Levin 30fd9a2dab treewide: fix a few typos in NEWS, docs and comments 2023-02-15 10:41:03 +00:00
Lennart Poettering 74e795ee55 id128: introduce ERRNO_IS_MACHINE_ID_UNSET() helper macro 2023-02-01 15:25:30 +01:00
Daan De Meyer 2642d22adc nspawn: Drop CAP_NET_BIND_SERVICE when in userns but not in netns
If we're in a user namespace but not unsharing the network namespace,
we won't be able to bind any privileged ports even with
CAP_NET_BIND_SERVICE, so let's drop it from the retained capabilities
so services can condition themselves on that.
2023-01-26 22:18:47 +01:00
Lennart Poettering 162f6477c6 path-util: rework file_in_same_dir() on top of path_extract_directory()
Let's port one more over.

Note that this changes behaviour of file_in_same_dir() in some regards.
Specifically, a trailing slash of the input path will be treated
differently: previously we'd operate below that dir then, instead of the
parent. I think that makes little sense however, and I think the code
using this function doesn't expect that either.

Moroever, addresses some corner cases if the path is specified as "/" or
".", i.e. where e cannot extract a parent. These will now be treated as
error, which I think is much cleaner.
2023-01-24 18:13:27 +01:00
Lennart Poettering 22ee78a898 loop-util: always tell kernel explicitly about loopback sector size
Let's not leave the sector size unspecified: either set a user supplied
value, or auto-detect the right size by probing the disk image
accordingly.
2023-01-18 10:47:17 +01:00
Lennart Poettering b36e39d2eb nspawn: port over basename() → path_extract_filename() 2022-12-23 15:04:19 +01:00
Yu Watanabe 5bb1d7fbab tree-wide: use -EBADF more 2022-12-21 01:50:33 +09:00
Yu Watanabe 19ee48a6c2 tree-wide: introduce PIPE_EBADF macro 2022-12-20 11:12:58 +09:00
Zbigniew Jędrzejewski-Szmek 254d1313ae tree-wide: use -EBADF for fd initialization
-1 was used everywhere, but -EBADF or -EBADFD started being used in various
places. Let's make things consistent in the new style.

Note that there are two candidates:
EBADF 9 Bad file descriptor
EBADFD 77 File descriptor in bad state

Since we're initializating the fd, we're just assigning a value that means
"no fd yet", so it's just a bad file descriptor, and the first errno fits
better. If instead we had a valid file descriptor that became invalid because
of some operation or state change, the other errno would fit better.

In some places, initialization is dropped if unnecessary.
2022-12-19 15:00:57 +01:00
Yu Watanabe 9d50f8508b mount-util: make mount_switch_root() take a mount propagation flag 2022-12-15 14:17:22 +09:00
Christian Brauner fefb7a6def nspawn: remove cgroup socket
Signed-off-by: Christian Brauner (Microsoft) <brauner@kernel.org>
2022-12-13 16:03:30 +01:00
Christian Brauner bb1aa18569 nspawn: remove pty socket
Signed-off-by: Christian Brauner (Microsoft) <brauner@kernel.org>
2022-12-13 16:03:30 +01:00
Christian Brauner b07ee9035e nspawn: remove rtnl socket
Signed-off-by: Christian Brauner (Microsoft) <brauner@kernel.org>
2022-12-13 16:03:30 +01:00
Christian Brauner 5d9d3fcb18 nspawn: s/kmsg_socket_pair/fd_inner_socket_pair/g
Also stop stashing the kmsg fifo fd in the socket. Just retrieve it in
the parent and have the parent hold on to it.

Signed-off-by: Christian Brauner (Microsoft) <brauner@kernel.org>
2022-12-13 15:25:46 +01:00
Christian Brauner af06cd3024 nspawn: s/fd_socket_pair/fd_outer_socket_pair/g
Signed-off-by: Christian Brauner (Microsoft) <brauner@kernel.org>
2022-12-13 15:25:46 +01:00
Christian Brauner 525f4e59db nspawn: remove uid socket
Signed-off-by: Christian Brauner (Microsoft) <brauner@kernel.org>
2022-12-13 15:25:46 +01:00
Christian Brauner 1823d92d7b nspawn: remove uuid socket
Signed-off-by: Christian Brauner (Microsoft) <brauner@kernel.org>
2022-12-13 15:25:45 +01:00
Christian Brauner b1e1d1fa48 nspawn: remove pid socket
Signed-off-by: Christian Brauner (Microsoft) <brauner@kernel.org>
2022-12-13 15:25:45 +01:00