public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Adhemerval Zanella <azanella@sourceware.org>
To: glibc-cvs@sourceware.org
Subject: [glibc] elf: Do not process invalid tunable format
Date: Tue, 21 Nov 2023 20:48:51 +0000 (GMT)	[thread overview]
Message-ID: <20231121204851.B6CD73858D38@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=b4cf6cac73725d988957410116ddf088546239ca

commit b4cf6cac73725d988957410116ddf088546239ca
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Mon Nov 6 17:25:38 2023 -0300

    elf: Do not process invalid tunable format
    
    Tunable definitions with more than one '=' on are parsed and enabled,
    and any subsequent '=' are ignored.  It means that tunables in the form
    'tunable=tunable=value' or 'tunable=value=value' are handled as
    'tunable=value'.  These inputs are likely user input errors, which
    should not be accepted.
    
    Checked on x86_64-linux-gnu.
    Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>

Diff:
---
 elf/dl-tunables.c  |  6 ++++--
 elf/tst-tunables.c | 22 +++++++++++++++++-----
 2 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/elf/dl-tunables.c b/elf/dl-tunables.c
index f7dca8f7c1..082a76d9c4 100644
--- a/elf/dl-tunables.c
+++ b/elf/dl-tunables.c
@@ -192,10 +192,12 @@ parse_tunables (char *valstring)
 
       const char *value = p;
 
-      while (*p != ':' && *p != '\0')
+      while (*p != '=' && *p != ':' && *p != '\0')
 	p++;
 
-      if (*p == '\0')
+      if (*p == '=')
+	break;
+      else if (*p == '\0')
 	done = true;
       else
 	*p++ = '\0';
diff --git a/elf/tst-tunables.c b/elf/tst-tunables.c
index d874b73b68..7fe9907e05 100644
--- a/elf/tst-tunables.c
+++ b/elf/tst-tunables.c
@@ -161,24 +161,36 @@ static const struct test_t
     0,
     0,
   },
-  /* The ill-formatted tunable is also skipped.  */
+  /* If there is a ill-formatted key=value, everything after is also ignored.  */
   {
     "glibc.malloc.mmap_threshold=glibc.malloc.mmap_threshold=4096:glibc.malloc.check=2",
-    2,
+    0,
     0,
     0,
   },
-  /* For an integer tunable, parse will stop on non number character.  */
   {
     "glibc.malloc.check=2=2",
-    2,
+    0,
     0,
     0,
   },
   {
     "glibc.malloc.check=2=2:glibc.malloc.mmap_threshold=4096",
+    0,
+    0,
+    0,
+  },
+  {
+    "glibc.malloc.check=2=2:glibc.malloc.check=2",
+    0,
+    0,
+    0,
+  },
+  /* Valid tunables set before ill-formatted ones are set.  */
+  {
+    "glibc.malloc.check=2:glibc.malloc.mmap_threshold=4096=4096",
     2,
-    4096,
+    0,
     0,
   }
 };

                 reply	other threads:[~2023-11-21 20:48 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20231121204851.B6CD73858D38@sourceware.org \
    --to=azanella@sourceware.org \
    --cc=glibc-cvs@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).