This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] BZ #14545: Always check dtv before freeing dtv[-1]
- From: Andreas Jaeger <aj at suse dot com>
- To: libc-alpha at sourceware dot org, "H.J. Lu" <hjl dot tools at gmail dot com>
- Date: Thu, 06 Sep 2012 10:08:11 +0200
- Subject: Re: [PATCH] BZ #14545: Always check dtv before freeing dtv[-1]
- References: <20120905202107.GA22504@intel.com>
On Wednesday, September 05, 2012 13:21:07 H.J. Lu wrote:
> Hi,
>
> We should always check dtv before freeing dtv[-1], including in
> libc.a, since dtv is a static array in libc.a. _dl_initial_dtv
> is intialized to &static_dtv[1] so that index -1 contains the length.
> Testd on Linux/x86-64. OK to install?
Could you add a test for the testsuite, please?
Andreas
> Thanks.
>
>
> H.J.
> ---
> ChangeLog | 7 +++++++
> csu/libc-tls.c | 2 ++
> elf/dl-tls.c | 2 --
> 3 files changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/ChangeLog b/ChangeLog
> index 8e3667f..672f99f 100644
> --- a/ChangeLog
> +++ b/ChangeLog
> @@ -1,5 +1,12 @@
> 2012-09-05 H.J. Lu <hongjiu.lu@intel.com>
>
> + [BZ #14545]
> + * csu/libc-tls.c (_dl_initial_dtv): New variable.
> + * elf/dl-tls.c (_dl_deallocate_tls): Always check dtv before
> + freeing dtv[-1].
> +
> +2012-09-05 H.J. Lu <hongjiu.lu@intel.com>
> +
> [BZ #5784]
> * extra-lib.mk: Skip archive if it is in $(skip-lib.a)
>
> diff --git a/csu/libc-tls.c b/csu/libc-tls.c
> index b00a5cc..eb9c502 100644
> --- a/csu/libc-tls.c
> +++ b/csu/libc-tls.c
> @@ -65,6 +65,8 @@ size_t _dl_tls_static_size = 2048;
> size_t _dl_tls_static_used;
> /* Alignment requirement of the static TLS block. */
> size_t _dl_tls_static_align;
> +/* Initial dtv of the main thread, not allocated with normal malloc.
> */ +void *_dl_initial_dtv = &static_dtv[1];
>
> /* Generation counter for the dtv. */
> size_t _dl_tls_generation;
> diff --git a/elf/dl-tls.c b/elf/dl-tls.c
> index 4138312..ff59e9e 100644
> --- a/elf/dl-tls.c
> +++ b/elf/dl-tls.c
> @@ -477,9 +477,7 @@ _dl_deallocate_tls (void *tcb, bool dealloc_tcb)
> free (dtv[1 + cnt].pointer.val);
>
> /* The array starts with dtv[-1]. */
> -#ifdef SHARED
> if (dtv != GL(dl_initial_dtv))
> -#endif
> free (dtv - 1);
>
> if (dealloc_tcb)
--
Andreas Jaeger aj@{suse.com,opensuse.org} Twitter/Identica: jaegerandi
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn,Jennifer Guild,Felix Imendörffer,HRB16746 (AG Nürnberg)
GPG fingerprint = 93A3 365E CE47 B889 DF7F FED1 389A 563C C272 A126