public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH][BZ 21357] unwind-dw2-fde: Call free() outside of unwind mutex
@ 2017-04-06 19:58 Rabin Vincent
  2017-04-10 14:40 ` Adhemerval Zanella
  0 siblings, 1 reply; 4+ messages in thread
From: Rabin Vincent @ 2017-04-06 19:58 UTC (permalink / raw)
  To: libc-alpha; +Cc: Rabin Vincent

From: Rabin Vincent <rabinv@axis.com>

__deregister_frame_info_bases() calls free() while holding a mutex which
is also used from _Unwind_Find_FDE().  This leads to a deadlock if
AddressSanitizer uses _Unwind_Backtrace() from its free()
implementation.

2017-04-06  Rabin Vincent  <rabinv@axis.com>

	[BZ #21357]
	* sysdeps/generic/unwind-dw2-fde.c (__deregister_frame_info_bases):
	Call free() outside of mutex.

diff --git a/sysdeps/generic/unwind-dw2-fde.c b/sysdeps/generic/unwind-dw2-fde.c
index 2f0bcd2..104a255 100644
--- a/sysdeps/generic/unwind-dw2-fde.c
+++ b/sysdeps/generic/unwind-dw2-fde.c
@@ -202,6 +202,7 @@ __deregister_frame_info_bases (void *begin)
 {
   struct object **p;
   struct object *ob = 0;
+  struct fde_vector *tofree = NULL;
 
   /* If .eh_frame is empty, we haven't registered.  */
   if (*(uword *) begin == 0)
@@ -225,7 +226,7 @@ __deregister_frame_info_bases (void *begin)
 	  {
 	    ob = *p;
 	    *p = ob->next;
-	    free (ob->u.sort);
+	    tofree = ob->u.sort;
 	    goto out;
 	  }
       }
@@ -244,6 +245,7 @@ __deregister_frame_info_bases (void *begin)
 
  out:
   __gthread_mutex_unlock (&object_mutex);
+  free (tofree);
   return (void *) ob;
 }
 hidden_def (__deregister_frame_info_bases)

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

* Re: [PATCH][BZ 21357] unwind-dw2-fde: Call free() outside of unwind mutex
  2017-04-06 19:58 [PATCH][BZ 21357] unwind-dw2-fde: Call free() outside of unwind mutex Rabin Vincent
@ 2017-04-10 14:40 ` Adhemerval Zanella
  2017-04-13  9:55   ` Rabin Vincent
  0 siblings, 1 reply; 4+ messages in thread
From: Adhemerval Zanella @ 2017-04-10 14:40 UTC (permalink / raw)
  To: libc-alpha

On 06/04/2017 16:58, Rabin Vincent wrote:
> From: Rabin Vincent <rabinv@axis.com>
> 
> __deregister_frame_info_bases() calls free() while holding a mutex which
> is also used from _Unwind_Find_FDE().  This leads to a deadlock if
> AddressSanitizer uses _Unwind_Backtrace() from its free()
> implementation.
> 
> 2017-04-06  Rabin Vincent  <rabinv@axis.com>
> 
> 	[BZ #21357]
> 	* sysdeps/generic/unwind-dw2-fde.c (__deregister_frame_info_bases):
> 	Call free() outside of mutex.
> 
> diff --git a/sysdeps/generic/unwind-dw2-fde.c b/sysdeps/generic/unwind-dw2-fde.c
> index 2f0bcd2..104a255 100644
> --- a/sysdeps/generic/unwind-dw2-fde.c
> +++ b/sysdeps/generic/unwind-dw2-fde.c
> @@ -202,6 +202,7 @@ __deregister_frame_info_bases (void *begin)
>  {
>    struct object **p;
>    struct object *ob = 0;
> +  struct fde_vector *tofree = NULL;
>  
>    /* If .eh_frame is empty, we haven't registered.  */
>    if (*(uword *) begin == 0)
> @@ -225,7 +226,7 @@ __deregister_frame_info_bases (void *begin)
>  	  {
>  	    ob = *p;
>  	    *p = ob->next;
> -	    free (ob->u.sort);
> +	    tofree = ob->u.sort;
>  	    goto out;
>  	  }
>        }
> @@ -244,6 +245,7 @@ __deregister_frame_info_bases (void *begin)
>  
>   out:
>    __gthread_mutex_unlock (&object_mutex);
> +  free (tofree);
>    return (void *) ob;
>  }
>  hidden_def (__deregister_frame_info_bases)

LGTM, I assume you actually tested on some platform, right? Do you have write access?

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

* Re: [PATCH][BZ 21357] unwind-dw2-fde: Call free() outside of unwind mutex
  2017-04-10 14:40 ` Adhemerval Zanella
@ 2017-04-13  9:55   ` Rabin Vincent
  2017-04-13 17:28     ` Adhemerval Zanella
  0 siblings, 1 reply; 4+ messages in thread
From: Rabin Vincent @ 2017-04-13  9:55 UTC (permalink / raw)
  To: Adhemerval Zanella; +Cc: libc-alpha

On Mon, Apr 10, 2017 at 11:40:07AM -0300, Adhemerval Zanella wrote:
> On 06/04/2017 16:58, Rabin Vincent wrote:
> > 	[BZ #21357]
> > 	* sysdeps/generic/unwind-dw2-fde.c (__deregister_frame_info_bases):
> > 	Call free() outside of mutex.
> 
> LGTM, I assume you actually tested on some platform, right? Do you have write access?

Yes, I tested it on a 32-bit MIPS platform.  No, I don't have write
access.

Thanks.

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

* Re: [PATCH][BZ 21357] unwind-dw2-fde: Call free() outside of unwind mutex
  2017-04-13  9:55   ` Rabin Vincent
@ 2017-04-13 17:28     ` Adhemerval Zanella
  0 siblings, 0 replies; 4+ messages in thread
From: Adhemerval Zanella @ 2017-04-13 17:28 UTC (permalink / raw)
  To: Rabin Vincent; +Cc: libc-alpha



On 13/04/2017 06:55, Rabin Vincent wrote:
> On Mon, Apr 10, 2017 at 11:40:07AM -0300, Adhemerval Zanella wrote:
>> On 06/04/2017 16:58, Rabin Vincent wrote:
>>> 	[BZ #21357]
>>> 	* sysdeps/generic/unwind-dw2-fde.c (__deregister_frame_info_bases):
>>> 	Call free() outside of mutex.
>>
>> LGTM, I assume you actually tested on some platform, right? Do you have write access?
> 
> Yes, I tested it on a 32-bit MIPS platform.  No, I don't have write
> access.
> 
> Thanks.
> 

Alright, I will check this in.

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

end of thread, other threads:[~2017-04-13 17:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-06 19:58 [PATCH][BZ 21357] unwind-dw2-fde: Call free() outside of unwind mutex Rabin Vincent
2017-04-10 14:40 ` Adhemerval Zanella
2017-04-13  9:55   ` Rabin Vincent
2017-04-13 17:28     ` 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).