]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: remove support for writable /etc/mtab
authorKarel Zak <kzak@redhat.com>
Fri, 17 Jun 2022 11:42:11 +0000 (13:42 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 17 Jun 2022 11:42:11 +0000 (13:42 +0200)
This commit removes --enable-libmount-support-mtab.

The classic /etc/mtab is broken by design. It does not support
namespaces, chroots, etc. The only sane way to keep track of
mounted filesystems is to ask the kernel. It's a bad idea to maintain
a mount table in userspace.

Signed-off-by: Karel Zak <kzak@redhat.com>
14 files changed:
configure.ac
libmount/src/context.c
libmount/src/context_mount.c
libmount/src/tab_parse.c
libmount/src/tab_update.c
libmount/src/version.c
tests/functions.sh
tests/ts/libmount/context
tests/ts/libmount/context-py
tests/ts/libmount/update
tests/ts/mount/devname
tests/ts/mount/remount
tests/ts/mount/rlimit [deleted file]
tests/ts/mount/umount-alltargets

index 5821a3bf1c5435f7fbfe85c64d149d5a92bbb4d0..824e8bbd244e95731ffb226c6d9e645ce78c2c12 100644 (file)
@@ -1176,10 +1176,6 @@ AC_ARG_ENABLE([libmount-support-mtab],
   [], [enable_libmount_support_mtab=no]
 )
 
-AS_IF([test "x$enable_libmount_support_mtab" = xyes], [
-  AC_DEFINE([USE_LIBMOUNT_SUPPORT_MTAB], [1], [Define to 1 if want to support mtab.])
-])
-
 dnl
 dnl libsmartcols
 dnl
index 7927012d2080b5afe9c6fb490899aa849fe6dd4c..ac74c0e7b344c054c38602b334a4494edd785acd 100644 (file)
@@ -346,12 +346,6 @@ static int context_init_paths(struct libmnt_context *cxt, int writable)
 
        assert(cxt);
 
-#ifdef USE_LIBMOUNT_SUPPORT_MTAB
-       if (!cxt->mtab_path) {
-               cxt->mtab_path = mnt_get_mtab_path();
-               DBG(CXT, ul_debugobj(cxt, "mtab path initialized to: %s", cxt->mtab_path));
-       }
-#endif
        if (!cxt->utab_path) {
                cxt->utab_path = mnt_get_utab_path();
                DBG(CXT, ul_debugobj(cxt, "utab path initialized to: %s", cxt->utab_path));
@@ -372,12 +366,7 @@ static int context_init_paths(struct libmnt_context *cxt, int writable)
        if (!ns_old)
                return -MNT_ERR_NAMESPACE;
 
-#ifdef USE_LIBMOUNT_SUPPORT_MTAB
-       mnt_has_regular_mtab(&cxt->mtab_path, &cxt->mtab_writable);
-       if (!cxt->mtab_writable)
-#endif
-               /* use /run/mount/utab if /etc/mtab is useless */
-               mnt_has_regular_utab(&cxt->utab_path, &cxt->utab_writable);
+       mnt_has_regular_utab(&cxt->utab_path, &cxt->utab_writable);
 
        if (!mnt_context_switch_ns(cxt, ns_old))
                return -MNT_ERR_NAMESPACE;
index 6af83e0412fa8128c14d8efcf8245d8609db1488..0ebf8ec1b392f550d06c98f68b31953028325f2a 100644 (file)
@@ -1214,48 +1214,6 @@ int mnt_context_do_mount(struct libmnt_context *cxt)
        } else
                res = do_mount_by_pattern(cxt, cxt->fstype_pattern);
 
-#ifdef USE_LIBMOUNT_SUPPORT_MTAB
-       if (mnt_context_get_status(cxt)
-           && !mnt_context_is_fake(cxt)
-           && !cxt->helper
-           && mnt_context_mtab_writable(cxt)) {
-
-               int is_rdonly = -1;
-
-               DBG(CXT, ul_debugobj(cxt, "checking for RDONLY mismatch"));
-
-               /*
-                * Mounted by mount(2), do some post-mount checks
-                *
-                * Kernel can be used to use MS_RDONLY for bind mounts, but the
-                * read-only request could be silently ignored. Check it to
-                * avoid 'ro' in mtab and 'rw' in /proc/mounts.
-                */
-               if ((cxt->mountflags & MS_BIND)
-                   && (cxt->mountflags & MS_RDONLY)) {
-
-                       if (is_rdonly < 0)
-                               is_rdonly = mnt_is_readonly(mnt_context_get_target(cxt));
-                       if (!is_rdonly)
-                               mnt_context_set_mflags(cxt, cxt->mountflags & ~MS_RDONLY);
-               }
-
-
-               /* Kernel can silently add MS_RDONLY flag when mounting file
-                * system that does not have write support. Check this to avoid
-                * 'ro' in /proc/mounts and 'rw' in mtab.
-                */
-               if (!(cxt->mountflags & (MS_RDONLY | MS_MOVE))
-                   && !mnt_context_propagation_only(cxt)) {
-
-                       if (is_rdonly < 0)
-                               is_rdonly = mnt_is_readonly(mnt_context_get_target(cxt));
-                       if (is_rdonly)
-                               mnt_context_set_mflags(cxt, cxt->mountflags | MS_RDONLY);
-               }
-       }
-#endif
-
        /* Cleanup will be immediate on failure, and deferred to umount on success */
        if (mnt_context_is_veritydev(cxt))
                mnt_context_deferred_delete_veritydev(cxt);
index 4407f9c9c7652727646d6a33c862b2495554e6b7..c5de990414703e1db0e85cdde8903cf5314e9555 100644 (file)
@@ -1172,27 +1172,6 @@ int __mnt_table_parse_mtab(struct libmnt_table *tb, const char *filename,
        if (filename)
                DBG(TAB, ul_debugobj(tb, "%s requested as mtab", filename));
 
-#ifdef USE_LIBMOUNT_SUPPORT_MTAB
-       if (mnt_has_regular_mtab(&filename, NULL)) {
-
-               DBG(TAB, ul_debugobj(tb, "force mtab usage [filename=%s]", filename));
-
-               rc = mnt_table_parse_file(tb, filename);
-
-               /*
-                * If @filename forces us to read from /proc then also read
-                * utab file to merge userspace mount options.
-                */
-               if (rc == 0 && is_mountinfo(tb))
-                       goto read_utab;
-
-               if (!rc)
-                       return 0;
-               filename = NULL;        /* failed */
-       } else
-               filename = NULL;        /* mtab useless */
-#endif
-
        if (!filename || strcmp(filename, _PATH_PROC_MOUNTINFO) == 0) {
                filename = _PATH_PROC_MOUNTINFO;
                tb->fmt = MNT_FMT_MOUNTINFO;
@@ -1212,9 +1191,6 @@ int __mnt_table_parse_mtab(struct libmnt_table *tb, const char *filename,
 
        if (!is_mountinfo(tb))
                return 0;
-#ifdef USE_LIBMOUNT_SUPPORT_MTAB
-read_utab:
-#endif
        DBG(TAB, ul_debugobj(tb, "mtab parse: #2 read utab"));
 
        if (mnt_table_get_nents(tb) == 0)
index 3a22e7188b94b6d44cdcffd0f736c1ff2ac8c40b..6e16cd165e2f7ef53c50a692d2d90a9b694f717b 100644 (file)
@@ -111,16 +111,11 @@ int mnt_update_set_filename(struct libmnt_update *upd, const char *filename,
 
        /* detect tab filename -- /etc/mtab or /run/mount/utab
         */
-#ifdef USE_LIBMOUNT_SUPPORT_MTAB
-       mnt_has_regular_mtab(&path, &rw);
-#endif
-       if (!rw) {
-               path = NULL;
-               mnt_has_regular_utab(&path, &rw);
-               if (!rw)
-                       return -EACCES;
-               upd->userspace_only = TRUE;
-       }
+       path = NULL;
+       mnt_has_regular_utab(&path, &rw);
+       if (!rw)
+               return -EACCES;
+       upd->userspace_only = TRUE;
        upd->filename = strdup(path);
        if (!upd->filename)
                return -ENOMEM;
index b69b09a170bcd3a870b209fc3f824a6c10c85645..211bb9fe4feeb5b295855ba0a10623a7cc03ea9e 100644 (file)
@@ -34,9 +34,6 @@ static const char *lib_features[] = {
 #ifdef HAVE_CRYPTSETUP
        "verity",
 #endif
-#ifdef USE_LIBMOUNT_SUPPORT_MTAB
-       "mtab",
-#endif
 #ifdef USE_LIBMOUNT_SUPPORT_NAMESPACES
        "namespaces",
 #endif
index 561412212066942461bf57a2efe3bcc6ef0e11f4..e24d5c87984d94787d605fe403613f3f9ccd485b 100644 (file)
@@ -1073,15 +1073,6 @@ function ts_init_socket_to_file {
        fi
 }
 
-function ts_has_mtab_support {
-       grep -q '#define USE_LIBMOUNT_SUPPORT_MTAB' ${top_builddir}/config.h
-       if [ $? == 0 ]; then
-               echo "yes"
-       else
-               echo "no"
-       fi
-}
-
 function ts_has_ncurses_support {
        grep -q '#define HAVE_LIBNCURSES' ${top_builddir}/config.h
        if [ $? == 0 ]; then
index 70c779cdf636b6ad06ce20ed29b23bd46efc6ae5..da1ba715254f30b5e08f5689c2a79f2ae36c381d 100755 (executable)
@@ -32,12 +32,6 @@ $TS_CMD_UMOUNT $MOUNTPOINT &> /dev/null
 ts_scsi_debug_init dev_size_mb=100
 DEVNAME=$(basename $TS_DEVICE)
 
-MOUNTINFO_ONLY=yes
-has_mtab=$( ts_has_mtab_support )
-if [ "$has_mtab" == "yes" ]; then
-       MOUNTINFO_ONLY=no
-fi
-
 ts_log "Create partitions"
 $TS_CMD_FDISK --noauto-pt ${TS_DEVICE} &> /dev/null <<EOF
 o
@@ -64,17 +58,9 @@ mkfs.ext4 -L "$LABEL" -U "$UUID" $DEVICE &> /dev/null
 
 ts_log "Do tests..."
 
-export LIBMOUNT_MTAB=$TS_OUTPUT.mtab
-> $LIBMOUNT_MTAB
-
-# check local mtab of system mountinfo
 function is_mounted {
-       if [ "$MOUNTINFO_ONLY" = "yes" ]; then
-               ts_is_mounted "$1"
-               return $?
-       fi
-       grep -q "$1" $LIBMOUNT_MTAB && return 0
-       return 1
+       ts_is_mounted "$1"
+       return $?
 }
 
 
index a6a081694bb4e9607d4b0e82f88a3ae6e7d7b3c0..c5029f479a76247927c94aa269732a89d75131c7 100755 (executable)
@@ -41,12 +41,6 @@ $TS_CMD_UMOUNT $MOUNTPOINT &> /dev/null
 ts_scsi_debug_init dev_size_mb=100
 DEVNAME=$(basename $TS_DEVICE)
 
-MOUNTINFO_ONLY=yes
-has_mtab=$( ts_has_mtab_support )
-if [ "$has_mtab" == "yes" ]; then
-       MOUNTINFO_ONLY=no
-fi
-
 ts_log "Create partitions"
 $TS_CMD_FDISK --noauto-pt ${TS_DEVICE} &> /dev/null <<EOF
 o
@@ -73,17 +67,9 @@ mkfs.ext4 -L "$LABEL" -U "$UUID" $DEVICE &> /dev/null
 
 ts_log "Do tests..."
 
-export LIBMOUNT_MTAB=$TS_OUTPUT.mtab
-> $LIBMOUNT_MTAB
-
-# check local mtab of system mountinfo
 function is_mounted {
-       if [ "$MOUNTINFO_ONLY" = "yes" ]; then
-               ts_is_mounted "$1"
-               return $?
-       fi
-       grep -q "\(^\| \)$1 " $LIBMOUNT_MTAB && return 0
-       return 1
+       ts_is_mounted "$1"
+       return $?
 }
 
 
index abc1547829bc25aef9c4616a601a2ca13e875a9e..fb69bee2d13f37607229355b264ddcff211cc8be 100755 (executable)
@@ -19,54 +19,11 @@ TESTPROG="$TS_HELPER_LIBMOUNT_UPDATE"
 #    redefined to subtest specific namespace -- it means that $TS_OUTPUT is a
 #    different file within a subtest.
 #
-#  - all this test uses global $TS_OUTPUT.{mtab,mountinfo}
-
-export LIBMOUNT_MTAB=$TS_OUTPUT.mtab
-rm -f $LIBMOUNT_MTAB
-> $LIBMOUNT_MTAB
-
-
-#
-# Traditional /etc/mtab
-#
-has_mtab=$( ts_has_mtab_support )
-if [ "$has_mtab" == "yes" ]; then
-
-       ts_init_subtest "mtab-mount"
-       ts_run $TESTPROG --add /dev/sda1 /mnt/foo ext3 "rw,bbb,ccc,fff=FFF,ddd,noexec"
-       ts_run $TESTPROG --add /dev/sdb1 /mnt/bar ext3 "gg=G,ffff=f,ro,noatime"
-       ts_run $TESTPROG --add /dev/sda2 /mnt/bar ext3 "rw,noatime"
-       ts_run $TESTPROG --add /dev/sda1 /mnt/gogo ext3 "rw,noatime,nosuid"
-       ts_run $TESTPROG --add none /proc proc defaults
-       cp $LIBMOUNT_MTAB $TS_OUTPUT    # save the mtab aside
-       ts_finalize_subtest             # checks the mtab
-
-       ts_init_subtest "mtab-move"
-       ts_run $TESTPROG --move /mnt/foo /mnt/newfoo
-       ts_run $TESTPROG --move /mnt/bar /mnt/newbar
-       cp $LIBMOUNT_MTAB $TS_OUTPUT    # save the mtab aside
-       ts_finalize_subtest             # checks the mtab
-
-       ts_init_subtest "mtab-remount"
-       ts_run $TESTPROG --remount /mnt/newfoo "ro,noatime"
-       ts_run $TESTPROG --remount /mnt/bar "rw,atime,nosuid"
-       cp $LIBMOUNT_MTAB $TS_OUTPUT    # save the mtab aside
-       ts_finalize_subtest             # checks the mtab
-
-       ts_init_subtest "mtab-umount"
-       ts_run $TESTPROG --remove /mnt/bar
-       ts_run $TESTPROG --remove /mnt/gogo
-       ts_run $TESTPROG --remove /proc
-       cp $LIBMOUNT_MTAB $TS_OUTPUT    # save the mtab aside
-       ts_finalize_subtest             # checks the mtab
-fi
+#  - all this test uses global $TS_OUTPUT.mountinfo
 
 #
 # utab
 #
-rm -f $LIBMOUNT_MTAB
-ln -s /proc/mounts $LIBMOUNT_MTAB
-
 export LIBMOUNT_UTAB=$TS_OUTPUT.utab
 rm -f $LIBMOUNT_UTAB
 > $LIBMOUNT_UTAB
@@ -76,26 +33,26 @@ ts_run $TESTPROG --add /dev/sda1 /mnt/foo ext3 "rw,bbb,ccc,fff=FFF,ddd,noexec"
 ts_run $TESTPROG --add /dev/sdb1 /mnt/bar ext3 "ro,user"
 ts_run $TESTPROG --add /dev/sda2 /mnt/xyz ext3 "rw,loop=/dev/loop0,uhelper=hal"
 ts_run $TESTPROG --add none /proc proc "rw,user"
-cp $LIBMOUNT_UTAB $TS_OUTPUT   # save the mtab aside
-ts_finalize_subtest            # checks the mtab
+cp $LIBMOUNT_UTAB $TS_OUTPUT   # save the utab aside
+ts_finalize_subtest            # checks the utab
 
 ts_init_subtest "utab-move"
 ts_run $TESTPROG --move /mnt/bar /mnt/newbar
 ts_run $TESTPROG --move /mnt/xyz /mnt/newxyz
-cp $LIBMOUNT_UTAB $TS_OUTPUT   # save the mtab aside
-ts_finalize_subtest            # checks the mtab
+cp $LIBMOUNT_UTAB $TS_OUTPUT   # save the utab aside
+ts_finalize_subtest            # checks the utab
 
 ts_init_subtest "utab-remount"
 ts_run $TESTPROG --remount /mnt/newbar "ro,noatime"
 ts_run $TESTPROG --remount /mnt/newxyz "rw,user"
-cp $LIBMOUNT_UTAB $TS_OUTPUT   # save the mtab aside
-ts_finalize_subtest            # checks the mtab
+cp $LIBMOUNT_UTAB $TS_OUTPUT   # save the utab aside
+ts_finalize_subtest            # checks the utab
 
 ts_init_subtest "utab-umount"
 ts_run $TESTPROG --remove /mnt/newbar
 ts_run $TESTPROG --remove /proc
-cp $LIBMOUNT_UTAB $TS_OUTPUT   # save the mtab aside
-ts_finalize_subtest            # checks the mtab
+cp $LIBMOUNT_UTAB $TS_OUTPUT   # save the utab aside
+ts_finalize_subtest            # checks the utab
 
 #
 # fstab - replace
index f4ebc6dfaa8826c795f9e7ca0d36863973217d7a..dd44725944f412c54e449fb1ef7149b51b1d9e0a 100755 (executable)
@@ -33,10 +33,6 @@ ts_device_init
 DEVICE=$TS_LODEV
 
 MTAB_FILE="/proc/mounts"
-has_mtab=$( ts_has_mtab_support )
-if [ "$has_mtab" == "yes" ]; then
-       MTAB_FILE="/etc/mtab"
-fi
 
 mkfs.ext2 $DEVICE &> /dev/null || ts_die "Cannot make ext2 on $DEVICE"
 
index 38db9bf9f3068858e50cd90c363a85b32d19d2b2..468d5d30b2a828c40c609b5740a8f5ee6c45bde6 100755 (executable)
@@ -35,10 +35,6 @@ ts_device_init
 DEVICE=$TS_LODEV
 
 MTAB_FILE="/proc/mounts"
-has_mtab=$( ts_has_mtab_support )
-if [ "$has_mtab" == "yes" ]; then
-       MTAB_FILE="/etc/mtab"
-fi
 
 mkfs.ext2 $DEVICE &> /dev/null || ts_die "Cannot make ext2 on $DEVICE"
 
diff --git a/tests/ts/mount/rlimit b/tests/ts/mount/rlimit
deleted file mode 100755 (executable)
index 50d9153..0000000
+++ /dev/null
@@ -1,93 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (C) 2007 Karel Zak <kzak@redhat.com>
-#
-# This file is part of util-linux.
-#
-# This file is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This file is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-
-#
-# The /etc/mtab file should not be modified if RLIMIT_FSIZE (ulimit -f)
-# is too low, otherwise the file could be corrupted (incomplete write).
-# The [u]mount(8) has to block SIGXFSZ and check if all writes and fflush
-# calls are successful.
-#
-
-TS_TOPDIR="${0%/*}/../.."
-TS_DESC="rlimit-fsize"
-
-. $TS_TOPDIR/functions.sh
-ts_init "$*"
-
-ts_check_test_command "$TS_CMD_MOUNT"
-ts_check_test_command "$TS_CMD_UMOUNT"
-ts_check_test_command "$TS_HELPER_MD5"
-
-ts_skip_nonroot
-ts_check_losetup
-ts_check_prog "mkfs.ext2"
-
-has_mtab=$( ts_has_mtab_support )
-[ "$has_mtab" == "yes" ] || ts_skip "mtab unsupported"
-
-[ -L /etc/mtab ] && ts_skip "mtab is symlink"
-[ "$(stat --format '%s' /etc/mtab)" -gt "1024" ] || ts_skip "mtab is too small"
-
-function mtab_checksum()
-{
-       "$TS_HELPER_MD5" < /etc/mtab
-}
-
-ts_device_init
-DEVICE=$TS_LODEV
-
-mkfs.ext2 $DEVICE &> /dev/null || ts_die "Cannot make ext2 on $DEVICE"
-
-
-ts_init_subtest "mount"
-OLD_SUM=$(mtab_checksum)
-[ -d "$TS_MOUNTPOINT" ] || mkdir -p $TS_MOUNTPOINT
-(
-       ulimit -f 1
-       $TS_CMD_MOUNT $DEVICE $TS_MOUNTPOINT
-) &> /dev/null
-NEW_SUM=$(mtab_checksum)
-[ $NEW_SUM = $OLD_SUM ] && echo "OK: mtab unmodified by mount" >> $TS_OUTPUT
-ts_is_mounted $DEVICE || ts_die "Cannot find $DEVICE in /proc/mounts"
-$TS_CMD_UMOUNT $TS_MOUNTPOINT &> /dev/null
-ts_is_mounted $DEVICE && ts_die "$DEVICE is still mounted"
-ts_finalize_subtest
-
-
-ts_init_subtest "umount"
-[ -d "$TS_MOUNTPOINT" ] || mkdir -p $TS_MOUNTPOINT
-$TS_CMD_MOUNT $DEVICE $TS_MOUNTPOINT &> /dev/null
-ts_is_mounted $DEVICE || ts_die "Cannot find $DEVICE in /proc/mounts"
-OLD_SUM=$(mtab_checksum)
-(
-       ulimit -f 1
-       $TS_CMD_UMOUNT $TS_MOUNTPOINT &> /dev/null
-) &> /dev/null
-NEW_SUM=$(mtab_checksum)
-[ $NEW_SUM = $OLD_SUM ] && echo "OK: mtab unmodified by umount" >> $TS_OUTPUT
-if ts_is_mounted $DEVICE; then
-       echo "FAIL: $DEVICE is still mounted" >> $TS_OUTPUT
-       $TS_CMD_UMOUNT $TS_MOUNTPOINT &> /dev/null
-else
-       # repair /etc/mtab
-       $TS_CMD_UMOUNT --fake $TS_MOUNTPOINT &> /dev/null
-fi
-ts_finalize_subtest
-
-ts_log "Success"
-ts_finalize
index 37a163d87929c59833fffb3a10f17cafb9518aa5..ccf612c89ec948cd201dfd55ab88a76b77be26ab 100755 (executable)
@@ -18,11 +18,6 @@ ts_check_prog "mkfs.ext2"
 $TS_CMD_UMOUNT --help | grep -q all-targets
 [ $? -eq 1 ] && ts_skip "all-targets unsupported"
 
-has_mtab=$( ts_has_mtab_support )
-if [ "$has_mtab" == "yes" ]; then
-       [ -L /etc/mtab ] || ts_skip "regular mtab"
-fi
-
 # set global variable TS_DEVICE
 ts_scsi_debug_init dev_size_mb=50