Conversation

Replying to
It gives you compiler-style optimizations for division by a constant where the divisor is a runtime constant rather than a compile-time constant. In hardened_malloc, I use it to quickly perform division by the allocation size and slab size. It makes the out-of-line metadata fast.
2
4
Replying to and
I have a lot of lower hanging fruit to address before considering that kind of micro-optimization. It's these 2 fields in the per-size-class slab allocator: github.com/GrapheneOS/har. It could be another one of these tables if I generated it when building: github.com/GrapheneOS/har.
1
Replying to
The entirety of the mutable hardened_malloc state is in a statically allocated, dedicated metadata region that's never reused or mixed with anything else. There is no threat model where these being in there has any relevance to security. An attacker has no reason to mess with it.
1
Replying to and
The metadata region has a high entropy random base within a guard region and is only referenced via the `ro` global. If an attacker has arbitrary read and write primitives, they're beyond needing to target malloc metadata. If for some reason they do, the divisors don't matter.
1
Replying to and
If CONFIG_SEAL_METADATA is enabled, MPK is used to make the metadata region inaccessible (no read or write), and it only toggles on thread-local access within malloc. It's not enabled by default because it doesn't accomplish much when it's already a dedicated, isolated region.
1