public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Siddhesh Poyarekar <siddhesh@sourceware.org>
To: libc-alpha@sourceware.org
Cc: adhemerval.zanella@linaro.org, fweimer@redhat.com, carlos@redhat.com
Subject: [PATCH 1/2] Make all malloc tunables SXID_ERASE
Date: Tue,  3 Oct 2023 16:11:50 -0400	[thread overview]
Message-ID: <20231003201151.1406279-2-siddhesh@sourceware.org> (raw)
In-Reply-To: <20231003201151.1406279-1-siddhesh@sourceware.org>

The malloc tunables were made SXID_IGNORE to mimic the environment
variables they aliased, in order to maintain compatibility.  This
allowed alteration of allocator behaviour across setuid boundaries,
where a setuid program may ignore the tunable but its non-setuid child
can read it and adjust allocator behaviour accordingly.

It's not clear how useful this misfeature is; most library behaviour
tuning is limited to the current process and does not bleed in scope
like this.  If behaviour change across privilege boundaries is
desirable, it should be done with a wrapper program around the
non-setuid child that sets these envvars, instead of using the setuid
process as the messenger.  In future, maybe systemwide tunables could
allow setting tunable values across privilege boundaries.

Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
---
 elf/dl-tunables.list          | 12 +++---------
 elf/tst-env-setuid-tunables.c | 25 ++-----------------------
 elf/tst-env-setuid.c          |  4 ++--
 sysdeps/generic/unsecvars.h   |  7 +++++++
 4 files changed, 14 insertions(+), 34 deletions(-)

diff --git a/elf/dl-tunables.list b/elf/dl-tunables.list
index 695ba7192e..42d8ffd06d 100644
--- a/elf/dl-tunables.list
+++ b/elf/dl-tunables.list
@@ -22,7 +22,9 @@
 # maxval: Optional maximum acceptable value
 # env_alias: An alias environment variable
 # security_level: Specify security level of the tunable for AT_SECURE binaries.
-# 		  Valid values are:
+# 		  Valid values are as follows. There must be a strong, well
+# 		  documented reason for a tunable to be marked SXID_IGNORE or
+# 		  SXID_NONE:
 #
 # 	     SXID_ERASE: (default) Do not read and do not pass on to
 # 	     child processes.
@@ -41,7 +43,6 @@ glibc {
     top_pad {
       type: SIZE_T
       env_alias: MALLOC_TOP_PAD_
-      security_level: SXID_IGNORE
       default: 131072
     }
     perturb {
@@ -49,35 +50,29 @@ glibc {
       minval: 0
       maxval: 0xff
       env_alias: MALLOC_PERTURB_
-      security_level: SXID_IGNORE
     }
     mmap_threshold {
       type: SIZE_T
       env_alias: MALLOC_MMAP_THRESHOLD_
-      security_level: SXID_IGNORE
     }
     trim_threshold {
       type: SIZE_T
       env_alias: MALLOC_TRIM_THRESHOLD_
-      security_level: SXID_IGNORE
     }
     mmap_max {
       type: INT_32
       env_alias: MALLOC_MMAP_MAX_
-      security_level: SXID_IGNORE
       minval: 0
     }
     arena_max {
       type: SIZE_T
       env_alias: MALLOC_ARENA_MAX
       minval: 1
-      security_level: SXID_IGNORE
     }
     arena_test {
       type: SIZE_T
       env_alias: MALLOC_ARENA_TEST
       minval: 1
-      security_level: SXID_IGNORE
     }
     tcache_max {
       type: SIZE_T
@@ -91,7 +86,6 @@ glibc {
     mxfast {
       type: SIZE_T
       minval: 0
-      security_level: SXID_IGNORE
     }
     hugetlb {
       type: SIZE_T
diff --git a/elf/tst-env-setuid-tunables.c b/elf/tst-env-setuid-tunables.c
index f0b92c97e7..79795cdce7 100644
--- a/elf/tst-env-setuid-tunables.c
+++ b/elf/tst-env-setuid-tunables.c
@@ -60,26 +60,6 @@ const char *teststrings[] =
   "glibc.not_valid.check=2",
 };
 
-const char *resultstrings[] =
-{
-  "glibc.malloc.mmap_threshold=4096",
-  "glibc.malloc.mmap_threshold=4096",
-  "glibc.malloc.mmap_threshold=4096",
-  "glibc.malloc.perturb=0x800",
-  "glibc.malloc.perturb=0x800:glibc.malloc.mmap_threshold=4096",
-  "glibc.malloc.perturb=0x800:glibc.malloc.mmap_threshold=4096",
-  "glibc.malloc.mmap_threshold=4096",
-  "glibc.malloc.mmap_threshold=4096",
-  "glibc.malloc.mmap_threshold=glibc.malloc.mmap_threshold=4096",
-  "",
-  "",
-  "",
-  "",
-  "",
-  "",
-  "",
-};
-
 static int
 test_child (int off)
 {
@@ -87,12 +67,11 @@ test_child (int off)
 
   printf ("    [%d] GLIBC_TUNABLES is %s\n", off, val);
   fflush (stdout);
-  if (val != NULL && strcmp (val, resultstrings[off]) == 0)
+  if (val != NULL && val[0] == '\0')
     return 0;
 
   if (val != NULL)
-    printf ("    [%d] Unexpected GLIBC_TUNABLES VALUE %s, expected %s\n",
-	    off, val, resultstrings[off]);
+    printf ("    [%d] Unexpected GLIBC_TUNABLES VALUE %s\n", off, val);
   else
     printf ("    [%d] GLIBC_TUNABLES environment variable absent\n", off);
 
diff --git a/elf/tst-env-setuid.c b/elf/tst-env-setuid.c
index 032ab44be2..100e2c6871 100644
--- a/elf/tst-env-setuid.c
+++ b/elf/tst-env-setuid.c
@@ -46,9 +46,9 @@ test_child (void)
       return 1;
     }
 
-  if (getenv ("MALLOC_MMAP_THRESHOLD_") == NULL)
+  if (getenv ("MALLOC_MMAP_THRESHOLD_") != NULL)
     {
-      printf ("MALLOC_MMAP_THRESHOLD_ lost\n");
+      printf ("MALLOC_MMAP_THRESHOLD_ is still set\n");
       return 1;
     }
 
diff --git a/sysdeps/generic/unsecvars.h b/sysdeps/generic/unsecvars.h
index 8278c50a84..ca70e2e989 100644
--- a/sysdeps/generic/unsecvars.h
+++ b/sysdeps/generic/unsecvars.h
@@ -17,7 +17,14 @@
   "LD_SHOW_AUXV\0"							      \
   "LOCALDOMAIN\0"							      \
   "LOCPATH\0"								      \
+  "MALLOC_ARENA_MAX\0"							      \
+  "MALLOC_ARENA_TEST\0"							      \
+  "MALLOC_MMAP_MAX_\0"							      \
+  "MALLOC_MMAP_THRESHOLD_\0"						      \
+  "MALLOC_PERTURB_\0"							      \
+  "MALLOC_TOP_PAD_\0"							      \
   "MALLOC_TRACE\0"							      \
+  "MALLOC_TRIM_THRESHOLD_\0"						      \
   "NIS_PATH\0"								      \
   "NLSPATH\0"								      \
   "RESOLV_HOST_CONF\0"							      \
-- 
2.41.0


  reply	other threads:[~2023-10-03 20:12 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-03 20:11 [PATCH 0/2] make all " Siddhesh Poyarekar
2023-10-03 20:11 ` Siddhesh Poyarekar [this message]
2023-10-03 20:11 ` [PATCH 2/2] aarch64: Make glibc.mem.tagging SXID_ERASE Siddhesh Poyarekar
2023-10-04  7:29   ` Szabolcs Nagy
2023-10-04 11:59     ` Siddhesh Poyarekar
2023-10-04 14:04       ` Szabolcs Nagy
2023-10-04 14:23         ` Siddhesh Poyarekar
2023-10-04 14:51           ` Szabolcs Nagy
2023-10-04 14:53             ` Siddhesh Poyarekar
2023-10-04 15:05               ` Siddhesh Poyarekar
2023-10-04 17:01             ` Adhemerval Zanella Netto
2023-10-05  8:19               ` Szabolcs Nagy
2023-10-05 12:55                 ` Siddhesh Poyarekar
2023-10-05 13:59                   ` Szabolcs Nagy
2023-10-05 14:05                     ` Siddhesh Poyarekar
2023-10-05 18:31                     ` Zack Weinberg
2023-10-05 19:11                       ` Siddhesh Poyarekar
2023-10-06 12:25                         ` Zack Weinberg
2023-10-06 12:41                           ` Siddhesh Poyarekar
2023-10-06 17:10                             ` Adhemerval Zanella Netto
2023-10-06 18:04                               ` Siddhesh Poyarekar
2023-10-08 19:51                       ` Michael Hudson-Doyle
2023-10-31 19:58                         ` Zack Weinberg

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=20231003201151.1406279-2-siddhesh@sourceware.org \
    --to=siddhesh@sourceware.org \
    --cc=adhemerval.zanella@linaro.org \
    --cc=carlos@redhat.com \
    --cc=fweimer@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).