[RFC PATCH] malloc: Harden malloc by protecting chunk fd/bk pointers
Wilco Dijkstra
Wilco.Dijkstra@arm.com
Fri Dec 19 14:17:19 GMT 2025
Hi Arjun,
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.
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.
Cheers,
Wilco
More information about the Libc-alpha
mailing list