Commit Graph
163 Commits
Author SHA1 Message Date
Mike Yuan 7ce2c1bb5f mountpoint-util: rename fd_is_mount_point() to is_mount_point_at()
fd_* functions in our codebase usually mean fd-specific operations,
while this one actually takes openat()-style params. Rename it
accordingly hence.
2025-01-22 01:37:31 +01:00
Lennart Poettering b979368075 mount-util: introduce umountat_detach_verbose()
This new helper allows unmounting paths by fd.
2025-01-20 11:31:55 +01:00
Mike Yuan 70923ed358 meson: enable -Wzero-as-null-pointer-constant
Support for C added in gcc 15:
https://github.com/gcc-mirror/gcc/commit/236c0829ee21a179c81b83f0d7f112ca23c47a4d
2025-01-16 02:26:56 +01:00
Mike Yuan 07610cafcf namespace-util: modernize fd_is_namespace() and is_our_namespace()
- Make fd_is_namespace() take NamespaceType
- Drop support for kernel without NS_GET_NSTYPE (< 4.11)
- Port is_our_namespace() to namespace_open_by_type()
  (preparation for later commits, where the latter
  would go by pidfd if available, avoiding procfs)
2025-01-04 17:07:59 +01:00
Lennart Poettering b1b128d0e2 mount-util: add debug message to make_userns() failure 2024-12-19 15:33:52 +01:00
Lennart Poettering 91cdc8ab0f mount-util: add debug output when we switched root 2024-12-19 15:33:44 +01:00
Yu Watanabe 5261c521e3 mount-util: make path_get_mount_info() work arbitrary inode
Follow-up for d49d95df0a.
Replaces 9a032ec55a.
Fixes #35075.
2024-11-08 13:25:17 +01:00
Ivan Kruglov 9af164b71c use report_errno_and_exit() in src/shared/mount-util.c 2024-11-06 11:18:38 +01:00
Yu Watanabe d49d95df0a mount-util: introduce path_is_network_fs_harder()
It also detects e.g. glusterfs or mounts with "_netdev" option.
2024-11-06 04:58:55 +09:00
Andres Beltran eae5127246 core: add id-mapped mount support for Exec directories 2024-11-01 18:45:28 +00:00
Integral ddb8a639d5 tree-wide: replace for loop with FOREACH_ELEMENT or FOREACH_ARRAY macros (#34893) 2024-10-26 07:10:22 +09:00
Daan De Meyer 04f0a17e92 mount-util: Make get_submounts() a public function 2024-10-16 11:37:57 +01:00
Mike Yuan 3f8999a76e fs-util: rename laccess to access_nofollow
In order to distinguish it from libc function naming.
2024-10-05 01:30:43 +02:00
Mike Yuan 7c1dd9e288 various: correct laccess() error check
laccess is our own macro that uses RET_NERRNO.
2024-10-04 21:26:04 +02:00
Yu Watanabe dd86e6c45c mount-util: wrap long line 2024-09-06 13:09:36 +09:00
Luca Boccassi 5162829ec8 core: do BindMount/MountImage operations in async control process
These operations might require slow I/O, and thus might block PID1's main
loop for an undeterminated amount of time. Instead of performing them
inline, fork a worker process and stash away the D-Bus message, and reply
once we get a SIGCHILD indicating they have completed. That way we don't
break compatibility and callers can continue to rely on the fact that when
they get the method reply the operation either succeeded or failed.

To keep backward compatibility, unlike reload control processes, these
are ran inside init.scope and not the target cgroup. Unlike ExecReload,
this is under our control and is not defined by the unit. This is necessary
because previously the operation also wasn't ran from the target cgroup,
so suddenly forking a copy-on-write copy of pid1 into the target cgroup
will make memory usage spike, and if there is a MemoryMax= or MemoryHigh=
set and the cgroup is already close to the limit, it will cause an OOM
kill, where previously it would have worked fine.
2024-08-29 12:48:55 +01:00
Mike Yuan e633e8627f mount-util: reorder params for mount_in_userspace, clean up logging 2024-07-23 19:31:32 +02:00
Mike Yuan 974e34a018 mount-util: do not unnecessarily acquire mountns fd twice
This also enables us to use pidref_namespace_open().
2024-07-23 19:30:55 +02:00
Mike Yuan 706302897a mount-util: clean up mount_exchange_graceful a bit, don't duplicate move_mount when fallback 2024-07-23 19:30:55 +02:00
Lennart Poettering a8db162d8a test: beef up test case for fid-based equality checks 2024-07-01 16:02:05 +02:00
Luca Boccassi a1a40297db core: deduplicate identical dm-verity ExtensionImages=
It turns out OverlayFS doesn't handle gracefully when the same source is
specified multiple times in lowerdir= and it fails with ELOOP:

Failed to mount overlay (type overlay) on /run/systemd/mount-rootfs/opt (MS_RDONLY "lowerdir=/run/systemd/unit-extensions/1/opt:/run/systemd/unit-extensions/0/opt:/run/systemd/mount-rootfs/opt"): Too many levels of symbolic links

This happens even if we mount each image in a different internal mount
path, as OverlayFS will resolve it and look for the backing device, which
will be the same device mapper entity, and return a hard error.
This error does not appear if dm-verity is not used, so it is very
confusing for users, and unnecessary.

When mounting ExtensionImages, check if an image is dm-veritied,
and drop duplicates if the root hashes match, to avoid this user-unfriendly
hard error.
2024-06-28 14:37:58 +01:00
Dmitry V. Levin c309b9e9c3 treewide: fix a few typos in NEWS, docs, comments, and log messages 2024-04-27 12:11:13 +02:00
Daan De Meyer 827004df94 mount-util: Silence noisy trace log message 2024-04-22 18:01:06 +02:00
Lennart Poettering f4a63ce25f dissect-image: add flag for explicitly enabling userspace verity signature checking
let's make userspace verity signature checking optional. This adds a
dissection flag to enable the logic and patches through all our users to
enable it by default, thus effectively not changing anything from the
status quo ante. However, know we have a knob to turn this off in
certain scenarios.
2024-02-28 16:17:40 +01:00
Krzesimir Nowak 1927bcdc67 mount-util: Add a helper for remounting a bind mount 2024-02-22 19:06:22 +01:00
Benjamin Franzke 614d09a37d nspawn: add support for owneridmap bind option
owneridmap bind option will map the target directory owner from inside the
container to the owner of the directory bound from the host filesystem.
This will ensure files and directories created in the container will be owned
by the directory owner of the host filesystem. All other users will remain
unmapped. Files to be written as other users in the container will not be
allowed.

Resolves: #27037
2024-02-15 11:49:54 +01:00
Mike Yuan b409aacb0a mountpoint-util: introduce path_is_mount_point_full 2024-02-06 15:09:28 +08:00
Yu Watanabe d2881ef96e tree-wide: add short comments for namespace_open() and namespace_enter()
Also use -EBADF when unspecified.
2024-01-19 15:06:08 +09:00
AtariDreams 5ba46b99f7 simplify bitwise checking (#30722)
Some of these checks before bitwise operations are redundant and compilers
do not always recognize them, so let's simplify the code to make the intentions
clearer.
2024-01-09 10:18:10 +09:00
Lennart Poettering bb59b92256 mount-util: make sure mount_switch_root() works as clean NOP when '/' is specified as target 2023-12-14 13:13:45 +09:00
Luca Boccassi 918ef2eeeb Merge pull request #29748 from poettering/tgtmode
Storage target mode, inspired by "target disk mode" á la MacOS, but with NVMe-TCP
2023-11-02 17:26:05 +00:00
Luca Boccassi 6d5202ccaa mount-util: call CLEANUP_ARRAY after allocating array
Coverity gets confused if it is called before.

CID#1523757
2023-11-02 15:34:10 +00:00
Lennart Poettering e9ccae3135 process-util: add new FORK_DEATHSIG_SIGKILL flag, rename FORK_DEATHSIG → FORK_DEATHSIG_SIGTERM
Sometimes it makes sense to hard kill a client if we die. Let's hence
add a third FORK_DEATHSIG flag for this purpose: FORK_DEATHSIG_SIGKILL.

To make things less confusing this also renames FORK_DEATHSIG to
FORK_DEATHSIG_SIGTERM to make clear it sends SIGTERM. We already had
FORK_DEATHSIG_SIGINT, hence this makes things nicely symmetric.

A bunch of users are switched over for FORK_DEATHSIG_SIGKILL where we
know it's safe to abort things abruptly. This should make some kernel
cases more robust, since we cannot get confused by signal masks or such.

While we are at it, also fix a bunch of bugs where we didn't take
FORK_DEATHSIG_SIGINT into account in safe_fork()
2023-11-02 14:09:23 +01:00
Lennart Poettering dba4fa8910 nspawn: make sure idmapped logic works if DDI contains only /usr/ tree
If we have a DDI that contains only a /usr/ tree (and which is thus
combined with a tmpfs for root on boot) we previously would try to apply
idmapping to the tmpfs, but not the /usr/ mount. That's broken of
course.

Fix this by applying it to both trees.
2023-11-01 00:50:43 +00:00
Lennart Poettering 7113640493 fd-uitl: rename PIPE_EBADF → EBADF_PAIR, and add EBADF_TRIPLET
We use it for more than just pipe() arrays. For example also for
socketpair(). Hence let's give it a generic name.

Also add EBADF_TRIPLET to mirror this for things like
stdin/stdout/stderr arrays, which we use a bunch of times.
2023-10-26 22:30:42 +02:00
Lennart Poettering 83d5bbaf1b mount-util: add one more const 2023-10-25 15:53:10 +09:00
Mike Yuan 0f095d0b8f shared/mount-util: log correct errno
Follow-up for 5f48198af8
2023-10-21 06:25:36 +08:00
Luca Boccassi 5f48198af8 mount tunnel: use PidRef 2023-10-19 16:31:05 +01:00
Luca Boccassi 7c83d42ef8 mount-util: use mount beneath to replace previous namespace mount
Instead of mounting over, do an atomic swap using mount beneath, if
available. This way assets can be mounted again and again (e.g.:
updates) without leaking mounts.
2023-10-16 14:33:47 +01:00
Luca Boccassi 5897469a08 core: fix checking for extension-releases for ExtensionImages/Directories
The parsing is done after the image has been opened, not before, as it
cannot be done on an block device. Also fix returning on any error for
ExtensionDirectories, not just ENOENT.

Follow-up for 55ea4ef096
2023-10-12 12:17:58 +01:00
Luca Boccassi ddba5a1ad6 mount-util: use new mount API for image mount tunnel 2023-10-02 14:30:23 +01:00
Luca Boccassi 3e1072726b dissect-image: support verity_dissect_and_mount() in two steps too
With the new mount API first the image is opened, and later mounted
2023-10-02 14:02:32 +01:00
Lennart Poettering 44cc82bfbf mount-util: add make_fsmount() 2023-10-02 14:02:32 +01:00
Luca Boccassi a7e0199ece mount-util: use new mount API for bind mount tunnel
If we have the new mount API we can simplify bind mounting into a namespace
a lot
2023-10-02 14:02:32 +01:00
Yu Watanabe 2b60ce545c mount-util: drop unused remount_and_move_sub_mounts() 2023-08-22 23:21:43 +09:00
Lennart Poettering 1155f44f48 execute: split out mounting of credentials fs
Let's add two new helpers: mount_credentials_fs() and
credentials_fs_mount_flags(). The former mounts a file system suitable
for storing of unencrypted credentials at runtime (i.e. a ramfs or
tmpfs). The latter determines the right mount flags to use for such a
mount.

Both functions mostly just take code from execute.c, but make two
changes:

1. If the kernel supports it we'll use a tmpfs with the new "noswap"
   mount option instead of ramfs. Was added in kernel 6.4, hence is very
   recent, but tmpfs is so much less crappy than ramfs, hence worth it.

2. We'll set MS_NOSYMFOLLOW on the mounts if supported. These file
   systems should only contain regulra files, hence no need to allow
   symlinks.
2023-07-04 23:03:24 +02:00
Daan De Meyer 506c1bb594 stat-util: Make sure we trigger automounts when looking for ESP/XBOOTLDR
Fixes #25417
2023-06-30 12:25:07 +01:00
Lennart Poettering f56f9c6b3e mount-util: tweak flags decoding in mount_verbose_full()
Fine-tune the decoding of mount options in mount_verbose_full() to
provide more helpful log output:

1. decode changing of propagation changes
2. discern changing of superblock flags/mount option string from mount
   flags
3. don't check secondary fields when deciding which mount op is
   executed, only the flags decide that.
2023-06-29 22:15:16 +01:00
Lennart Poettering 11e2be3a19 mount-util: use inode_type_to_string() in mode_to_inaccessible_inode()
Let's reuse the inode type name table here and shorten/simplify the code
a bit.
2023-06-26 17:24:35 +02:00
Lennart Poettering 1b618bf141 mount-util: add helper that can bind mount submounts of one dir to another 2023-06-23 18:30:59 +02:00