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

Avoid core dump on invalid redaction bookmark #10138

Merged
merged 1 commit into from
Mar 18, 2020

Conversation

ghost
Copy link

@ghost ghost commented Mar 16, 2020

Motivation and Context

libzfs aborts and dumps core on EINVAL from the kernel when trying to
do a redacted send with a bookmark that is not a redaction bookmark.

Description

Move redaction bookmark validation to zfs_send_one in libzfs.

Check if the bookmark given for redactions is actually a redaction
bookmark. Print an error message and exit gracefully if it is not.

Don't abort on EINVAL in zfs_send_one.

How Has This Been Tested?

ZTS on FreeBSD

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.
  • I have run the ZFS Test Suite with this change applied.
  • All commit messages are properly formatted and contain Signed-off-by.

@ghost ghost added Status: Code Review Needed Ready for review and testing Component: Userspace user space functionality labels Mar 16, 2020
@ghost ghost requested a review from pcd1193182 March 16, 2020 19:21
@pcd1193182
Copy link
Contributor

Haven't done a detailed review yet, but my first thought is that this code would probably be better suited to being in libzfs itself, rather than in zfs_main.c. Why not just handle the EINVAL in libzfs_send_one ?

@ghost
Copy link
Author

ghost commented Mar 16, 2020

In general it seems most validation is done outside of libzfs. I had originally put the validation in libzfs but found that there was much more input validation happening in the zfs command rather than in the libzfs function, so I opted to obey that convention.

My first idea was rather than validating input, to simply handle EINVAL as you suggest. But EINVAL can be the result of a lot of things, so I didn't feel it would be appropriate to give a more specific error message that may not be correct. It seems more useful to check for the likely user error and give a specific reason why the command failed, leaving the generic message and abort in place to catch other, less likely, cases.

@pcd1193182
Copy link
Contributor

pcd1193182 commented Mar 16, 2020

Plenty of validation happens in libzfs, and I think that this would be better suited to inclusion in libzfs. Most of the validation that happens in zfs_main is basic validation of the general validity of a command, and very little or none of it involves inspecting the details of a particular dataset or bookmark.

EDIT: I looked at it a bit more, ZFS send definitely has more validation in zfs_main.c than in libzfs, but it is something of an outlier compared to other commands, and we should probably attempt to reverse that trend if possible.

As for handling EINVAL, it can be caused by many things, but it should still probably be handled. The error message can be fully generic. It shouldn't throw an internal error when we call zfs_send_one with an invalid set of arguments. We should probably just add it to the list of errors that just does zfs_error_aux(hdl, strerror(errno));.

libzfs aborts and dumps core on EINVAL from the kernel when trying to
do a redacted send with a bookmark that is not a redaction bookmark.

Move redacted bookmark validation into libzfs.

Check if the bookmark given for redactions is actually a redaction
bookmark.  Print an error message and exit gracefully if it is not.

Don't abort on EINVAL in zfs_send_one.

Signed-off-by: Ryan Moeller <ryan@iXsystems.com>
@ghost ghost force-pushed the check-redaction-bookmark branch from 470a20f to 24d9cb5 Compare March 17, 2020 16:56
@ghost
Copy link
Author

ghost commented Mar 17, 2020

  • Move redaction bookmark validation to zfs_send_one in libzfs
  • Don't abort on EINVAL in zfs_send_one

@codecov-io
Copy link

codecov-io commented Mar 17, 2020

Codecov Report

Merging #10138 into master will increase coverage by <1%.
The diff coverage is 84%.

Impacted file tree graph

@@           Coverage Diff            @@
##           master   #10138    +/-   ##
========================================
+ Coverage      79%      79%   +<1%     
========================================
  Files         385      385            
  Lines      122435   122448    +13     
========================================
+ Hits        96681    96860   +179     
+ Misses      25754    25588   -166
Flag Coverage Δ
#kernel 80% <ø> (ø) ⬆️
#user 66% <84%> (+1%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4d32aba...24d9cb5. Read the comment docs.

@behlendorf behlendorf added Status: Accepted Ready to integrate (reviewed, tested) and removed Status: Code Review Needed Ready for review and testing labels Mar 18, 2020
@behlendorf behlendorf merged commit 22df245 into openzfs:master Mar 18, 2020
@ghost ghost deleted the check-redaction-bookmark branch March 18, 2020 20:03
jsai20 pushed a commit to jsai20/zfs that referenced this pull request Mar 30, 2021
libzfs aborts and dumps core on EINVAL from the kernel when trying to
do a redacted send with a bookmark that is not a redaction bookmark.

Move redacted bookmark validation into libzfs.

Check if the bookmark given for redactions is actually a redaction
bookmark.  Print an error message and exit gracefully if it is not.

Don't abort on EINVAL in zfs_send_one.

Reviewed-by: Paul Dagnelie <pcd@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Ryan Moeller <ryan@iXsystems.com>
Closes openzfs#10138
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Userspace user space functionality Status: Accepted Ready to integrate (reviewed, tested)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants