From 03f036cbccdd8699f5fe8540ef317595a35bceb8 Mon Sep 17 00:00:00 2001 From: sterlingjensen <5555776+sterlingjensen@users.noreply.github.com> Date: Tue, 19 Jan 2021 13:57:31 -0600 Subject: [PATCH] Re-apply path sanitizer, as mount(8) still mangles it Prior to util-linux 2.36.2, if a file or directory in the current working directory was named 'dataset' then mount(8) would prepend the current working directory to the dataset. Eventually, we should be able to drop this workaround. Reviewed-by: Brian Behlendorf Signed-off-by: Sterling Jensen Closes #11295 Closes #11462 --- cmd/mount_zfs/mount_zfs.c | 15 ++++++++++++++ .../cli_root/zfs_mount/zfs_mount_013_pos.ksh | 20 ++++++++++++++++--- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/cmd/mount_zfs/mount_zfs.c b/cmd/mount_zfs/mount_zfs.c index ca39d22847..5196c3e5cb 100644 --- a/cmd/mount_zfs/mount_zfs.c +++ b/cmd/mount_zfs/mount_zfs.c @@ -50,6 +50,21 @@ libzfs_handle_t *g_zfs; static void parse_dataset(const char *target, char **dataset) { + /* + * Prior to util-linux 2.36.2, if a file or directory in the + * current working directory was named 'dataset' then mount(8) + * would prepend the current working directory to the dataset. + * Check for it and strip the prepended path when it is added. + */ + char cwd[PATH_MAX]; + if (getcwd(cwd, PATH_MAX) == NULL) { + perror("getcwd"); + return; + } + int len = strlen(cwd); + if (strncmp(cwd, target, len) == 0) + target += len; + /* Assume pool/dataset is more likely */ strlcpy(*dataset, target, PATH_MAX); diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_013_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_013_pos.ksh index 810a69470d..e6a4be1577 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_013_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_013_pos.ksh @@ -32,7 +32,9 @@ typeset -r fs=$TESTPOOL/$TESTFS function cleanup { cd $STF_SUITE - [[ -d $TESTDIR/$$ ]] && (rm -rf $TESTDIR/$$ || log_fail) + if [[ -d $TESTDIR/$$ ]]; then + log_must rm -rf $TESTDIR/$$ + fi mounted && zfs $mountcmd $TESTPOOL return 0 } @@ -50,13 +52,25 @@ force_unmount $fs log_note "Verify mount(8) does not canonicalize before calling helper" # Canonicalization is confused by files in PWD matching [device|mountpoint] -mkdir -p $TESTDIR/$$/$TESTPOOL && cd $TESTDIR/$$ || log_fail +log_must mkdir -p $TESTDIR/$$/$TESTPOOL +log_must cd $TESTDIR/$$ # The env flag directs zfs to exec /bin/mount, which then calls helper log_must eval ZFS_MOUNT_HELPER=1 zfs $mountcmd -v $TESTPOOL # mount (2.35.2) still suffers from a cosmetic PWD prefix bug log_must mounted $TESTPOOL force_unmount $TESTPOOL +log_note "Verify CWD prefix filter " +log_must cd / +log_must zfs set mountpoint=legacy $TESTPOOL +log_must mkdir -p $mntpoint +log_must mount -t zfs $TESTPOOL $mntpoint +log_must ismounted $TESTPOOL +log_must umount $mntpoint +log_must zfs set mountpoint=$mntpoint $TESTPOOL +log_must cd - +force_unmount $TESTPOOL + log_note "Verify '-f ' fakemount" log_must $helper -f $fs $mntpoint log_mustnot ismounted $fs @@ -75,4 +89,4 @@ log_note "Verify ' '" log_must $helper ${vdevs[0]} $mntpoint log_must mounted $mntpoint -log_pass "zfs mount helper correctly handles both device and pool strings" \ No newline at end of file +log_pass "zfs mount helper correctly handles both device and pool strings"