Skip to content

Commit

Permalink
Overflowing refreservation is bad
Browse files Browse the repository at this point in the history
Someone came to me and pointed out that you could pretty
readily cause the refreservation calculation to exceed
2**64, given the 2**17 multiplier in it, and produce
refreservations wildly less than the actual volsize in cases where
it should have failed.

Signed-off-by: Rich Ercolani <[email protected]>
  • Loading branch information
rincebrain committed Mar 14, 2024
1 parent 8f2f6cd commit 055bde4
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/libzfs/libzfs_dataset.c
Original file line number Diff line number Diff line change
Expand Up @@ -5566,7 +5566,16 @@ volsize_from_vdevs(zpool_handle_t *zhp, uint64_t nblocks, uint64_t blksize)
* Scale this size down as a ratio of 128k / tsize.
* See theory statement above.
*/
volsize = nblocks * asize * SPA_OLD_MAXBLOCKSIZE / tsize;
volsize = (nblocks * asize) / tsize;
/*
* If we would blow UINT64_MAX with this next multiplication,
* don't.
*/
if (volsize > (UINT64_MAX / SPA_OLD_MAXBLOCKSIZE))
volsize = UINT64_MAX;
else
volsize *= SPA_OLD_MAXBLOCKSIZE;

if (volsize > ret) {
ret = volsize;
}
Expand Down

0 comments on commit 055bde4

Please sign in to comment.