Patchwork RFC: tunables failure indications...

login
register
mail settings
Submitter DJ Delorie
Date Dec. 11, 2019, 10 p.m.
Message ID <xnh826sesv.fsf@greed.delorie.com>
Download mbox | patch
Permalink /patch/36733/
State New
Headers show

Comments

DJ Delorie - Dec. 11, 2019, 10 p.m.
Siddhesh Poyarekar <siddhesh@gotplt.org> writes:
>> No, in the case DJ and I were looking at this was a static vs. ASLR vs.
>> kernel VMA layout issue where we still have kernel issues on less
>> maintstream architectures. We still need to fail safe in those cases
>> and I think we should just shut the process down with appropriate error
>> messages.
>
> OK, I was just wondering if this was a kernel bug.  Either ways,
> shutting down with an error sounds good, preferably in the ld.so way
> (i.e. write to stderr and _exit()) rather than a forced segfault.

How about this?
Siddhesh Poyarekar - Dec. 12, 2019, 3:50 a.m.
On 12/12/19 3:30 am, DJ Delorie wrote:
> diff --git a/elf/dl-tunables.c b/elf/dl-tunables.c
> index e625ac1a7d..b55d677aee 100644
> --- a/elf/dl-tunables.c
> +++ b/elf/dl-tunables.c
> @@ -45,12 +45,15 @@ tunables_strdup (const char *in)
>    while (in[i++] != '\0');
>    char *out = __sbrk (i);
>  
> -  /* FIXME: In reality if the allocation fails, __sbrk will crash attempting to
> -     set the thread-local errno since the TCB has not yet been set up.  This
> -     needs to be fixed with an __sbrk implementation that does not set
> -     errno.  */
> +  /* For most of the tunables code, we ignore user errors.  However,
> +     this is a system error - and running out of memory at program
> +     startup should be reported, so we do.  */
>    if (out == (void *)-1)
> -    return NULL;
> +    {
> +#define SBRKMSG "sbrk() failure while processing tunables"
> +      write (2, SBRKMSG, sizeof(SBRKMSG) - 1);
> +      _exit (1);

I think this could be a _dl_fatal_printf() or similar.

Siddhesh

Patch

diff --git a/elf/dl-tunables.c b/elf/dl-tunables.c
index e625ac1a7d..b55d677aee 100644
--- a/elf/dl-tunables.c
+++ b/elf/dl-tunables.c
@@ -45,12 +45,15 @@  tunables_strdup (const char *in)
   while (in[i++] != '\0');
   char *out = __sbrk (i);
 
-  /* FIXME: In reality if the allocation fails, __sbrk will crash attempting to
-     set the thread-local errno since the TCB has not yet been set up.  This
-     needs to be fixed with an __sbrk implementation that does not set
-     errno.  */
+  /* For most of the tunables code, we ignore user errors.  However,
+     this is a system error - and running out of memory at program
+     startup should be reported, so we do.  */
   if (out == (void *)-1)
-    return NULL;
+    {
+#define SBRKMSG "sbrk() failure while processing tunables"
+      write (2, SBRKMSG, sizeof(SBRKMSG) - 1);
+      _exit (1);
+    }
 
   i--;