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

Correctly handle errors from kern_path() in zfsctl_snapdir_vget() #7864

Merged
merged 1 commit into from
Sep 5, 2018

Conversation

siebenmann
Copy link
Contributor

@siebenmann siebenmann commented Sep 4, 2018

Motivation and Context

Fix #7764

zfsctl_snapdir_vget() calls kern_path() and then returns any errors untouched, which is incorrect behavior. As a regular kernel function, kern_path() returns errors as negative errnos, such as -ELOOP, but ZFS code expects errors to be positive errnos, such as ELOOP. When these untouched negative errnos are returned to other ZFS functions, the functions incorrectly handle the results; in the case of #7764, this causes zpl_fh_to_dentry() to turn the negative error result into a positive number, which the kernel (in the form of exportfs_decode_fh()) considers to be a pointer and immediately panics on.

Description

The fix is to negate the return value from kern_path().

How Has This Been Tested?

To test this fix, I built a Fedora 28 VM with the official 0.7.9 DKMS modules, verified that it paniced as a NFS server following the reproduction steps in #7764, and then hand-patched the DKMS source to negate the kern_path() return value. With my patched and rebuilt DKMS modules, the Fedora 28 NFS server didn't panic and clients just got the expected ESTALE errors.

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.

As a regular kernel function, kern_path() returns errors as negative
errnos, such as -ELOOP. zfsctl_snapdir_vget() must convert these into
the positive errnos used throughout the ZFS code when it returns them
to other ZFS functions so that the ZFS code properly sees them as
errors.

Signed-off-by: Chris Siebenmann <cks.git01@cs.toronto.edu>
Closes openzfs#7764
@behlendorf behlendorf added the Status: Accepted Ready to integrate (reviewed, tested) label Sep 5, 2018
@behlendorf behlendorf merged commit cfa3754 into openzfs:master Sep 5, 2018
@brandonhaberfeld
Copy link

Thankx all. Amazing to see the open source world in action....

tonyhutter pushed a commit to tonyhutter/zfs that referenced this pull request Sep 5, 2018
As a regular kernel function, kern_path() returns errors as negative
errnos, such as -ELOOP. zfsctl_snapdir_vget() must convert these into
the positive errnos used throughout the ZFS code when it returns them
to other ZFS functions so that the ZFS code properly sees them as
errors.

Reviewed-by: George Melikov <mail@gmelikov.ru>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Chris Siebenmann <cks.git01@cs.toronto.edu>
Closes openzfs#7764
Closes openzfs#7864
tonyhutter pushed a commit to tonyhutter/zfs that referenced this pull request Sep 5, 2018
As a regular kernel function, kern_path() returns errors as negative
errnos, such as -ELOOP. zfsctl_snapdir_vget() must convert these into
the positive errnos used throughout the ZFS code when it returns them
to other ZFS functions so that the ZFS code properly sees them as
errors.

Reviewed-by: George Melikov <mail@gmelikov.ru>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Chris Siebenmann <cks.git01@cs.toronto.edu>
Closes openzfs#7764
Closes openzfs#7864
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Accepted Ready to integrate (reviewed, tested)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Panic in NFS filehandle decoding for snapshots [code issue identified and reproducible]
4 participants