Skip to content
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

Stop segfaulting on unmount error case #12804

Merged
merged 1 commit into from
Nov 30, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions lib/libzfs/libzfs_mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -595,9 +595,13 @@ unmount_one(zfs_handle_t *zhp, const char *mountpoint, int flags)
default:
libzfs_err = EZFS_UMOUNTFAILED;
}
return (zfs_error_fmt(zhp->zfs_hdl, libzfs_err,
dgettext(TEXT_DOMAIN, "cannot unmount '%s'"),
mountpoint));
if (zhp) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If zhp == NULL invoking unmount_one doesn't make sense at all. Most likely null value is injected from

if (unmount_one(sets[i].dataset, sets[i].mountpoint,
and the if-guard should go there, much like it is done few lines below:
if (sets[i].dataset)

and
if (sets[i].dataset)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I mostly put the guard in there because of the comment at

suggesting that sometimes calling with a NULL was deliberately permitted - and if you look, do_unmount on Linux doesn't actually use the zhp arg anywhere, so it could have something reasonable happen when called there.

I don't particularly care either way, I just went for the option that changed less behavior.

Copy link
Contributor

Choose a reason for hiding this comment

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

You're right, Rich. Indeed zhp is used in neither of OS-specific implementations, what really matters is the mountpoint. Quite a surprise to be honest :)

return (zfs_error_fmt(zhp->zfs_hdl, libzfs_err,
dgettext(TEXT_DOMAIN, "cannot unmount '%s'"),
mountpoint));
} else {
return (-1);
}
}

return (0);
Expand Down