public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] elf: Don't call fatal_error in _dl_signal_error
@ 2024-04-03 12:39 H.J. Lu
  2024-04-03 19:54 ` Adhemerval Zanella Netto
  2024-04-08 15:28 ` Florian Weimer
  0 siblings, 2 replies; 5+ messages in thread
From: H.J. Lu @ 2024-04-03 12:39 UTC (permalink / raw)
  To: libc-alpha

Don't call fatal_error in _dl_signal_error since _dl_signal_error should
only be called from _dl_catch_exception and get_catch should never return
NULL.  Otherwise, fatal_error should be called directly instead.
---
 elf/dl-catch.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/elf/dl-catch.c b/elf/dl-catch.c
index 2109516dba..a023555165 100644
--- a/elf/dl-catch.c
+++ b/elf/dl-catch.c
@@ -117,16 +117,11 @@ _dl_signal_error (int errcode, const char *objname, const char *occasion,
   if (! errstring)
     errstring = N_("DYNAMIC LINKER BUG!!!");
 
-  if (lcatch != NULL)
-    {
-      _dl_exception_create (lcatch->exception, objname, errstring);
-      *lcatch->errcode = errcode;
+  _dl_exception_create (lcatch->exception, objname, errstring);
+  *lcatch->errcode = errcode;
 
-      /* We do not restore the signal mask because none was saved.  */
-      __longjmp (lcatch->env[0].__jmpbuf, 1);
-    }
-  else
-    fatal_error (errcode, objname, occasion, errstring);
+  /* We do not restore the signal mask because none was saved.  */
+  __longjmp (lcatch->env[0].__jmpbuf, 1);
 }
 rtld_hidden_def (_dl_signal_error)
 
-- 
2.44.0


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

* Re: [PATCH] elf: Don't call fatal_error in _dl_signal_error
  2024-04-03 12:39 [PATCH] elf: Don't call fatal_error in _dl_signal_error H.J. Lu
@ 2024-04-03 19:54 ` Adhemerval Zanella Netto
  2024-04-03 20:00   ` H.J. Lu
  2024-04-08 15:28 ` Florian Weimer
  1 sibling, 1 reply; 5+ messages in thread
From: Adhemerval Zanella Netto @ 2024-04-03 19:54 UTC (permalink / raw)
  To: libc-alpha, H.J. Lu



On 03/04/24 09:39, H.J. Lu wrote:
> Don't call fatal_error in _dl_signal_error since _dl_signal_error should
> only be called from _dl_catch_exception and get_catch should never return
> NULL.  Otherwise, fatal_error should be called directly instead.

Is this related to BZ#31596 or did you catch it by code review?  I think 
this is required for lazy binding being fatal error on initializer 
functions (elf/dl-open.c:829).

> ---
>  elf/dl-catch.c | 13 ++++---------
>  1 file changed, 4 insertions(+), 9 deletions(-)
> 
> diff --git a/elf/dl-catch.c b/elf/dl-catch.c
> index 2109516dba..a023555165 100644
> --- a/elf/dl-catch.c
> +++ b/elf/dl-catch.c
> @@ -117,16 +117,11 @@ _dl_signal_error (int errcode, const char *objname, const char *occasion,
>    if (! errstring)
>      errstring = N_("DYNAMIC LINKER BUG!!!");
>  
> -  if (lcatch != NULL)
> -    {
> -      _dl_exception_create (lcatch->exception, objname, errstring);
> -      *lcatch->errcode = errcode;
> +  _dl_exception_create (lcatch->exception, objname, errstring);
> +  *lcatch->errcode = errcode;
>  
> -      /* We do not restore the signal mask because none was saved.  */
> -      __longjmp (lcatch->env[0].__jmpbuf, 1);
> -    }
> -  else
> -    fatal_error (errcode, objname, occasion, errstring);
> +  /* We do not restore the signal mask because none was saved.  */
> +  __longjmp (lcatch->env[0].__jmpbuf, 1);
>  }
>  rtld_hidden_def (_dl_signal_error)
>  

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

* Re: [PATCH] elf: Don't call fatal_error in _dl_signal_error
  2024-04-03 19:54 ` Adhemerval Zanella Netto
@ 2024-04-03 20:00   ` H.J. Lu
  2024-04-04 16:56     ` Adhemerval Zanella Netto
  0 siblings, 1 reply; 5+ messages in thread
From: H.J. Lu @ 2024-04-03 20:00 UTC (permalink / raw)
  To: Adhemerval Zanella Netto; +Cc: libc-alpha

On Wed, Apr 3, 2024 at 12:54 PM Adhemerval Zanella Netto
<adhemerval.zanella@linaro.org> wrote:
>
>
>
> On 03/04/24 09:39, H.J. Lu wrote:
> > Don't call fatal_error in _dl_signal_error since _dl_signal_error should
> > only be called from _dl_catch_exception and get_catch should never return
> > NULL.  Otherwise, fatal_error should be called directly instead.
>
> Is this related to BZ#31596 or did you catch it by code review?  I think

Yes, it is related.  I noticed by code review.

> this is required for lazy binding being fatal error on initializer
> functions (elf/dl-open.c:829).

elf/dl-open.c:829 calls _dl_catch_exception.

> > ---
> >  elf/dl-catch.c | 13 ++++---------
> >  1 file changed, 4 insertions(+), 9 deletions(-)
> >
> > diff --git a/elf/dl-catch.c b/elf/dl-catch.c
> > index 2109516dba..a023555165 100644
> > --- a/elf/dl-catch.c
> > +++ b/elf/dl-catch.c
> > @@ -117,16 +117,11 @@ _dl_signal_error (int errcode, const char *objname, const char *occasion,
> >    if (! errstring)
> >      errstring = N_("DYNAMIC LINKER BUG!!!");
> >
> > -  if (lcatch != NULL)
> > -    {
> > -      _dl_exception_create (lcatch->exception, objname, errstring);
> > -      *lcatch->errcode = errcode;
> > +  _dl_exception_create (lcatch->exception, objname, errstring);
> > +  *lcatch->errcode = errcode;
> >
> > -      /* We do not restore the signal mask because none was saved.  */
> > -      __longjmp (lcatch->env[0].__jmpbuf, 1);
> > -    }
> > -  else
> > -    fatal_error (errcode, objname, occasion, errstring);
> > +  /* We do not restore the signal mask because none was saved.  */
> > +  __longjmp (lcatch->env[0].__jmpbuf, 1);
> >  }
> >  rtld_hidden_def (_dl_signal_error)
> >



-- 
H.J.

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

* Re: [PATCH] elf: Don't call fatal_error in _dl_signal_error
  2024-04-03 20:00   ` H.J. Lu
@ 2024-04-04 16:56     ` Adhemerval Zanella Netto
  0 siblings, 0 replies; 5+ messages in thread
From: Adhemerval Zanella Netto @ 2024-04-04 16:56 UTC (permalink / raw)
  To: H.J. Lu; +Cc: libc-alpha



On 03/04/24 17:00, H.J. Lu wrote:
> On Wed, Apr 3, 2024 at 12:54 PM Adhemerval Zanella Netto
> <adhemerval.zanella@linaro.org> wrote:
>>
>>
>>
>> On 03/04/24 09:39, H.J. Lu wrote:
>>> Don't call fatal_error in _dl_signal_error since _dl_signal_error should
>>> only be called from _dl_catch_exception and get_catch should never return
>>> NULL.  Otherwise, fatal_error should be called directly instead.
>>
>> Is this related to BZ#31596 or did you catch it by code review?  I think
> 
> Yes, it is related.  I noticed by code review.
> 
>> this is required for lazy binding being fatal error on initializer
>> functions (elf/dl-open.c:829).
> 
> elf/dl-open.c:829 calls _dl_catch_exception.

I think it because lazy binding errors from _dl_lookup_symbol_x calls
_dl_exception_create_format/_dl_signal_cexception instead of _dl_signal_error
mainly because it can not translate the message at the time. 

From _dl_catch_exception comment, it aims to support first argument being
NULL so all exceptions are fatal.  This change change this assumption,
meaning _dl_signal_error can not be called in this way (since now it always
expects to return the exception to caller).

> 
>>> ---
>>>  elf/dl-catch.c | 13 ++++---------
>>>  1 file changed, 4 insertions(+), 9 deletions(-)
>>>
>>> diff --git a/elf/dl-catch.c b/elf/dl-catch.c
>>> index 2109516dba..a023555165 100644
>>> --- a/elf/dl-catch.c
>>> +++ b/elf/dl-catch.c
>>> @@ -117,16 +117,11 @@ _dl_signal_error (int errcode, const char *objname, const char *occasion,
>>>    if (! errstring)
>>>      errstring = N_("DYNAMIC LINKER BUG!!!");
>>>
>>> -  if (lcatch != NULL)
>>> -    {
>>> -      _dl_exception_create (lcatch->exception, objname, errstring);
>>> -      *lcatch->errcode = errcode;
>>> +  _dl_exception_create (lcatch->exception, objname, errstring);
>>> +  *lcatch->errcode = errcode;
>>>
>>> -      /* We do not restore the signal mask because none was saved.  */
>>> -      __longjmp (lcatch->env[0].__jmpbuf, 1);
>>> -    }
>>> -  else
>>> -    fatal_error (errcode, objname, occasion, errstring);
>>> +  /* We do not restore the signal mask because none was saved.  */
>>> +  __longjmp (lcatch->env[0].__jmpbuf, 1);
>>>  }
>>>  rtld_hidden_def (_dl_signal_error)
>>>
> 
> 
> 

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

* Re: [PATCH] elf: Don't call fatal_error in _dl_signal_error
  2024-04-03 12:39 [PATCH] elf: Don't call fatal_error in _dl_signal_error H.J. Lu
  2024-04-03 19:54 ` Adhemerval Zanella Netto
@ 2024-04-08 15:28 ` Florian Weimer
  1 sibling, 0 replies; 5+ messages in thread
From: Florian Weimer @ 2024-04-08 15:28 UTC (permalink / raw)
  To: H.J. Lu; +Cc: libc-alpha

* H. J. Lu:

> Don't call fatal_error in _dl_signal_error since _dl_signal_error should
> only be called from _dl_catch_exception and get_catch should never return
> NULL.  Otherwise, fatal_error should be called directly instead.
> ---
>  elf/dl-catch.c | 13 ++++---------
>  1 file changed, 4 insertions(+), 9 deletions(-)
>
> diff --git a/elf/dl-catch.c b/elf/dl-catch.c
> index 2109516dba..a023555165 100644
> --- a/elf/dl-catch.c
> +++ b/elf/dl-catch.c
> @@ -117,16 +117,11 @@ _dl_signal_error (int errcode, const char *objname, const char *occasion,
>    if (! errstring)
>      errstring = N_("DYNAMIC LINKER BUG!!!");
>  
> -  if (lcatch != NULL)
> -    {
> -      _dl_exception_create (lcatch->exception, objname, errstring);
> -      *lcatch->errcode = errcode;
> +  _dl_exception_create (lcatch->exception, objname, errstring);
> +  *lcatch->errcode = errcode;
>  
> -      /* We do not restore the signal mask because none was saved.  */
> -      __longjmp (lcatch->env[0].__jmpbuf, 1);
> -    }
> -  else
> -    fatal_error (errcode, objname, occasion, errstring);
> +  /* We do not restore the signal mask because none was saved.  */
> +  __longjmp (lcatch->env[0].__jmpbuf, 1);
>  }
>  rtld_hidden_def (_dl_signal_error)

elf/ld.so program-does-not-exist triggers are null pointer dereference
with this patch.

I'll post a proper test case for this, looks like we have a gap here.

Thanks,
Florian


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

end of thread, other threads:[~2024-04-08 15:28 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-03 12:39 [PATCH] elf: Don't call fatal_error in _dl_signal_error H.J. Lu
2024-04-03 19:54 ` Adhemerval Zanella Netto
2024-04-03 20:00   ` H.J. Lu
2024-04-04 16:56     ` Adhemerval Zanella Netto
2024-04-08 15:28 ` Florian Weimer

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).