[RFC PATCH] malloc: Harden malloc by protecting chunk fd/bk pointers

Arjun Shankar arjun@redhat.com
Fri Dec 19 22:13:43 GMT 2025


Hi Wilco,

> My first question would be, what is the performance hit? The pointer
> scrambling scheme is pretty inefficient, requiring 3 extra instructions
> for each pointer access. A doubly-linked list insert requires at least 5
> pointer reads/writes (6 if you also check link consistency), resulting in
> a huge overhead.
>
> There are cheaper ways, eg. a key to scramble the pointers should add
> only 1 instruction per pointer access and offers more opportunities for CSE.

Understood. I'll try to experiment with something like what is done
for tcache_key and compare and report back on the performance hit.

> In general I would first add higher level abstractions for doubly linked list
> manipulations and functions to insert/remove chunks from their bins rather
> than immediately turning on scrambling. Depending on the overhead we
> could just enable it for checking/debug malloc. There are also many checks
> and asserts that might become redundant with pointer scrambling.

I see what you mean. I recall doing the same set of changes in
multiple similar sequences of statements. Abstracting them away would
make it easier to make such changes. I'm going to work on this. It
seems useful on its own.

Thank you for your comments!

Cheers,
Arjun



More information about the Libc-alpha mailing list