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

ZAP: Fix leaf references on zap_expand_leaf() errors #16159

Merged
merged 1 commit into from
May 10, 2024

Conversation

amotin
Copy link
Member

@amotin amotin commented May 3, 2024

Depending on kind of error zap_expand_leaf() may return with or without valid leaf reference held. Make sure it returns NULL if due to error it has no leaf to return. Make its callers to check the returned leaf pointer, and release the leaf if it is not NULL.

Closes #12366

How Has This Been Tested?

Not really.

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)
  • Library ABI change (libzfs, libzfs_core, libnvpair, libuutil and libzfsbootenv)
  • Documentation (a change to man pages or other documentation)

Checklist:

Depending on kind of error zap_expand_leaf() may return with or
without valid leaf reference held.  Make sure it returns NULL if
due to error it has no leaf to return.  Make its callers to check
the returned leaf pointer, and release the leaf if it is not NULL.

Signed-off-by:	Alexander Motin <mav@FreeBSD.org>
Sponsored by:	iXsystems, Inc.
Closes openzfs#12366
@amotin amotin added the Status: Code Review Needed Ready for review and testing label May 3, 2024
zap_put_leaf_maybe_grow_ptrtbl(zn, l, tag, tx);
if (l != NULL) {
if (err == ENOSPC)
zap_put_leaf(l);
Copy link
Contributor

Choose a reason for hiding this comment

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

(not a review, I'm trying to understand this)

it gets here because it was zap_grow_ptrtbl which returned ENOSPC; when can that happen? a) the ZAP is way too large (2^46 entries, right?) and b) on transition from 2^28 to 2^48 zap_hashbits, that is when upgrading from micro to fat zap? Is there any other case that I'm missing why ENOSPC can happen here?

I mean, I'm trying to understand which separate two leaves does the zap_put_leaf get called for and whether that could cause additional trouble - this is the second occasion, the first is on line 713.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've primarily just refactored already present code. I was actually thinking about actual out of space, but it seems not checked at this point, and you seem right that hash size limit may be the primary (and pretty unlikely) factor.

zap_expand_leaf() puts one leaf inside, while another (where the entry is going to be inserted) returns to the caller. So it is the leaf that gets new entry is checked for coming overflow and possible hash table grow. I.e. I see no problems, unless you specify better.

@behlendorf behlendorf added Status: Accepted Ready to integrate (reviewed, tested) and removed Status: Code Review Needed Ready for review and testing labels May 10, 2024
@behlendorf behlendorf merged commit 136c053 into openzfs:master May 10, 2024
23 of 25 checks passed
amotin added a commit to amotin/zfs that referenced this pull request May 23, 2024
Depending on kind of error zap_expand_leaf() may return with or
without valid leaf reference held.  Make sure it returns NULL if
due to error it has no leaf to return.  Make its callers to check
the returned leaf pointer, and release the leaf if it is not NULL.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Alexander Motin <mav@FreeBSD.org>
Sponsored by:	iXsystems, Inc.
Closes openzfs#12366 
Closes openzfs#16159
ixhamza pushed a commit to truenas/zfs that referenced this pull request May 23, 2024
Depending on kind of error zap_expand_leaf() may return with or
without valid leaf reference held.  Make sure it returns NULL if
due to error it has no leaf to return.  Make its callers to check
the returned leaf pointer, and release the leaf if it is not NULL.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Alexander Motin <mav@FreeBSD.org>
Sponsored by:	iXsystems, Inc.
Closes openzfs#12366 
Closes openzfs#16159
ixhamza pushed a commit to truenas/zfs that referenced this pull request May 23, 2024
Depending on kind of error zap_expand_leaf() may return with or
without valid leaf reference held.  Make sure it returns NULL if
due to error it has no leaf to return.  Make its callers to check
the returned leaf pointer, and release the leaf if it is not NULL.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Alexander Motin <mav@FreeBSD.org>
Sponsored by:	iXsystems, Inc.
Closes openzfs#12366 
Closes openzfs#16159
behlendorf pushed a commit that referenced this pull request May 29, 2024
Depending on kind of error zap_expand_leaf() may return with or
without valid leaf reference held.  Make sure it returns NULL if
due to error it has no leaf to return.  Make its callers to check
the returned leaf pointer, and release the leaf if it is not NULL.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Alexander Motin <mav@FreeBSD.org>
Sponsored by:	iXsystems, Inc.
Closes #12366 
Closes #16159
lundman pushed a commit to openzfsonwindows/openzfs that referenced this pull request Sep 4, 2024
Depending on kind of error zap_expand_leaf() may return with or
without valid leaf reference held.  Make sure it returns NULL if
due to error it has no leaf to return.  Make its callers to check
the returned leaf pointer, and release the leaf if it is not NULL.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Alexander Motin <mav@FreeBSD.org>
Sponsored by:	iXsystems, Inc.
Closes openzfs#12366 
Closes openzfs#16159
@amotin amotin deleted the zap_leak branch November 19, 2024 00:57
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.

extra zap_put_leaf in an unlikely code path
3 participants