Skip to content

zfs_main: allow umount only on original mountpoint #17421

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

Closed
wants to merge 1 commit into from

Conversation

ixhamza
Copy link
Member

@ixhamza ixhamza commented Jun 4, 2025

Motivation and Context

Prevent silent unmount of the real mounpoint when running zfs umount on a binded mount.

Description

When “zfs umount” is run on a bind mount, it silently unmounts the real dataset and leaves the bind stale. Add a check so umount only succeeds if the path matches the original mountpoint; otherwise, print an error and abort to prevent accidental unmounts.

How Has This Been Tested?

Before

buildroot@root:~# zpool create -O mountpoint=/mnt/tank tank nvme0n1
buildroot@root:~# mkdir -p /mnt/tank-bind
buildroot@root:~# mount --bind /mnt/tank /mnt/tank-bind
buildroot@root:~# zfs umount /mnt/tank-bind
buildroot@root:~# mount | grep tank
tank on /mnt/tank-bind type zfs (rw,relatime,xattr,noacl,casesensitive)

After

buildroot@root:~# zpool create -O mountpoint=/mnt/tank tank nvme0n1
buildroot@root:~# mkdir -p /mnt/tank-bind
buildroot@root:~# mount --bind /mnt/tank /mnt/tank-bind
buildroot@root:~# zfs umount /mnt/tank-bind
cannot unmount '/mnt/tank-bind': not a original mountpoint
buildroot@root:~# mount | grep tank
tank on /mnt/tank type zfs (rw,relatime,xattr,noacl,casesensitive)
tank on /mnt/tank-bind type zfs (rw,relatime,xattr,noacl,casesensitive)
buildroot@root:~# umount /mnt/tank-bind
buildroot@root:~# mount | grep tank
tank on /mnt/tank type zfs (rw,relatime,xattr,noacl,casesensitive)

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)
  • Quality assurance (non-breaking change which makes the code more robust against bugs)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Library ABI change (libzfs, libzfs_core, libnvpair, libuutil and libzfsbootenv)
  • Documentation (a change to man pages or other documentation)

Checklist:

When “zfs umount” is run on a bind mount, it silently unmounts the real
dataset and leaves the bind stale. Add a check so umount only succeeds
if the path matches the original mountpoint; otherwise, print an error
and abort to prevent accidental unmounts.

Signed-off-by: Ameer Hamza <ahamza@ixsystems.com>
@ixhamza ixhamza force-pushed the NAS-136078-fix-bind-umount branch from f186da8 to 1baf528 Compare June 4, 2025 16:48
Comment on lines +7758 to +7760
if (strcmp(entry.mnt_mountp, path) != 0) {
(void) fprintf(stderr, gettext("cannot %s '%s': not an original"
" mountpoint\n"), cmdname, path);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I understand there is a problem, I am not sure this solution is right. Please correct me if I am wrong, but looking on getextmntent() I see this comment:

 * Search for the path in /proc/self/mounts. Rather than looking for the
 * specific path, which can be fooled by non-standard paths (i.e. ".."
 * or "//"), we stat() the path and search for the corresponding
 * (major,minor) device pair.

, which makes me think the exactly path match is not required there.

@behlendorf behlendorf added the Status: Code Review Needed Ready for review and testing label Jun 10, 2025
@amotin amotin closed this Jun 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Code Review Needed Ready for review and testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants