Skip to content

Commit c475167

Browse files
delphijbehlendorf
authored andcommitted
Illumos #1661: Fix flaw in sa_find_sizes() calculation
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 <matt@delphix.com> Reviewed by: Dan McDonald <danmcd@nexenta.com> Approved by: Gordon Ross <gwr@nexenta.com> References to Illumos issue: https://www.illumos.org/issues/1661 Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov> Closes #426
1 parent 3cee226 commit c475167

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

module/zfs/sa.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -607,14 +607,14 @@ sa_find_sizes(sa_os_t *sa, sa_bulk_attr_t *attr_desc, int attr_count,
607607
* and spill buffer.
608608
*/
609609
if (buftype == SA_BONUS && *index == -1 &&
610-
P2ROUNDUP(*total + hdrsize, 8) >
610+
(*total + P2ROUNDUP(hdrsize, 8)) >
611611
(full_space - sizeof (blkptr_t))) {
612612
*index = i;
613613
done = B_TRUE;
614614
}
615615

616616
next:
617-
if (P2ROUNDUP(*total + hdrsize, 8) > full_space &&
617+
if ((*total + P2ROUNDUP(hdrsize, 8)) > full_space &&
618618
buftype == SA_BONUS)
619619
*will_spill = B_TRUE;
620620
}

0 commit comments

Comments
 (0)