Commit Graph
84 Commits
Author SHA1 Message Date
nl6720 96963e5615 dissect-image: mount the ESP with fmask=0177 (#35871)
Avoid showing the files on the ESP (i.e. a FAT formatted volume) as
executable by removing the execute permission from them.

IMO this makes the colored output of `ls` more sensible since the file
system will be mounted with `noexec` anyway.

Add a `fstype_can_fmask_dmask` function that checks if a file system
type can use the `fmask` and `dmask` mount options.

This replaces `fstype_can_umask` since it was only used in
`partition_pick_mount_options` which only cares about the file system
support for fmask & dmask now.

It somewhat reduces the coverage of the feature since there are more file
systems that support umask as opposed to those supporting dmask & dmask,
but it should not be much of an issue since fmask & dmask are supported
by vfat, exfat and ntfs3.
2025-01-08 15:19:33 +01:00
Luca Boccassi 5dfce2296c Merge pull request #33496 from YHNdnzj/fd-is-mount-symlink
mountpoint-util: do not assume symlinks are not mountpoints
2024-07-02 10:07:20 +02:00
Lennart Poettering 2ed5bd5738 mountpoint-util: clarify that EOVERFLOW is visible on nfs4/autofs mounts 2024-07-01 15:45:15 +02:00
Lennart Poettering 4c39ab9b40 mountpoint-util: use the FID stuff for detecting the root of mounts
In the unlikely event that sandboxes block statx() but let
name_to_handle_at() through it's a good way to determine the root inode
of the namespace, since its parent inode will have the same FID and
mnt_id.
2024-07-01 15:45:15 +02:00
Lennart Poettering 81995fbb96 mountpoint-util: add new helper name_to_handle_at_try_fid()
Newer kernels support a new flag for name_to_handle_at(): AT_HANDLE_FID.
This flag is supposed to return an identifier for an inode that we can
use for checking inode identity. It's supposed to be a replacement for
checking .st_ino which doesn't work anymore today because inode numbers
are no longer unique on file systems (not on overlayfs, and not on btrfs
for example). Hence, be a good citizen and add infrastructure to support
AT_HANDLE_FID. Unfortunately that doesn't work for old kernels, hence
add a fallback logic: if we can use the flag, use it. If we cannot use
name_to_handle_at() without it, which might give us a good ID too. But
of course tha tcan fail as well, which callers have to check.
2024-07-01 15:45:15 +02:00
Lennart Poettering 6fba9a28b9 mountpoint-util: use ERRNO_IS_xyz() at more places 2024-07-01 15:45:15 +02:00
Lennart Poettering 8da6413860 mountpoint-util: add public helper for comparing file handles
We already have the code, let's move it to a function of its own and
export it.
2024-07-01 15:45:15 +02:00
Lennart Poettering a89690f719 mountpoint-util: make is_name_to_handle_at_fatal_error() an exported API
And while we are at it, make it use ERRNO_IS_xyz() where appropriate.

And move it up a bit, so we can use in the whole of mountpoint-util.c
(which we want to later).
2024-07-01 15:45:15 +02:00
Mike Yuan 36e48f22af mountpoint-util: do not assume symlinks are not mountpoints
They very much can be with the new mount API.
2024-06-27 14:57:16 +02:00
Zbigniew Jędrzejewski-Szmek bfd5a0687f various: move const ptr indicator to return value 2024-06-19 16:28:28 +02:00
Mike Yuan 88873231c8 mountpoint-util: add missing assertions, make mount_fd static 2024-05-22 00:48:51 +08:00
Zbigniew Jędrzejewski-Szmek 055b465a3f shared/mountpoint-util: for old kernels, assume "norecovery" is supported by btrfs
Fixup for e3828d7103, as requested in
https://github.com/systemd/systemd/pull/32892#issuecomment-2117903328.
2024-05-21 15:13:42 +02:00
Daan De Meyer e3828d7103 mountpoint-util: Deal with kernel API breakage in "norecovery" mount option
"norecovery" was deprecated for btrfs in
https://github.com/torvalds/linux/commit/74ef00185eb864252156022ff129b01549504175
and removed in
https://github.com/torvalds/linux/commit/a1912f712188291f9d7d434fba155461f1ebef66.

Let's drop our assumption that btrfs supports "norecovery" and first query for the
new name of the option followed by querying for the old name.
2024-05-17 14:29:09 +02:00
Luca Boccassi d50f58d641 Merge pull request #31210 from poettering/chdir-hardening
WorkingDirectory= hardening
2024-02-06 12:41:43 +00:00
Lennart Poettering 0fb08bd5e3 mountpoint-util: add small helper that checks if a path is below the API VFS hierarchies 2024-02-06 11:13:28 +01:00
Mike Yuan b409aacb0a mountpoint-util: introduce path_is_mount_point_full 2024-02-06 15:09:28 +08:00
Mike Yuan 2d70878162 tree-wide: replace FOREACH_POINTER with FOREACH_ARGUMENT
The latter is more generic and while being compatible with
the former.
2024-01-24 21:29:11 +08:00
Daan De Meyer d852352b9c mountpoint-util: Check hardcoded list before asking kernel if option is supported
mount_option_supported() will call fsopen() which will probe the
kernel filesystem module. This means that we'll suddenly start
probing filesystem modules when running generators as those determine
which mount options to use. To prevent generators from loading kernel
filesystem modules as much as possible, let's always first check the
hardcoded list of filesystem which we know support a feature before
falling back to asking the kernel.
2023-10-05 16:50:30 +02:00
Luca Boccassi f273c09c51 mountpoint-util: add bool mount_new_api_supported() helper 2023-10-02 14:02:32 +01:00
Yu Watanabe 68a4fc8b53 fd-util: do not call statx() twice when it does not provide mount ID
Previously, in path_is_root_at(), if statx() does not provide mount ID,
path_get_mnt_id_at() was called, but it also calls statx(). Let's avoid
the second trial.
2023-07-22 02:22:06 +09:00
Yu Watanabe 7487115766 mountpoint-util: statx() may return EINVAL if the kernel does not support the syscall
When statx() is called with AT_STATX_DONT_SYNC, glibc's fallback code
returns EINVAL. See statx_generic() in glibc.
2023-07-22 02:20:22 +09:00
Lennart Poettering c8ab89e569 mountpoint-util: make path_get_mnt_id_at() work with a NULL path 2023-04-25 14:00:38 +02:00
Luca Boccassi 21453b8b4b Merge pull request #27349 from mrc0mmand/codespell
tree-wide: code spelling fixes
2023-04-20 22:02:17 +01:00
Frantisek Sumsal 94d82b5980 tree-wide: code spelling fixes
As reported by Fossies.
2023-04-20 21:54:59 +02:00
Yu Watanabe 4b1e461c49 mountpoint-util: check /proc is mounted on failure 2023-04-19 03:28:34 +09:00
Luca Boccassi 3e5b771755 Merge pull request #27269 from poettering/statx-dont-sync
mountpoint-util: don't go to the network when doing statx() to detect mountpoints/mnt_id
2023-04-14 16:23:51 +01:00
Lennart Poettering d791013ff5 string-util: add strstrafter()
strstrafter() is like strstr() but returns a pointer to the first
character *after* the found substring, not on the substring itself.
Quite often this is what we actually want.

Inspired by #27267 I think it makes sense to add a helper for this,
to avoid the potentially fragile manual pointer increment afterwards.
2023-04-14 16:56:15 +02:00
Lennart Poettering d230d4770d mountpoint-util: use memcmp_nn() where appropriate 2023-04-14 13:15:39 +02:00
Lennart Poettering 524ea5852a mountpoint-util: fix hosed overflow check
The overflow check was hosed in two ways: overflows in C are undefined,
hence gcc was free to just optimize the whole thing away. We need to
catch overflows before we run into them, not after.

It checked for an overflow against size_t, but the field we need to
write this in is unsigned. i.e. typically 32bit rather than 64bit. Hence
check for the right maximum.

(The whole check is paranoia anyway, the kernel really shouldn't return
values that would induce an overflow, but you never know, the syscall
turned out to be problematic in so many other ways, hence let's stick to
this.)
2023-04-14 13:15:39 +02:00
Lennart Poettering 92851defbd mountpoint-util: pass AT_STATX_DONT_SYNC to statx() when looking for mnt_id/mountpoints
The concept of a "mount" is a local one, hence there's no point in going
to the network to retrieve mnt_id or STATX_ATTR_MOUNT_ROOT. Hence set
AT_STATX_DONT_SYNC so that the call will not go to the network ever, and
risk deadlocking on that.

Just some extra safety.
2023-04-14 13:15:35 +02:00
Lennart Poettering 50ed5cbf5f tree-wide: port various places to find_line_startswith() 2023-03-24 18:30:20 +01: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 9bf8441503 mountpoint-util: Add path_get_mnt_id_at() 2023-03-15 11:51:06 +01:00
Lennart Poettering e1349c045e mountpoint-util: add comment explaining why fstype_can_discard() can't use mount_option_supported() 2023-03-09 21:56:42 +01:00
Lennart Poettering 6eda6f7e51 mountpoint-util: add new fstype_can_umask() helper 2023-03-09 21:56:42 +01:00
Lennart Poettering 034ebc47a2 mountpoint-util: move 'norecovery' detection into its own helper call
And let's also ask the kernel explicitly for support.
2023-03-09 21:56:42 +01:00
Lennart Poettering 4e6d305ae2 mountpoint-util: use mount_option_supported() to detect if 'discard' is support for an fs 2023-03-09 21:56:42 +01:00
Lennart Poettering 117e703447 mountpoint-util: generalize mount_option_supported() 2023-03-09 21:56:42 +01:00
Lennart Poettering 7d3b157b77 mountpoint-util: add helper that checks if MS_NOSYMFOLLOW is supported 2023-03-09 16:14:29 +01: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 edac5c4636 mountpoint-util: introduce mount_propagation_flag_is_valid() 2022-12-15 14:15:59 +09:00
Yu Watanabe b205e59ad4 mountpoint-util: rename mount_propagation_flags_to_string() and friends as singular 2022-12-15 14:15:55 +09:00
Yu Watanabe a6e16d949c Merge pull request #25723 from keszybz/generators-tmp
Run generators with / ro and /tmp mounted
2022-12-15 12:53:49 +09:00
Zbigniew Jędrzejewski-Szmek 61ef30515b shared: add new safe_fork flag FORK_PRIVATE_TMP
If the flag is set, we mount /tmp/ in a way that is suitable for generators and
other quick jobs.

Unfortunately I had to move some code from shared/mount-util.c to
basic/mountpoint-util.c. The functions that are moved are very thin wrappers
around mount(2), so this doesn't actually change much in the code split between
libbasic and libshared.

Implications for the host would be weird if a private mount namespace is not
used, so assert on FORK_NEW_MOUNTNS when the flag is used.
2022-12-14 22:12:44 +01:00
David Tardon 229b008635 mountpoint-util: reduce variable scope 2022-12-13 15:47:52 +01:00
Frantisek Sumsal 9bfd596674 Revert "mountpoint-util: tmpfs supports uid=/gid= mount options"
This reverts commit 7d4f00c88c.

fstype_can_uid_gid() is about fixating all files to the specified
uid/gid. tmpfs does not qualify. The uid/gid parameter there is simply
about the default uid/gid for the root inode of the tmpfs, it allows
setting uids/gid arbirarily for all inodes after that.

This distinction matters: for file systems this function returns true
for we can use this in place of uidmapped mounts. But for tmpfs this is
not going to work, given inodes on that fs can end up having arbitrary
uid/gid.

See: https://github.com/systemd/systemd/pull/25284#issue-1438427144
2022-11-07 15:43:54 +01:00
Frantisek Sumsal 7d4f00c88c mountpoint-util: tmpfs supports uid=/gid= mount options
As tmpfs(5) says, both uid= and gid= are supported since kernel 2.5.7 and
the mount utility seems to agree:

```
# stat -c "%U:%G" mnt
root:root
# mount -o uid=testuser,gid=testuser -t tmpfs tmpfs mnt
# stat -c "%U:%G" mnt
testuser:testuser
```

However, systemd-mount currently complains:

```
# systemd-mount --owner testuser -t tmpfs tmpfs mnt
File system type tmpfs is not known to support uid=/gid=, refusing.
```
2022-11-07 00:03:49 +01:00
Thomas Blume d72f4a3897 basic/mountpoint-util: skip dependency on quota services for some filesystems 2022-10-14 20:57:30 +02:00
Lennart Poettering 71c943dc40 mountpoint-util: make fd_is_mountpoint() work reasonably with AT_EMPTYPATH
Inspired by: https://github.com/systemd/systemd/pull/24141

Calling fd_is_mountpoint() with AT_EMPTYPATH and an empty filename can
only work if we have new statx() available. If we do not, we can still
make things work for directories, but not for other inodes (since there
we cannot query information about the parent inode to compare things.)

Hence, let's handle and test this explicitly, to support this to the
level this is possible.
2022-08-02 20:01:59 +02:00
Lennart Poettering a9dac7a6dd tree-wide: port various places over to new stat_inode_same() helper 2022-02-14 17:27:14 +01:00