Multi-zone malloc(9)

Matthew Fleming mdf356 at gmail.com
Fri Jul 23 15:48:28 UTC 2010


On Fri, Jul 23, 2010 at 6:47 AM, Ivan Voras <ivoras at freebsd.org> wrote:
> On 07/22/10 18:54, mdf at FreeBSD.org wrote:
>> Occasionally we run into use-after-free and malloc'd buffer overrun
>> scenarios.  When this happens it can be rather difficult to determine
>> what code is at fault, since e.g. every 64 byte allocation, regardless
>> of malloc type, comes from the same UMA zone.  This means that an
>> overflow in M_TEMP will affect M_DEVBUF, etc.  Adding multiple uma
>> zones for each bucket size means that we can hash on the malloc type's
>> shortdesc field so that there are fewer collisions and misused memory
>> from one malloc type only affects a subset of other malloc types.
>
> To what extent does something like this help? As I read it, you still
> have the problem of overflows from one allocation trashing data in some
> other random allocation, but now you also have to track which hash
> bucket is it in while debugging?

It helps in that, with several repros on different hash functions, you
now can know exactly which malloc type was doing the trashing, because
it's the intersection of all the hash classes from each instance.
Assuming you have a core dump, the hash class is listed in the
malloc_type_internal hanging off the malloc type, so it's easy to
correlate.  There's a ddb function in the patch to print all the
matching types, and a gdb script would be easy to write as well.

> And would this interfere with possible NUMA efforts? (because it sort of
> looks similar - hashing allocations to "zones", which in NUMA case would
> be per-CPU).

The NUMA effort with malloc/uma is still theoretical so I can't say
for sure, but I believe these two issues are orthogonal.

Thanks,
matthew


More information about the freebsd-arch mailing list