public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [suggestion] tcache double-free check
@ 2020-07-19  6:40 Eyal Itkin
  2020-07-21  2:44 ` Carlos O'Donell
  0 siblings, 1 reply; 10+ messages in thread
From: Eyal Itkin @ 2020-07-19  6:40 UTC (permalink / raw)
  To: GNU C Library

Hello,

Going over the internals of the tcache entries, I stumbled upon the
entry->key field used for double-free checks. The full thread behind
this field can be found here:
http://sourceware-org.1504.n7.nabble.com/patch-tcache-double-free-check-td544878.html.

While the double-free check is a good idea, I think that Florian was
correct when he asked about the reason behind storing pointers to the
tcache control block on the heap itself. In the current
implementation, free()ed tcache allocations will contain a pointer to
the tcache control block, thus exposing it to corruption in case the
programmer mistakenly used the allocation after it was freed / freed
some buffers in the wrong way.

The reason behind using "tcache" as the entry key was explained by
Delorie (the developer of this patch):
"
... The value is arbitrary, it can be anything that we can argue won't
come up in usual program flows.
"

Instead of using some arbitrary constant or coming up with a fancy
random value, is it possible we update the key to something that won't
point to a critical memory management struct such as the tcache
control block? I suggest a simple change that will ensure that the
value used won't be a pointer that can be dereferenced: ~tcache
(instead of tcache). The bitwise not costs a mere 1 CPU cycle, while
making sure the key won't be a valid memory address.

Before submitting a patch for this change, I wanted to hear your
opinion about it.
Thanks, and credit to Awarau for pointing this out to me.
Eyal.

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2020-07-24 12:29 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-19  6:40 [suggestion] tcache double-free check Eyal Itkin
2020-07-21  2:44 ` Carlos O'Donell
2020-07-21  6:03   ` Florian Weimer
2020-07-23  2:35     ` Carlos O'Donell
2020-07-23 11:56       ` Adhemerval Zanella
2020-07-23 12:06         ` Florian Weimer
2020-07-23 21:26           ` Carlos O'Donell
2020-07-23 22:07             ` Eyal Itkin
2020-07-24  3:01               ` Carlos O'Donell
2020-07-24 12:29               ` Adhemerval Zanella

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).