Skip to content

Disable mount(8) canonical paths in do_mount() #6437

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

loli10K
Copy link
Contributor

@loli10K loli10K commented Aug 1, 2017

Description

By default the mount(8) command, as invoked by zfs mount, will try to resolve any path parameter in its canonical form: this could lead to mount failures when the cwd contains a symlink having the same name of the dataset being mounted.

Fix this by explicitly disabling mount(8) path canonicalization.

Motivation and Context

Fix #1791
Maybe fix #6429: i don't have a reproducer to verify this could solve the issue addressed in d32d25c. If it does we could revert that change to the unit file since the systemd version used in CentOS7 does not (yet) support it.

How Has This Been Tested?

Tested manually, will probably need to add/modify something in tests/zfs-tests/tests/functional/cli_root/zfs_mount.
This PR is mostly just to propose a possible fix for #6429.

root@linux:~# POOLNAME="wipefs"
root@linux:~# TMPDIR='/var/tmp'
root@linux:~# #
root@linux:~# cd /sbin
root@linux:/sbin# ls -l $POOLNAME
-rwxr-xr-x 1 root root 27144 Mar 30  2015 wipefs
root@linux:/sbin# mountpoint -q $TMPDIR || mount -t tmpfs tmpfs $TMPDIR
root@linux:/sbin# zpool destroy $POOLNAME
root@linux:/sbin# rm -f $TMPDIR/zpool.dat
root@linux:/sbin# fallocate -l 64m $TMPDIR/zpool.dat
root@linux:/sbin# strace -f -s 1024 -e trace=execve,mount zpool create $POOLNAME $TMPDIR/zpool.dat
execve("/usr/sbin/zpool", ["zpool", "create", "wipefs", "/var/tmp/zpool.dat"], [/* 14 vars */]) = 0
Process 3715 attached
[pid  3715] execve("/bin/mount", ["/bin/mount", "--no-canonicalize", "-t", "zfs", "-o", "defaults,atime,strictatime,dev,exec,rw,suid,nomand,zfsutil", "wipefs", "/wipefs"], [/* 14 vars */]) = 0
Process 3716 attached
[pid  3716] execve("/sbin/mount.zfs", ["/sbin/mount.zfs", "wipefs", "/wipefs", "-o", "rw,strictatime,zfsutil"], [/* 10 vars */]) = 0
[pid  3716] mount("wipefs", "/wipefs", "zfs", MS_STRICTATIME, "rw,strictatime,zfsutil,mntpoint=/wipefs") = 0
[pid  3716] +++ exited with 0 +++
[pid  3715] --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=3716, si_uid=0, si_status=0, si_utime=0, si_stime=0} ---
[pid  3715] +++ exited with 0 +++
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=3715, si_uid=0, si_status=0, si_utime=0, si_stime=0} ---
+++ exited with 0 +++
root@linux:/sbin# #
root@linux:/sbin# mount -t zfs # what!?
/sbin/wipefs on /wipefs type zfs (rw,xattr,noacl)
root@linux:/sbin# 

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Performance enhancement (non-breaking change which improves efficiency)
  • Code cleanup (non-breaking change which makes code smaller or more readable)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation (a change to man pages or other documentation)

Checklist:

  • My code follows the ZFS on Linux code style requirements.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • All commit messages are properly formatted and contain Signed-off-by.
  • Change has been approved by a ZFS on Linux member.

@loli10K loli10K added the Status: Work in Progress Not yet ready for general review label Aug 1, 2017
@loli10K loli10K requested a review from behlendorf August 1, 2017 19:59
@loli10K loli10K removed the Status: Work in Progress Not yet ready for general review label Aug 16, 2017
@behlendorf
Copy link
Contributor

Let me get this tested on CentOS 7 so I can verify we can drop the change to the unit file.

@behlendorf
Copy link
Contributor

@loli10K I can verify that WorkingDirectory is no longer required in the zfs-mount.service.in file with your fix. Can you rebase this PR and include that change so we can get this merged.

diff --git a/etc/systemd/system/zfs-mount.service.in b/etc/systemd/system/zfs-mo
index 36dc3be..0664fd9 100644
--- a/etc/systemd/system/zfs-mount.service.in
+++ b/etc/systemd/system/zfs-mount.service.in
@@ -11,7 +11,6 @@ Before=local-fs.target
 Type=oneshot
 RemainAfterExit=yes
 ExecStart=@sbindir@/zfs mount -a
-WorkingDirectory=-/sbin/
 
 [Install]
 WantedBy=zfs-share.service

By default the mount(8) command, as invoked by 'zfs mount', will try
to resolve any path parameter in its canonical form: this could lead
to mount failures when the cwd contains a symlink having the same name
of the dataset being mounted.

Fix this by explicitly disabling mount(8) path canonicalization.

Signed-off-by: loli10K <[email protected]>
@loli10K loli10K force-pushed the mount-disable-path-canonicalization branch from 616656d to 9485536 Compare August 18, 2017 03:37
@behlendorf behlendorf merged commit 9000a9f into openzfs:master Aug 21, 2017
tonyhutter pushed a commit that referenced this pull request Aug 22, 2017
By default the mount(8) command, as invoked by 'zfs mount', will try
to resolve any path parameter in its canonical form: this could lead
to mount failures when the cwd contains a symlink having the same name
of the dataset being mounted.

Fix this by explicitly disabling mount(8) path canonicalization.

Reviewed-by: George Melikov <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: loli10K <[email protected]>
Closes #1791 
Closes #6429 
Closes #6437
@loli10K loli10K deleted the mount-disable-path-canonicalization branch August 31, 2017 17:55
Fabian-Gruenbichler pushed a commit to Fabian-Gruenbichler/zfs that referenced this pull request Sep 29, 2017
By default the mount(8) command, as invoked by 'zfs mount', will try
to resolve any path parameter in its canonical form: this could lead
to mount failures when the cwd contains a symlink having the same name
of the dataset being mounted.

Fix this by explicitly disabling mount(8) path canonicalization.

Reviewed-by: George Melikov <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: loli10K <[email protected]>
Closes openzfs#1791 
Closes openzfs#6429 
Closes openzfs#6437
@jh3141
Copy link

jh3141 commented Mar 10, 2018

This change appears to prevent user-mode mounting of volumes:

root@athena:~# zfs allow jules mount testpool/jtest

jules@athena:~$ zfs mount testpool/jtest
mount: only root can use "--no-canonicalize" option
cannot mount 'testpool/jtest': Invalid argument

Is it possible that the --no-canonicalize option could be used only when necessary? Or is there another solution to this that doesn't prevent user mounting?

(System is Ubuntu 16.04, running latest ZoL from master)

@behlendorf
Copy link
Contributor

@jh3141 this could be made optional to resolve user-mode mounting of filesystems. But reliably detecting where's it's nessisary likely wouldn't be reliable. I've opened #7294 to track this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

zfs-mount.service WorkingDirectory ignored (Not an absolute path) zfs mount failed if the cwd contains a symlink with the same name
4 participants