Commit Graph

710 Commits

Author SHA1 Message Date
Gabriel de Perthuis 3dde0d076d Add to the list of pseudo-filesystem types
Useful commands for maintaining the list:

    grep -w ^nodev /proc/filesystems |sort

In a Linux source checkout:

    git grep -wl file_system_type '*.c' |xargs grep -L FS_REQUIRES_DEV |xargs grep -wA12 file_system_type |grep -F '.name' |uniq |column -t
2020-05-20 20:28:01 +02:00
Karel Zak 6390860d71 libmount: (umount) fix FD leak
References: 7065cc0e53
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-05-15 12:09:43 +02:00
Roberto Bergantinos Corpas 31b3a523ec libmount: fix mount -a EBUSY for cifs
fstab:

 //rhel73/myshare/sub/path  /mnt   cifs

after mount in mountinfo:

 #  grep cifs /proc/self/mountinfo
 47 39 0:40 /sub/path /mnt rw,relatime shared:60 - cifs //rhel73/myshare/sub/path ...
            ^^^^^^^^^
or:

 # grep cifs /proc/self/mountinfo
 47 39 0:40 / /mnt rw,relatime shared:60 - cifs //rhel73/myshare/sub/path ...
            ^

That is so since on kernel cifs code, cifs_get_root (which returns the
entry associated with mnt_root) return s_root if
CIFS_MOUNT_USE_PREFIX_PATH is set, no questions asked.

This situation can occurr often on CIFS mounts, as CIFS servers limit
frequently scope of access to the root path.

[kzak@redhat.com: - add more info to the commit message,
                  - clean up variable names]

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1826719
Signed-off-by: Roberto Bergantinos Corpas <rbergant@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-04-27 15:46:02 +02:00
Tycho Andersen 64cb2da8dc libmount: do not unnecessarily chmod utab.lock
Before ecfeae90a2 ("libmount: Ensure utab.lock mode 644"), you could do
something like:

irc:/tmp umount --version
umount from util-linux 2.27.1 (libmount 2.27.0: selinux, assert, debug)
irc:/tmp mkdir foo bar
irc:/tmp unshare -Urm
irc:/tmp mount --bind foo bar
irc:/tmp umount bar
irc:/tmp echo $?
0

However, afterwards, you get:

/tmp unshare -Urm
/tmp mount --bind foo bar
/tmp umount bar
umount: /tmp/bar: filesystem was unmounted, but failed to update userspace mount table.

Because of the chmod failing:

fchmod(3, 0644)                         = -1 EPERM (Operation not permitted)

Let's figure out whether the chmod is necessary before doing it, and only
do it if it is necessary. This won't fix cases where the system is already
broken, but at least on healthy systems umount will behave as before.

Signed-off-by: Tycho Andersen <tycho@tycho.ws>
2020-04-22 12:36:43 +02:00
Karel Zak 69fe4f4ba6 Merge branch 'clang' of https://github.com/neheb/util-linux
* 'clang' of https://github.com/neheb/util-linux:
  [clang-tidy] fix misleading identation
  [clang-tidy] use ceil
  [clang-tidy] fix wrong *cmp usage
  [clang-tidy] do not use else after return
  [clang-tidy] do not return in void functions
  [clang-tidy] fix mismatching declarations
2020-04-22 10:07:51 +02:00
Karel Zak e2aedec8d1 pylibmount: cleanup and sync UL_RaiseExc
Addresses: https://github.com/karelzak/util-linux/issues/1013
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-04-22 09:44:47 +02:00
Rosen Penev ad296391f9
[clang-tidy] fix wrong *cmp usage
Found with bugprone-suspicious-string-compare

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-04-20 13:21:00 -07:00
Rosen Penev 042f62dfc5
[clang-tidy] do not use else after return
Found with readability-else-after-return

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-04-20 13:20:59 -07:00
Karel Zak 3168ba091f libmount: use mnt_stat_mountpoint() on more places
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-04-06 11:58:29 +02:00
Fabian Vogt 7065cc0e53 libmount: Avoid triggering autofs in lookup_umount_fs_by_statfs
Currently, umount /foo results in a statfs("/foo") call, which triggers
autofs. This can create another mountpoint on /foo, which is then unmounted
later instead of the actual /foo at the time umount was called.

This is especially an issue for umount -R /bar, which just fails with
-EBUSY as the accidental mountpoint is never accounted for and so it tries
to umount /bar before /bar/someautofs.

Replace the direct statfs call with open(path, O_PATH) + fstatfs, which sees
the autofs mount directly, without triggering it.
2020-04-01 13:34:43 +02:00
Karel Zak a971746370 libmount: make mnt_context_find_umount_fs() more extendable
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-03-27 11:34:12 +01:00
Karel Zak 4ce77c625a libmount: (umount) FS lookup refactoring
Let's split lookup to more function to make it easy to add another
lookup method.

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-03-27 11:10:26 +01:00
Karel Zak 36d80cb6c1 libmount: smb2 is unsupported alias
Kenneth D'souza wrote:
 # grep -w MODULE_ALIAS_FS fs/cifs/cifsfs.c
 MODULE_ALIAS_FS("cifs");
 112/112│MODULE_ALIAS_FS("smb3");

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1812118
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-03-11 18:38:09 +01:00
Karel Zak b7ff4134be libmount: improve smb{2,3} support
It seems kernel can use smb3 as fstype in mountinfo.

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1812118
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-03-11 10:47:52 +01:00
Karel Zak 11b916cdab libmount: try read-only mount on write-protected superblock too
The classic mount(8) behavior is to try read-only on write-protected devices
if the first mount syscall attempt ends with EACCES.

It seems we can implement this feature also for EBUSY if the same mount source
is already mounted with "ro" superblock option.

The typical use-case is iso image (always read-only) mounted on two places.

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1809124
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-03-03 11:39:10 +01:00
Karel Zak acd229fc2a libmount: move "already mounted" code to separate function
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-03-03 10:55:28 +01:00
Karel Zak 88f04bf9e6 libmount: fix x- options use for non-root users
libmount returns EPERM for all X- and x- mount options for non-root
users when evaluate X-mount.mkdir. It's bug, we need to be sensitive
to only X-mount.mkdir and only if the target directory is missing.

Addresses: https://github.com/karelzak/util-linux/issues/941
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-01-28 10:54:33 +01:00
Karel Zak e3e7cd659e Merge branch 'dmverity_sig' of https://github.com/bluca/util-linux
* 'dmverity_sig' of https://github.com/bluca/util-linux:
  libmount: add support for signed verity devices
2020-01-23 15:47:15 +01:00
Karel Zak eae8661e68 libmount: (monitor) remove dead code [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-01-15 14:08:06 +01:00
Karel Zak 810dfb7de6 libmount: use vsnprintf() in more robust way [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-01-15 13:59:42 +01:00
Luca Boccassi 123b1a6708 libmount: add support for signed verity devices
A new API was added to libcryptsetup to make use of the kernel's new
CONFIG_DM_VERITY_VERIFY_ROOTHASH_SIG feature, which allows to sign
root hashes. Add a verity.roothashsig option to use it.
Device reuse will be allowed only if signatures are used by all, or
by none.
2020-01-13 12:24:55 +00:00
Karel Zak bb607cb3b2 docs: fix typos [fossies codespell scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-01-09 10:18:16 +01:00
Luca Boccassi e7924c4f15 libmount: do not obscure return code when checking verity options
In some corner cases, the return code was being overwritten without
being checked
2020-01-08 12:59:23 +01:00
Karel Zak 24cee7157a docs: update year in libs docs
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-01-06 12:59:45 +01:00
Karel Zak 6b0094d0c1 libmount: improve X-mount.mkdir for non-root users
Since v2.35 mount(8) drops suid on -EPERM and repeat necessary actions
before mount(2) syscall. This patch also improves this behavior for
X-mount.mkdir too.

mount(8):
 * return -EPERM on sanitize_paths() rather than call err()
 * call suid_drop() on failed sanitize_paths()
 * update man page

libmount:
 * mnt_context_prepare_target() refactoring
 * return -EPERM when in restricted mode for X-mount.mkdir

Fixed version:
 /home/kzak/mnt-foo   sr.net.home:/home/kzak   fuse.sshfs noauto,X-mount.mkdir

 $ mount /home/kzak/mnt-foo
 kzak@sr.net.home's password:

 $ /home/projects/util-linux/util-linux  findmnt /home/kzak/mnt-foo
 TARGET             SOURCE                 FSTYPE     OPTIONS
 /home/kzak/mnt-foo sr.net.home:/home/kzak fuse.sshfs rw,nosuid,nodev,relatime,user_id=1000,group_id=1000

Addresses: https://github.com/systemd/systemd/issues/14418
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-01-03 10:48:09 +01:00
Luca Boccassi 9835a4b6a1 verity: add support for Forward Error Correction options
Requires kernel built with CONFIG_DM_VERITY_FEC.
2019-12-10 12:52:39 +00:00
Luca Boccassi fe8358bf05 verity: ensure that hash_device and root_hash[_file] are passed together or not at all
If a hash device or a roothash are passed for verity usage, both have to be present
or we cannot use them. Make it an error to pass only one of them.
2019-12-10 12:52:39 +00:00
Luca Boccassi 141bb954e7 verity: add new verity.roothashfile option
Allow users to point mount to a file to read the roothash, in addition
to passing it inline.
Allows a volume managed by a systemd mount unit to be updated without
changing the mount unit content itself, for easier and more user friendly
servicing.
2019-12-10 12:52:39 +00:00
Karel Zak cbc390da3a libmount: add verity to mount -V output
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-12-05 14:57:29 +01:00
Karel Zak 9309ca1b93 Merge branch 'dmverity' of https://github.com/bluca/util-linux
* 'dmverity' of https://github.com/bluca/util-linux:
  libmount: add support for verity devices via libcryptsetup
2019-12-05 13:23:46 +01:00
Luca Boccassi e6a498877c libmount: add support for verity devices via libcryptsetup
The following new options are added:

verity.hashdevice
verity.roothash
verity.hashoffset

The source path will be used as a dm-verity object, and will be
opened using libcryptsetup APIs.

A new --with-cryptsetup build-time option is added, which adds a
dependency on libcryptsetup. To ease bootstrapping, given libcryptsetup
build-depends on util-linux for libuuid, if --with-cryptsetup=yes but
libcryptsetup is not installed only a warning will be printed at
configure time rather than an error. This way stage0/first stage/ring0
builds can use the same configure options but avoid installing
cryptsetup to get a working base set, and then rebuild util-linux in
the next step of the boostrapping process.

If verity options are selected but cannot be fullfilled due to lack of
dependencies, mounting a volume will fail even if using a loop device
would work as a fallback, to avoid silently skipping integrity checks.
2019-12-05 10:39:21 +00:00
Karel Zak 3861c371f6 Merge branch 'mount-eperm'
* mount-eperm:
  mount: no exit on EPERM, continue without suid
2019-12-03 15:23:53 +01:00
Karel Zak 6f7c67a5ff libmount: fix typo in mnt_context_prepare_helper() [lgtm scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-12-03 14:31:55 +01:00
Karel Zak 6497f2d99e mount: no exit on EPERM, continue without suid
The current libmount assumes that mount(8) and umount(8) are suid
binaries. For this reason it implements internal rules which
restrict what is allowed for non-root users. Unfortunately, it's
out of reality for some use-cases where root permissions are no
required. Nice example are fuse filesystems.

So, the current situation is to call exit() always when mount, umount or
libmount are unsure with non-root user rights. This patch removes the
exit() call and replaces it with suid permissions drop, after that it
continues as usually. It means after suid-drop all depend on kernel
and no another security rule is used by libmount (simply because any
rule is no more necessary).

Example:

old version:
   $ mount -t fuse.sshfs kzak@192.168.111.1:/home/kzak /home/kzak/mnt
   mount: only root can use "--types" option

new version:
   $ mount -t fuse.sshfs kzak@192.168.111.1:/home/kzak /home/kzak/mnt
   kzak@192.168.111.1's password:

   $ findmnt /home/kzak/mnt
   TARGET         SOURCE                        FSTYPE     OPTIONS
   /home/kzak/mnt kzak@192.168.111.1:/home/kzak fuse.sshfs rw,nosuid,nodev,relatime,user_id=1000,group_id=1000

   $ umount /home/kzak/mnt
   $ echo $?
   0

Note that fuse user umount is supported since v2.34 due to user_id= in
kernel mount table.

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-11-19 14:58:20 +01:00
Karel Zak 916a3f8d29 libmount: don't access struct member, use API
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-11-18 16:19:15 +01:00
Karel Zak 6a735c2c5b libmount: make sure optsmode is initialized
Since 34333e5244 we apply fstab options
manually by mnt_context_apply_fs() on --all. The function does not
work correctly when optsmode is zero.

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-10-31 13:51:29 +01:00
Karel Zak 34333e5244 libmount: allow use -o together with --all
For example:
	# mount --verbose --all -t xfs -o ro

will mount all all XFS filesystems from fstab, but read-only.

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-10-31 12:25:08 +01:00
Karel Zak 7a56878d4b libmount: move context fs merge to separate function
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-10-31 12:25:08 +01:00
Karel Zak e5d2044407 libmount: fix mnt_context_next_remount()
The current implementation works, but the remount operation is done in
the cloned context and the original context (and calling application)
has no information about the final status/errors. This is mistake.

This new implementation works like mnt_context_next_mount(), it means
the same context (as used by application) is reused for all remounts.
The original setting is restored by mnt_context_apply_template().

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-10-31 12:25:08 +01:00
Karel Zak e83c09d49e libmount: save current FS setting as template
This commit adds new functions to save and reuse the current FS
setting (mount options from command line, etc) after context reset.
It's usable for example in "mount --all" when we use the same context
for more times for more mount operations.

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-10-31 12:25:08 +01:00
Karel Zak eee7ea558c libmount: use strdup_between_structs()
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-10-31 12:25:08 +01:00
Karel Zak 779e3c97aa libmount: cleanup strdup() use in context, add reg.test
* don't ignore strdup() result
* cleanup mnt_context_prepare_helper() to have only one return point
  (due to mnt_context_switch_ns())
* add mnt_context_prepare_helper() test program

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-10-31 12:25:08 +01:00
Karel Zak 71ed3b8337 libmount: add target prefix support
* add set/get functions to context
* use prefix to detect already mounted filesystems
* use prefix when prepare target path

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-10-31 12:25:08 +01:00
Karel Zak 05842a92d8 libmount: don't use /proc/mounts fallback if filename specified
The current solution is to use /proc/mounts if previous attempt to
open /proc/self/mountinfo failed. The fallback should not be used when
mount table path is explicitly specified by application. The default
is NULL, only in this case libmount should be try to be smart.

Reported-by: Alasdair G Kergon <agk@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-10-29 12:59:08 +01:00
Masami Hiramatsu 9ae113ca73 libmount: Add libselinux dependency to pkgconfig file
Add libselinux dependency to libmount if it is compiled
with selinux support.

Without this fix, 'pkg-config --libs --static mount' doesn't
show libselinux related options.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
2019-10-11 10:28:57 +02:00
Darsey Litzenberger e7305e4ea3 libmount: Recognize more FUSE pseudofs (avfsd, lxcfs, vmware-vmblock)
General info about these filesystems:

* fuse.avfsd: https://sourceforge.net/projects/avf/
* fuse.lxcfs: https://linuxcontainers.org/lxcfs/
* fuse.vmware-vmblock: https://github.com/vmware/open-vm-tools

Signed-off-by: Darsey Litzenberger <dlitz@dlitz.net>
2019-10-02 17:29:05 -07:00
Elliott Mitchell 2bb3aa36b2 cleanup: Remove some spurious spaces
Sorry detail-oriented people tend to wipe these out if they notice them.
Add in automated tools and lots of excess end-of-line spaces get wiped
out.

Addresses: https://github.com/karelzak/util-linux/pull/849
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-10-01 13:01:43 +02:00
Karel Zak bc747dfccf libmount: fix free() call on error
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-09-21 11:16:34 +02:00
Karel Zak 026f7d3020 libmount: use fmemopen() in more robust way [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-09-20 13:00:19 +02:00
Karel Zak 987ec2a696 libmount: fix typo
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-09-03 16:18:48 +02:00