aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>2024-05-06 13:18:46 -0300
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>2024-05-07 12:16:36 -0300
commitc8a0e21da63b6e5c7f558cdd31a5d208c1677df3 (patch)
tree2fcb785053ffe7d081b4b2c3181b666d6db9315f
parentbcae44ea8536b30a7119c0986ff5692bddacb672 (diff)
downloadglibc-c8a0e21da63b6e5c7f558cdd31a5d208c1677df3.zip
glibc-c8a0e21da63b6e5c7f558cdd31a5d208c1677df3.tar.gz
glibc-c8a0e21da63b6e5c7f558cdd31a5d208c1677df3.tar.bz2
elf: Remove glibc.rtld.enable_secure check from parse_tunables_string
And move it to parse_tunables. It avoids a string comparison for each tunable. Checked on aarch64-linux-gnu and x86_64-linux-gnu. Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
-rw-r--r--elf/dl-tunables.c58
1 files changed, 38 insertions, 20 deletions
diff --git a/elf/dl-tunables.c b/elf/dl-tunables.c
index 1db80e0..63cf8c7 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))
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;
- }
- }
break;
}
}
@@ -243,6 +240,16 @@ parse_tunables_string (const char *valstring, struct tunable_toset_t *tunables)
}
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);
+}
+
+static void
parse_tunables (const char *valstring)
{
struct tunable_toset_t tunables[tunables_list_size] = { 0 };
@@ -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;
+ }
+ }
+
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]);
}
}