From: Carlos O'Donell <carlos@redhat.com>
To: Eyal Itkin <eyal.itkin@gmail.com>,
GNU C Library <libc-alpha@sourceware.org>,
Florian Weimer <fweimer@redhat.com>
Subject: Re: [suggestion] tcache double-free check
Date: Mon, 20 Jul 2020 22:44:28 -0400 [thread overview]
Message-ID: <7cdac141-6a06-e6b8-7a2e-66e74c050bc9@redhat.com> (raw)
In-Reply-To: <CAA=iMU+z0rEMe5nTa=DCGv__Wf2XvwyNtz45BoX2qVki+ySD_A@mail.gmail.com>
On 7/19/20 2:40 AM, Eyal Itkin via Libc-alpha wrote:
> 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.
Just for reference the ML list URL is here:
https://sourceware.org/pipermail/libc-alpha/2018-November/098357.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.
> "
Correct.
> 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.
That sounds good to me.
I assume the point being that you can't use a "memory derefernce"
gadget directly with that memory, you'd need some other primitive
to process the ~tcache.
> 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.
I have no objections. I'd like to hear Florian's input (on TO).
--
Cheers,
Carlos.
next prev parent reply other threads:[~2020-07-21 2:44 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-19 6:40 Eyal Itkin
2020-07-21 2:44 ` Carlos O'Donell [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7cdac141-6a06-e6b8-7a2e-66e74c050bc9@redhat.com \
--to=carlos@redhat.com \
--cc=eyal.itkin@gmail.com \
--cc=fweimer@redhat.com \
--cc=libc-alpha@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).