[RFC] how to get the size of a malloc(9) block ?

jb jb.1234abcd at gmail.com
Thu Nov 28 15:14:20 UTC 2013


Luigi Rizzo <rizzo <at> iet.unipi.it> writes:

> ... 
> But I don't understand why you find ksize()/malloc_usable_size() dangerous.
> ...

The original crime is commited when *usable size* (an implementation detail)
is exported (leaked) to the caller.
To be blunt, when a caller requests memory of certain size, and its request is
satisfied, then it is not its business to learn details beyond that (and they
should not be offered as well).
The API should be sanitized, in kernel and user space.
Otherwise, all kind of charlatans will try to play hair-raising games with it.
If the caller wants to track the *requested size* programmatically, it is its
business to do it and it can be done very easily.

Some of these guys got it perfectly right:
http://stackoverflow.com/questions/5813078/is-it-possible-to-find-the-memory-allocated-to-the-pointer-without-searching-fo

jb







More information about the freebsd-current mailing list