Commit Graph

781 Commits

Author SHA1 Message Date
Karel Zak 0c19e4ca61 test_mount_optstr: use xstrdup()
Fixes: https://github.com/karelzak/util-linux/issues/1434
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-09-23 13:11:16 +02:00
Rafael Fontenelle 0e85613e3a Fix misspellings 2021-09-04 11:11:04 -03:00
Karel Zak 0fab76bd23 libmount: make mnt_table_get_fs_root() more robust [gcc-analyzer]
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-08-18 11:02:45 +02:00
Karel Zak 6ba7fbb442 libmount: support quotes in X-mount options
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-08-12 13:44:19 +02:00
Karel Zak 52f05cd4c3 libmount: show options string on parse error
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-08-12 13:41:56 +02:00
Karel Zak d85f45d5dd libmount: allow X-* options more than once
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-08-12 13:39:39 +02:00
Karel Zak 315e8f634a libmount: change propagation of /run for X-mount.subdir
We do not need to create a new mount node from /run/mount/tmptgt
(where we mount filesystem root), because /run is already mount
node in all mainstream distros, and we can use MS_PRIVATE for
this top-level directory. There is still fallback if /run is
on root filesystem.

This solution reduces number of mount operations, with the patch the
subdir implementation is:

 * open current namespace from /proc/self/ns/mnt
 * mkdir /run/mount/tmptg (if it does not exist)
 * make /run private by mount(MS_PRIVATE)
 * mount filesystem to /run/mount/tmptg
 * bind mount /run/mount/tmptg/<subdir> to <target>
 * umount /run/mount/tmptg
 * setns() to the original namespace

Signed-off-by: Karel Zak <kzak@redhat.com>
2021-08-12 12:12:39 +02:00
Karel Zak 7ae195affb libmount: use /run/mount/tmptgt rather than /tmp/mount/mount.<pid>
The unshared namespace is per-process, so we can use the same
directory in all mount(8) instances. It's unnecessary to create
and remove process specific directory.

Signed-off-by: Karel Zak <kzak@redhat.com>
2021-08-12 11:34:03 +02:00
Karel Zak f8ccd65956 libmount: remove support for obsolete /dev/.mount/utab
The default is /run/mount/utab for years.

Signed-off-by: Karel Zak <kzak@redhat.com>
2021-08-12 10:44:03 +02:00
Karel Zak e311e731be libmount: add X-mount.subdir=
Like btrfs subvol=, but more generic and for all filesystems. This
feature is marked as EXPERIMENTAL (may be removed).

 # mount /dev/sdc /mnt/test -o X-mount.subdir=AAA

 # findmnt /dev/sdc
 TARGET    SOURCE         FSTYPE OPTIONS
 /mnt/test /dev/sdc[/AAA] ext4   rw,relatime,stripe=512

Implemented as:

 * open current namespace from /proc/self/ns/mnt
 * mkdir /tmp/mount/mount.<pid>
 * unshare mount namespace
 * create mount node from /tmp/mount/mount.<pid> by mount(MS_BIND)
 * mark /tmp/mount/mount.<pid> private by mount(MS_PRIVATE|MS_REC)
 * bind mount /tmp/mount/mount.<pid>/subdir to <target>
 * umount /tmp/mount/mount.<pid>
 * rmdir /tmp/mount/mount.<pid>
 * setns() to the original namespace

Note that /tmp/mount/mount.<pid> conversion to mount node and call for
MS_PRIVATE are visible (propagated to the system) if /tmp is a shared
filesystem, the rest (all operations with the desired filesystem) is
atomic for a parental namespace.

Maybe one day it will be possible to reimplement it in more
elegant way with new mount kernel APIs (open_tree(), etc.).

Fixes: https://github.com/karelzak/util-linux/issues/1103
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-08-11 16:14:38 +02:00
Karel Zak 9ea47344ca lib/buffer: add support for "safe" encoding
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-08-06 12:02:39 +02:00
Karel Zak f60dc88848 lib/buffer: retun size of the buffer and data
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-08-05 16:06:12 +02:00
Karel Zak 2e03758dc5 lib/strutils: add strappend()
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-08-05 15:42:15 +02:00
Karel Zak 8420463b6d lib/strutils: rename strappend() to strconcat()
It concatenates two strings to a new string. It's something else than
"append".

Signed-off-by: Karel Zak <kzak@redhat.com>
2021-08-05 11:30:37 +02:00
Karel Zak afaece0eb2 libmount: assert() is enough [lgtm scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-08-02 10:58:56 +02:00
Karel Zak d6abaa0271 Merge branch 'meson_verity' of https://github.com/bluca/util-linux
* 'meson_verity' of https://github.com/bluca/util-linux:
  meson: fix dlopen support for cryptsetup
  meson: fix crypt_activate_by_signed_key detection
2021-07-14 12:19:49 +02:00
Luca Boccassi 5c49a482a9 verity: fix verity.roothashsig only working as last parameter
Parsing of verity.roothashsig did not take into consideration that other options
might follow, and used the whole string as a file path. But mnt_optstr_get_option
just returns a pointer in the mount option string, it doesn't extract it, so it
would have other subsequent options too. The length parameter has to be used.

Signed-off-by: Luca Boccassi <luca.boccassi@microsoft.com>
2021-07-11 18:14:40 +01:00
Luca Boccassi ce02babfa6 verity: add support for corruption action flag
Add verity.oncorruption= to let users override the default kernel
behaviour, using libcrypsetup's relevant flags.

Signed-off-by: Luca Boccassi <luca.boccassi@microsoft.com>
2021-07-11 18:12:06 +01:00
Luca Boccassi e6a4b4a163 meson: fix dlopen support for cryptsetup
dlopen is treated as a dependency, but that's not quite right, it
should be an alternative way to link to libcryptsetup.
Search for it only if cryptsetup is not disabled, and if the cryptsetup-dlopen
is explicitly set to enabled. If it is, do not link to libcryptsetup.

Add cryptsetup support status to the meson summary.
2021-07-02 19:45:28 +01:00
Karel Zak 5aa726461a libmount: check errno after strto..()
Addresses: https://github.com/karelzak/util-linux/issues/1356
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-06-21 15:03:01 +02:00
Karel Zak 17fc8693cd include/c: add drop_permissions(), consolidate UID/GID reset
Fixes: https://github.com/karelzak/util-linux/issues/1354
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-06-21 12:25:31 +02:00
Karel Zak b77e3e34bf libmount: add __format__ attribute
Reported-by: Jan Pazdziora <jpazdziora@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-06-18 16:34:20 +02:00
Karel Zak ac8697d606 libmount: add mnt_fs_is_regularfs() to public API
Fix: https://github.com/karelzak/util-linux/issues/1328
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-06-02 12:14:10 +02:00
Karel Zak d58121a22a docs: update copyright years
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-05-31 18:12:07 +02:00
Karel Zak 1c0d193441 build-sys: remove with-cryptsetup from tools/config-gen.d/all.conf
Unfortunately libtools is not smart enough to link libblkid
dynamically if we link in-tree static libmount.a for libmount tests.
In this case libtools always uses also libblkid.a, but it's problem
for libcryptsetup which requires versioned symbols from libblkid.so

This is no problem for normal binaries, but for libmount tests only
(where we need static library to by-pass public library API).

Signed-off-by: Karel Zak <kzak@redhat.com>
2021-05-31 17:44:10 +02:00
Karel Zak 903f812d0b libmount: fix memory leak [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-03-25 11:03:03 +01:00
Karel Zak 23b9caa1fc libmount: add assert() to umount lookup code
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-03-25 10:51:54 +01:00
Karel Zak 1c81dfff1a libmount: mnt_table_over_fs() make child optional
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-03-22 15:00:47 +01:00
Karel Zak a605568281 libmount: add mnt_table_over_fs()
The function returns the first over-mount for specified filesystem.

Signed-off-by: Karel Zak <kzak@redhat.com>
2021-03-22 11:24:49 +01:00
Zbigniew Jędrzejewski-Szmek 69939195bd meson: implement building of static programs
The whole thing is complicated by the fact that we have two layers
of libraries: e.g. libmount also needs libblkid. If we just tell meson
to make libmount static, this is not enough, because we also need it
to link to a static libblkid. Hence in the case of libs that link to
other libs internally, we need to create a different object with a
a different set of link_with items.

To avoid building the libraries twice, libfdisk and libmount are first
built into an internal "convenience" library, which is then linked into
the static and shared versions as appropriate.
2021-03-17 15:07:27 +01:00
Zbigniew Jędrzejewski-Szmek d4c880d5a4 meson: add second build system
To build: meson build && ninja -C build
To run tests: ninja -C build check
To install for packaging: DESTDIR=/var/tmp/inst ninja -C build install
To install for realz: sudo ninja -C build install

v2:
- Optional items are now based on the 'feature' feature in meson.
  Built libraries which are disabled turn into disabler() objects
  and also poison any executables which link to them.

What is there:
- building of the binaries and libs and the python module
- installation of binaries, libs, python module, localization files,
  man pages, pkgconfig files
- running of tests
- most options to configure build equivalently to the
  ./configure settings

Partially implemented:
- disabling of stuff when things missing. In the C code, the defines
  are all used, so that should be fine. In the build system, some
  files should be skipped, but that is probably not always done properly.
  Getting this right might require some testing of various build option
  combinations to get the details right.

Not implemented:
- static builds of fdisk and other binaries
- things marked with XXX or FIXME
- ???

Differences:
- .la files are not created. They are useless and everybody hates them.
- Requires.private in pkgconfig files are not present in the
  autogenerated .pc file. Not sure if they should be there or not. If
  necessary, they can be added by hand.
- man pages and systemd units are installed by the install target. Not
  sure why 'make install' doesn't do that.
- the split between / and /usr is probably wrong. But it's all pointless
  anyway, so maybe we could simplify things but not implementing it at
  all under meson?
2021-03-17 15:07:27 +01:00
Karel Zak f823700f61 pylibmount: PyEval_Call* is deprecate, use PyObject_Call*
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-03-15 16:37:47 +01:00
Karel Zak 296b58a79e libmount: (python) fix compiler warning
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-02-17 12:25:49 +01:00
Karel Zak b6787fca02 libmount: fix /{etc,proc}/filesystems use
* always update context->helper
* consolidate helper and syscall status use

Signed-off-by: Karel Zak <kzak@redhat.com>
2021-02-09 10:36:04 +01:00
Frantisek Sumsal 81edf9f0da ci: deal with uninstrumented binaries using instrumented libs
All `eject` tests were failing under ASan, since they call /bin/mount,
which is uninstrumented, but it picks up the instrumented `libblkid`
library, causing ASan to complain:

gcc:
ASan runtime does not come first in initial library list; you should either link runtime to your application or manually preload it with LD_PRELOAD.
eject: unmount of `/home/runner/work/util-linux/util-linux/tests/output/eject/umount-by-disk-mounted-mnt' failed

clang:
/bin/umount: symbol lookup error: /home/runner/work/util-linux/util-linux/.libs/libblkid.so.1: undefined symbol: __sancov_lowest_stack
eject: unmount of `/home/runner/work/util-linux/util-linux/tests/output/eject/umount-by-disk-mounted-mnt' failed

Subsequently, all tests which require the `scsi_debug` module get skipped,
since it's still in use due to the failed umount:

fdisk: align 512/4K                   ... SKIPPED (cannot remove scsi_debug module (rmmod))
fdisk: align 512/4K +alignment_offset ... SKIPPED (cannot remove scsi_debug module (rmmod))
fdisk: align 512/4K +MD               ... SKIPPED (cannot remove scsi_debug module (rmmod))

In case of gcc this can be easily resolved by setting $LD_PRELOAD to the
respective ASan library. clang makes this a bit more difficult, since it
compiles the ASan library statically, so firstly we need to force dynamic
linking (via -shared-asan), and then add the runtime DSO path to the
linker cache, since it's in a non-standard path.
2021-02-01 12:00:30 +01:00
Karel Zak 867df2617c lib: use ul_prefix for close_all_fds() and mkdir_p()
The names are too generic and it makes problems in static libraries.

Addresses: https://gitlab.com/cryptsetup/cryptsetup/-/issues/623
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-01-28 10:27:21 +01:00
Karel Zak 7b78b571b7 libmount: allow --read-only for not-root users
The command "mount -r" was supported for non-root users in very old
mount(8) versions. Unfortunately, in this case libmount replaces all
mount options from command line by options from fstab. We need
exception for MS_RDONLY.

Fixes: https://github.com/karelzak/util-linux/issues/1235
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-01-25 11:11:05 +01:00
Shahid Laher 2c2ff04fe9 libmount: add vboxsf, virtiofs to pseudo filesystems
Filesystems provided by a hypervisor for guest kernels:
* vboxsf: Linux 5.6
* virtiofs: Linux 5.4

Signed-off-by: Shahid Laher <govellius@gmail.com>
2021-01-20 18:04:33 +00:00
Roberto Bergantinos Corpas ff21f476f8 findmnt: add option to list all fs-independent flags
It might be useful for security auditing purposes list all possible
mount flags/options including default set which are normally not listed.

This patch adds "--vfs-all" option to list all fs-independent flags
on VFS-OPTIONS column, as well as libmount funcionality to accomplish
it.

i.e.:

$ findmnt -o VFS-OPTIONS
VFS-OPTIONS
rw,relatime
rw,nosuid,nodev,noexec,relatime
rw,nosuid,nodev,noexec,relatime
ro,nosuid,nodev,noexec
...

$ findmnt --vfs-all -o VFS-OPTIONS
VFS-OPTIONS
rw,exec,suid,dev,async,loud,nomand,atime,noiversion,diratime,relatime,nostrictatime,nolazytime,symfollow
rw,noexec,nosuid,nodev,async,loud,nomand,atime,noiversion,diratime,relatime,nostrictatime,nolazytime,symfollow
rw,noexec,nosuid,nodev,async,loud,nomand,atime,noiversion,diratime,relatime,nostrictatime,nolazytime,symfollow
ro,noexec,nosuid,nodev,async,loud,nomand,atime,noiversion,diratime,norelatime,nostrictatime,nolazytime,symfollow
...

[kzak@redhat.com: - cleanup coding style and comments]

Signed-off-by: Roberto Bergantinos Corpas <rbergant@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-01-15 17:51:07 +01:00
Karel Zak 372ce5b74e libmount: do not canonicalize ZFS source dataset
Fixes: https://github.com/karelzak/util-linux/issues/1231
Addresses: https://github.com/systemd/systemd/issues/18188
Addresses: https://github.com/openzfs/zfs/pull/11295
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-01-14 13:45:20 +01:00
Karel Zak ca27216aa6 build-sys: remove fallback for security_context_t
It seems like overkill to provide this #ifdef. For example coreutils
use "char *" for all selinux contexts (since 2014).

Signed-off-by: Karel Zak <kzak@redhat.com>
2021-01-13 13:12:19 +01:00
Karel Zak f19295ad12 libmount: mark entries from /proc/swaps by MNT_FS_SWAP
The function mnt_fs_is_swaparea() does not return TRUE for entries
from /proc/swaps. This is pretty strange.

Signed-off-by: Karel Zak <kzak@redhat.com>
2021-01-08 12:00:59 +01:00
Karel Zak 79acb5bf1e docs: update TODO (add item about mnt_context_get_excode() )
- add item about https://github.com/karelzak/util-linux/issues/1208
- remove old CAP_SYS_ADMIN note (in last versions mount(8) drops suid if
  necessary).

Addresses: https://github.com/karelzak/util-linux/issues/1208
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-01-06 15:17:19 +01:00
Karel Zak 22a64b02b9 libmount: fix compiler warnings [-Wmaybe-uninitialized]
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-12-17 11:07:25 +01:00
Karel Zak eba9ef598f libmount: don't use deprecated security_context_t
libselinux >= 3.1 makes security_context_t type deprecated. Let's
ifdef it to avoid unwanted warnings.

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-12-14 15:54:08 +01:00
Karel Zak cd588d6653 fuzzers: make tests setup more robust
- use robust functions like write_all()
- don't use assert() to check write/open/etc return values, because oss-fuzz.com
  report foreign (system, libc, ...) issues as our fails

Addresses: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=28009
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-12-01 11:35:02 +01:00
Karel Zak 52f730e478 libmount: don't use "symfollow" for helpers on user mounts
Addresses: https://github.com/karelzak/util-linux/issues/1193
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-19 09:49:16 +01:00
Samanta Navarro bd0f347f86 misc: fix typos
Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
2020-11-04 11:42:28 +00:00
Dr. David Alan Gilbert 97c9ec9ce3 libmount: Fix 0x%u usage
There's a couple of places which use varients on "0x%u" in format strings;
that's almost always wrong - you either want 0x%x or just %u.  In libmount's
case it's flags, so I'm assuming the intention really is hex.  In the ja.po
case it's %u in the original msgid.

Signed-off-by: Dr. David Alan Gilbert <dave@treblig.org>
2020-10-19 12:15:15 +02:00
Karel Zak ab35743a0f libmount: optimize mnt_optstr_apply_flags()
We append to the options string in loop there. It seems better to use
ul_buffer for this case to avoid duplicate strlen() and reallocs.

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-09-29 12:31:06 +02:00