unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Siddhesh Poyarekar <siddhesh@gotplt.org>
To: Eyal Itkin <eyal.itkin@gmail.com>, Carlos O'Donell <carlos@redhat.com>
Cc: Florian Weimer <fweimer@redhat.com>,
	GNU C Library <libc-alpha@sourceware.org>
Subject: Re: [PATCH] Update tcache double-free check
Date: Fri, 2 Jul 2021 12:54:43 +0530	[thread overview]
Message-ID: <0c7d951e-ef54-e521-535d-920ad76be33b@gotplt.org> (raw)
In-Reply-To: <CAA=iMULG5VYLWYDSRNdHwUmekUS0V3DPPky84hmQkuCD50cGKQ@mail.gmail.com>

Hello Eyal,

Carlos asked me to take a look at this because we think it's important 
to close this hole if we can.  Sorry we took long to get back to this.

On 8/10/20 7:05 PM, Eyal Itkin via Libc-alpha wrote:
> Due to that, I recommend using a random value per process according to
> the original scheme of getrandom() and a backup of "~tcache". Keeping
> in mind that the ASLR bits will supply some random, and that ~tcache
> will never be a value we expect to see in memory and won't ever be a
> mapped memory address that could be used by a use-after-free
> vulnerability as the original key ("tcache") was exploited. I don't
> see any value in a per-thread random key, as again, the random value
> will only help us avoid collisions with values from the program's
> memory.

Agreed, a per-process key is sufficient.  However your latest patch 
appears to have a per-thread key; I assume you intend to post an update 
patch based on feedback?

Given that our only goals are (1) put in some random value to avoid 
collisions and (2) not leak the address of an internal structure in the 
process, could this just be a single process-wide variable that is 
initialized at startup?

What this implies is that tcache_key (a static variable and not 
__thread) is initialized in ptmalloc_init instead of tcache_init and the 
same value is used in all threads.  ptmalloc_init is guaranteed to run 
in a single-threaded context as malloc gets called in the process of 
thread creation before it is spawned and hence should not need any 
synchronization.

Finally for randomness of the tcache_key, it might make sense to use 
getrandom first (as the patch already does) and then on failure, fall 
back to a munging of ~tcache and random_bits() (from 
include/random-bits.h) so that we don't leak addresses even on fallback. 
  However I'm not convinced that getrandom() is strictly necessary given 
our goals; I reckon it's just harmless given that it's a one time cost.

Siddhesh

PS: I'll make sure you're cc'd on this conversation, so you don't have 
to be registered to the mailing list to stay on track with this 
conversation.

  parent reply	other threads:[~2021-07-02  7:25 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-24 13:37 [PATCH] Update tcache double-free check Eyal Itkin via Libc-alpha
2020-07-24 21:05 ` Carlos O'Donell via Libc-alpha
2020-07-25 10:39   ` Eyal Itkin via Libc-alpha
2020-07-25 21:07     ` Carlos O'Donell via Libc-alpha
2020-08-10 13:07       ` Eyal Itkin via Libc-alpha
2020-08-10 13:12         ` Carlos O'Donell via Libc-alpha
2020-08-10 13:35           ` Eyal Itkin via Libc-alpha
2020-08-10 13:44             ` Carlos O'Donell via Libc-alpha
2021-07-02  7:24             ` Siddhesh Poyarekar [this message]
2021-07-02  7:57               ` Eyal Itkin via Libc-alpha
2021-07-02  8:45                 ` Siddhesh Poyarekar
2020-08-26 20:40           ` Carlos O'Donell via Libc-alpha
2020-10-03  9:04             ` Eyal Itkin via Libc-alpha
2020-10-04 19:41               ` Carlos O'Donell via Libc-alpha
2020-10-14 13:44                 ` Eyal Itkin via Libc-alpha

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

  List information: https://www.gnu.org/software/libc/involved.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0c7d951e-ef54-e521-535d-920ad76be33b@gotplt.org \
    --to=siddhesh@gotplt.org \
    --cc=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).