From: Karel Zak Date: Fri, 17 Jun 2022 11:42:11 +0000 (+0200) Subject: libmount: remove support for writable /etc/mtab X-Git-Tag: v2.39-rc1~606 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7f56e4129f1c951acc1a5f6f1efa8cf8b85d0075;p=thirdparty%2Futil-linux.git libmount: remove support for writable /etc/mtab 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 --- diff --git a/configure.ac b/configure.ac index 5821a3bf1c..824e8bbd24 100644 --- a/configure.ac +++ b/configure.ac @@ -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 diff --git a/libmount/src/context.c b/libmount/src/context.c index 7927012d20..ac74c0e7b3 100644 --- a/libmount/src/context.c +++ b/libmount/src/context.c @@ -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; diff --git a/libmount/src/context_mount.c b/libmount/src/context_mount.c index 6af83e0412..0ebf8ec1b3 100644 --- a/libmount/src/context_mount.c +++ b/libmount/src/context_mount.c @@ -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); diff --git a/libmount/src/tab_parse.c b/libmount/src/tab_parse.c index 4407f9c9c7..c5de990414 100644 --- a/libmount/src/tab_parse.c +++ b/libmount/src/tab_parse.c @@ -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) diff --git a/libmount/src/tab_update.c b/libmount/src/tab_update.c index 3a22e7188b..6e16cd165e 100644 --- a/libmount/src/tab_update.c +++ b/libmount/src/tab_update.c @@ -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; diff --git a/libmount/src/version.c b/libmount/src/version.c index b69b09a170..211bb9fe4f 100644 --- a/libmount/src/version.c +++ b/libmount/src/version.c @@ -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 diff --git a/tests/functions.sh b/tests/functions.sh index 5614122120..e24d5c8798 100644 --- a/tests/functions.sh +++ b/tests/functions.sh @@ -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 diff --git a/tests/ts/libmount/context b/tests/ts/libmount/context index 70c779cdf6..da1ba71525 100755 --- a/tests/ts/libmount/context +++ b/tests/ts/libmount/context @@ -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 < /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 $? } diff --git a/tests/ts/libmount/context-py b/tests/ts/libmount/context-py index a6a081694b..c5029f479a 100755 --- a/tests/ts/libmount/context-py +++ b/tests/ts/libmount/context-py @@ -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 < /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 $? } diff --git a/tests/ts/libmount/update b/tests/ts/libmount/update index abc1547829..fb69bee2d1 100755 --- a/tests/ts/libmount/update +++ b/tests/ts/libmount/update @@ -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 diff --git a/tests/ts/mount/devname b/tests/ts/mount/devname index f4ebc6dfaa..dd44725944 100755 --- a/tests/ts/mount/devname +++ b/tests/ts/mount/devname @@ -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" diff --git a/tests/ts/mount/remount b/tests/ts/mount/remount index 38db9bf9f3..468d5d30b2 100755 --- a/tests/ts/mount/remount +++ b/tests/ts/mount/remount @@ -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 index 50d915387d..0000000000 --- a/tests/ts/mount/rlimit +++ /dev/null @@ -1,93 +0,0 @@ -#!/bin/bash - -# -# Copyright (C) 2007 Karel Zak -# -# 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 diff --git a/tests/ts/mount/umount-alltargets b/tests/ts/mount/umount-alltargets index 37a163d879..ccf612c89e 100755 --- a/tests/ts/mount/umount-alltargets +++ b/tests/ts/mount/umount-alltargets @@ -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