public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Siddhesh Poyarekar <siddhesh@sourceware.org>
To: Adhemerval Zanella <adhemerval.zanella@linaro.org>,
	libc-alpha@sourceware.org
Cc: Joe Simmons-Talbott <josimmon@redhat.com>
Subject: Re: [PATCH 2/4] elf: Remove glibc.rtld.enable_secure check from parse_tunables_string
Date: Wed, 1 May 2024 13:15:25 -0400	[thread overview]
Message-ID: <ff7cb57d-fbc7-4bd1-9964-eaa274c2e40d@sourceware.org> (raw)
In-Reply-To: <20240430192739.1032549-3-adhemerval.zanella@linaro.org>

On 2024-04-30 15:25, Adhemerval Zanella wrote:
> And move it to parse_tunables.  It avoids a string comparison for
> each tunable.
> 
> Checked on aarch64-linux-gnu and x86_64-linux-gnu.
> ---
>   elf/dl-tunables.c | 58 +++++++++++++++++++++++++++++++----------------
>   1 file changed, 38 insertions(+), 20 deletions(-)
> 
> diff --git a/elf/dl-tunables.c b/elf/dl-tunables.c
> index 1db80e0f92..63cf8c7ab5 100644
> --- a/elf/dl-tunables.c
> +++ b/elf/dl-tunables.c
> @@ -119,6 +119,17 @@ do_tunable_update_val (tunable_t *cur, const tunable_val_t *valp,
>     cur->initialized = true;
>   }
>   
> +static bool
> +tunable_parse_num (const char *strval, size_t len, tunable_num_t *val)
> +{
> +  char *endptr = NULL;
> +  uint64_t numval = _dl_strtoul (strval, &endptr);
> +  if (endptr != strval + len)
> +    return false;
> +  *val = (tunable_num_t) numval;
> +  return true;
> +}
> +
>   /* Validate range of the input value and initialize the tunable CUR if it looks
>      good.  */
>   static bool
> @@ -128,11 +139,8 @@ tunable_initialize (tunable_t *cur, const char *strval, size_t len)
>   
>     if (cur->type.type_code != TUNABLE_TYPE_STRING)
>       {
> -      char *endptr = NULL;
> -      uint64_t numval = _dl_strtoul (strval, &endptr);
> -      if (endptr != strval + len)
> +      if (!tunable_parse_num (strval, len, &val.numval))

Refactoring.  OK.

>   	return false;
> -      val.numval = (tunable_num_t) numval;
>       }
>     else
>       val.strval = (struct tunable_str_t) { strval, len };
> @@ -223,17 +231,6 @@ parse_tunables_string (const char *valstring, struct tunable_toset_t *tunables)
>   	  if (tunable_is_name (cur->name, name))
>   	    {
>   	      tunables[i] = (struct tunable_toset_t) { cur, value, p - value };
> -
> -	      /* Ignore tunables if enable_secure is set */
> -	      if (tunable_is_name ("glibc.rtld.enable_secure", name))
> -		{
> -                  tunable_num_t val = (tunable_num_t) _dl_strtoul (value, NULL);
> -		  if (val == 1)
> -		    {
> -		      __libc_enable_secure = 1;
> -		      return 0;
> -		    }
> -		}

Drop this string comparison for a tunable comparison below.  OK.

>   	      break;
>   	    }
>   	}
> @@ -242,6 +239,16 @@ parse_tunables_string (const char *valstring, struct tunable_toset_t *tunables)
>     return ntunables;
>   }
>   
> +static void
> +parse_tunable_print_error (const struct tunable_toset_t *toset)
> +{
> +  _dl_error_printf ("WARNING: ld.so: invalid GLIBC_TUNABLES value `%.*s' "
> +		    "for option `%s': ignored.\n",
> +		    (int) toset->len,
> +		    toset->value,
> +		    toset->t->name);
> +}
> +

Refactor.  OK.

>   static void
>   parse_tunables (const char *valstring)
>   {
> @@ -253,6 +260,21 @@ parse_tunables (const char *valstring)
>         return;
>       }
>   
> +  /* Ignore tunables if enable_secure is set */
> +  struct tunable_toset_t *tsec =
> +    &tunables[TUNABLE_ENUM_NAME(glibc, rtld, enable_secure)];
> +  if (tsec->t != NULL)
> +    {
> +      tunable_num_t val;
> +      if (!tunable_parse_num (tsec->value, tsec->len, &val))
> +        parse_tunable_print_error (tsec);
> +      else if (val == 1)
> +	{
> +	  __libc_enable_secure = 1;
> +	  return;
> +	}
> +    }
> +

Directly read the enable_secure tunable when it is set.  OK.

>     for (int i = 0; i < tunables_list_size; i++)
>       {
>         if (tunables[i].t == NULL)
> @@ -260,11 +282,7 @@ parse_tunables (const char *valstring)
>   
>         if (!tunable_initialize (tunables[i].t, tunables[i].value,
>   			       tunables[i].len))
> -	_dl_error_printf ("WARNING: ld.so: invalid GLIBC_TUNABLES value `%.*s' "
> -			  "for option `%s': ignored.\n",
> -			  (int) tunables[i].len,
> -			  tunables[i].value,
> -			  tunables[i].t->name);
> +	parse_tunable_print_error (&tunables[i]);
>       }
>   }
>   

Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>

  reply	other threads:[~2024-05-01 17:15 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-30 19:25 [PATCH 0/4] More tunable fixes Adhemerval Zanella
2024-04-30 19:25 ` [PATCH 1/4] elf: Only process multiple tunable once (BZ 31686) Adhemerval Zanella
2024-05-01 12:54   ` Florian Weimer
2024-05-01 14:19     ` Adhemerval Zanella Netto
2024-05-01 16:30   ` Siddhesh Poyarekar
2024-04-30 19:25 ` [PATCH 2/4] elf: Remove glibc.rtld.enable_secure check from parse_tunables_string Adhemerval Zanella
2024-05-01 17:15   ` Siddhesh Poyarekar [this message]
2024-04-30 19:25 ` [PATCH 3/4] support: Add envp argument to support_capture_subprogram Adhemerval Zanella
2024-04-30 20:06   ` Joe Simmons-Talbott
2024-04-30 19:25 ` [PATCH 4/4] elf: Make glibc.rtld.enable_secure ignore alias environment variables Adhemerval Zanella
2024-05-01 17:40   ` Siddhesh Poyarekar
2024-05-01 18:00     ` Adhemerval Zanella Netto
2024-05-02 11:03       ` Siddhesh Poyarekar

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

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

  git send-email \
    --in-reply-to=ff7cb57d-fbc7-4bd1-9964-eaa274c2e40d@sourceware.org \
    --to=siddhesh@sourceware.org \
    --cc=adhemerval.zanella@linaro.org \
    --cc=josimmon@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).