Skip to content

Commit

Permalink
Illumos openzfs#1661: Fix flaw in sa_find_sizes() calculation
Browse files Browse the repository at this point in the history
When calculating space needed for SA_BONUS buffers, hdrsize is
always rounded up to next 8-aligned boundary. However, in two places
the round up was done against sum of 'total' plus hdrsize. On the
other hand, hdrsize increments by 4 each time, which means in certain
conditions, we would end up returning with will_spill == 0 and
(total + hdrsize) larger than full_space, leading to a failed
assertion because it's invalid for dmu_set_bonus.

Reviewed by: Matthew Ahrens <[email protected]>
Reviewed by: Dan McDonald <[email protected]>
Approved by: Gordon Ross <[email protected]>

References to Illumos issue:
  https://www.illumos.org/issues/1661

Signed-off-by: Brian Behlendorf <[email protected]>
Closes openzfs#426
  • Loading branch information
delphij authored and behlendorf committed Oct 24, 2011
1 parent 3cee226 commit c475167
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions module/zfs/sa.c
Original file line number Diff line number Diff line change
Expand Up @@ -607,14 +607,14 @@ sa_find_sizes(sa_os_t *sa, sa_bulk_attr_t *attr_desc, int attr_count,
* and spill buffer.
*/
if (buftype == SA_BONUS && *index == -1 &&
P2ROUNDUP(*total + hdrsize, 8) >
(*total + P2ROUNDUP(hdrsize, 8)) >
(full_space - sizeof (blkptr_t))) {
*index = i;
done = B_TRUE;
}

next:
if (P2ROUNDUP(*total + hdrsize, 8) > full_space &&
if ((*total + P2ROUNDUP(hdrsize, 8)) > full_space &&
buftype == SA_BONUS)
*will_spill = B_TRUE;
}
Expand Down

0 comments on commit c475167

Please sign in to comment.