Skip to content

Commit 89f3608

Browse files
sterlingjensenjsai20
authored andcommitted
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 <[email protected]> Signed-off-by: Sterling Jensen <[email protected]> Closes openzfs#11295 Closes openzfs#11462
1 parent 0d4f313 commit 89f3608

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

cmd/mount_zfs/mount_zfs.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,21 @@ libzfs_handle_t *g_zfs;
5050
static void
5151
parse_dataset(const char *target, char **dataset)
5252
{
53+
/*
54+
* Prior to util-linux 2.36.2, if a file or directory in the
55+
* current working directory was named 'dataset' then mount(8)
56+
* would prepend the current working directory to the dataset.
57+
* Check for it and strip the prepended path when it is added.
58+
*/
59+
char cwd[PATH_MAX];
60+
if (getcwd(cwd, PATH_MAX) == NULL) {
61+
perror("getcwd");
62+
return;
63+
}
64+
int len = strlen(cwd);
65+
if (strncmp(cwd, target, len) == 0)
66+
target += len;
67+
5368
/* Assume pool/dataset is more likely */
5469
strlcpy(*dataset, target, PATH_MAX);
5570

tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_013_pos.ksh

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ typeset -r fs=$TESTPOOL/$TESTFS
3232
function cleanup
3333
{
3434
cd $STF_SUITE
35-
[[ -d $TESTDIR/$$ ]] && (rm -rf $TESTDIR/$$ || log_fail)
35+
if [[ -d $TESTDIR/$$ ]]; then
36+
log_must rm -rf $TESTDIR/$$
37+
fi
3638
mounted && zfs $mountcmd $TESTPOOL
3739
return 0
3840
}
@@ -50,13 +52,25 @@ force_unmount $fs
5052

5153
log_note "Verify mount(8) does not canonicalize before calling helper"
5254
# Canonicalization is confused by files in PWD matching [device|mountpoint]
53-
mkdir -p $TESTDIR/$$/$TESTPOOL && cd $TESTDIR/$$ || log_fail
55+
log_must mkdir -p $TESTDIR/$$/$TESTPOOL
56+
log_must cd $TESTDIR/$$
5457
# The env flag directs zfs to exec /bin/mount, which then calls helper
5558
log_must eval ZFS_MOUNT_HELPER=1 zfs $mountcmd -v $TESTPOOL
5659
# mount (2.35.2) still suffers from a cosmetic PWD prefix bug
5760
log_must mounted $TESTPOOL
5861
force_unmount $TESTPOOL
5962

63+
log_note "Verify CWD prefix filter <dataset> <path>"
64+
log_must cd /
65+
log_must zfs set mountpoint=legacy $TESTPOOL
66+
log_must mkdir -p $mntpoint
67+
log_must mount -t zfs $TESTPOOL $mntpoint
68+
log_must ismounted $TESTPOOL
69+
log_must umount $mntpoint
70+
log_must zfs set mountpoint=$mntpoint $TESTPOOL
71+
log_must cd -
72+
force_unmount $TESTPOOL
73+
6074
log_note "Verify '-f <dataset> <path>' fakemount"
6175
log_must $helper -f $fs $mntpoint
6276
log_mustnot ismounted $fs
@@ -75,4 +89,4 @@ log_note "Verify '<device> <path>'"
7589
log_must $helper ${vdevs[0]} $mntpoint
7690
log_must mounted $mntpoint
7791

78-
log_pass "zfs mount helper correctly handles both device and pool strings"
92+
log_pass "zfs mount helper correctly handles both device and pool strings"

0 commit comments

Comments
 (0)