uma: Fix a few problems with KASAN integration
- Ensure that all items returned by UMA are aligned to KASAN_SHADOW_SCALE (8). This was true in practice since smaller alignments are not used by any consumers, but we should enforce it anyway. - Use a non-zero code for marking redzones that appear naturally in items that are not a multiple of the scale factor in size. Currently we do not modify keg layouts to force the creation of redzones. - Use a non-zero code for marking freed per-CPU items, otherwise accesses of freed per-CPU items are not detected by the runtime. Sponsored by: The FreeBSD Foundation
This commit is contained in:
parent
36226163fa
commit
b0dfc48684
@ -556,11 +556,12 @@ kasan_mark_item_valid(uma_zone_t zone, void *item)
|
||||
sz = zone->uz_size;
|
||||
rsz = roundup2(sz, KASAN_SHADOW_SCALE);
|
||||
if ((zone->uz_flags & UMA_ZONE_PCPU) == 0) {
|
||||
kasan_mark(item, sz, rsz, 0);
|
||||
kasan_mark(item, sz, rsz, KASAN_GENERIC_REDZONE);
|
||||
} else {
|
||||
pcpu_item = zpcpu_base_to_offset(item);
|
||||
for (i = 0; i <= mp_maxid; i++)
|
||||
kasan_mark(zpcpu_get_cpu(pcpu_item, i), sz, rsz, 0);
|
||||
kasan_mark(zpcpu_get_cpu(pcpu_item, i), sz, rsz,
|
||||
KASAN_GENERIC_REDZONE);
|
||||
}
|
||||
}
|
||||
|
||||
@ -580,7 +581,8 @@ kasan_mark_item_invalid(uma_zone_t zone, void *item)
|
||||
} else {
|
||||
pcpu_item = zpcpu_base_to_offset(item);
|
||||
for (i = 0; i <= mp_maxid; i++)
|
||||
kasan_mark(zpcpu_get_cpu(pcpu_item, i), 0, sz, 0);
|
||||
kasan_mark(zpcpu_get_cpu(pcpu_item, i), 0, sz,
|
||||
KASAN_UMA_FREED);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2238,6 +2240,14 @@ keg_layout(uma_keg_t keg)
|
||||
PRINT_UMA_ZFLAGS));
|
||||
|
||||
alignsize = keg->uk_align + 1;
|
||||
#ifdef KASAN
|
||||
/*
|
||||
* ASAN requires that each allocation be aligned to the shadow map
|
||||
* scale factor.
|
||||
*/
|
||||
if (alignsize < KASAN_SHADOW_SCALE)
|
||||
alignsize = KASAN_SHADOW_SCALE;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Calculate the size of each allocation (rsize) according to
|
||||
|
Loading…
Reference in New Issue
Block a user