{"id":2224686,"url":"http://patchwork.ozlabs.org/api/1.2/patches/2224686/?format=json","web_url":"http://patchwork.ozlabs.org/project/glibc/patch/f2c3955f106f9ce2401a97c392d3bb3575b10b0b.1776449736.git.dj@redhat.com/","project":{"id":41,"url":"http://patchwork.ozlabs.org/api/1.2/projects/41/?format=json","name":"GNU C Library","link_name":"glibc","list_id":"libc-alpha.sourceware.org","list_email":"libc-alpha@sourceware.org","web_url":"","scm_url":"","webscm_url":"","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<f2c3955f106f9ce2401a97c392d3bb3575b10b0b.1776449736.git.dj@redhat.com>","list_archive_url":null,"date":"2024-02-21T23:49:50","name":"[v7,3/4] Add system-wide tunables: Apply tunables part","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"e11fb1bd350087183154b2265616c8576bc31b55","submitter":{"id":4388,"url":"http://patchwork.ozlabs.org/api/1.2/people/4388/?format=json","name":"DJ Delorie","email":"dj@redhat.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/glibc/patch/f2c3955f106f9ce2401a97c392d3bb3575b10b0b.1776449736.git.dj@redhat.com/mbox/","series":[{"id":500385,"url":"http://patchwork.ozlabs.org/api/1.2/series/500385/?format=json","web_url":"http://patchwork.ozlabs.org/project/glibc/list/?series=500385","date":"2024-02-21T23:49:50","name":"Add system-wide tunables","version":7,"mbox":"http://patchwork.ozlabs.org/series/500385/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2224686/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2224686/checks/","tags":{},"related":[],"headers":{"Return-Path":"<libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org>","X-Original-To":["incoming@patchwork.ozlabs.org","libc-alpha@sourceware.org"],"Delivered-To":["patchwork-incoming@legolas.ozlabs.org","libc-alpha@sourceware.org"],"Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=CihkHv9F;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org\n (client-ip=2620:52:6:3111::32; helo=vm01.sourceware.org;\n envelope-from=libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org;\n receiver=patchwork.ozlabs.org)","sourceware.org;\n\tdkim=pass (1024-bit key,\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=CihkHv9F","sourceware.org; dmarc=pass (p=quarantine dis=none)\n header.from=redhat.com","sourceware.org; spf=pass smtp.mailfrom=redhat.com","server2.sourceware.org;\n arc=none smtp.remote-ip=170.10.129.124"],"Received":["from vm01.sourceware.org (vm01.sourceware.org\n [IPv6:2620:52:6:3111::32])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fy3735FZTz1yD3\n\tfor <incoming@patchwork.ozlabs.org>; Sat, 18 Apr 2026 04:19:06 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id A9DCA4CD2014\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 17 Apr 2026 18:19:04 +0000 (GMT)","from us-smtp-delivery-124.mimecast.com\n (us-smtp-delivery-124.mimecast.com [170.10.129.124])\n by sourceware.org (Postfix) with ESMTP id 026594AA3974\n for <libc-alpha@sourceware.org>; Fri, 17 Apr 2026 18:18:38 +0000 (GMT)","from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com\n (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by\n relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3,\n cipher=TLS_AES_256_GCM_SHA384) id us-mta-437-u9p4Y1TlNjO7Apagn_D_mw-1; Fri,\n 17 Apr 2026 14:18:37 -0400","from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com\n (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest\n SHA256)\n (No client certificate requested)\n by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS\n id 5042919560BB\n for <libc-alpha@sourceware.org>; Fri, 17 Apr 2026 18:18:36 +0000 (UTC)","from greed.delorie.com (unknown [10.22.88.82])\n by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with\n ESMTPS\n id 0FBB319560B1\n for <libc-alpha@sourceware.org>; Fri, 17 Apr 2026 18:18:35 +0000 (UTC)","from greed.delorie.com (localhost [127.0.0.1])\n by greed.delorie.com (8.16.1/8.16.1) with ESMTPS id 63HIIYVb651997\n (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT)\n for <libc-alpha@sourceware.org>; Fri, 17 Apr 2026 14:18:34 -0400","(from dj@localhost)\n by greed.delorie.com (8.16.1/8.16.1/Submit) id 63HIIYMr651996;\n Fri, 17 Apr 2026 14:18:34 -0400"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org A9DCA4CD2014","OpenDKIM Filter v2.11.0 sourceware.org 026594AA3974"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org 026594AA3974","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org 026594AA3974","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776449919; cv=none;\n b=O5n19qGV51pZAUdMvbpG7jotCM4w7PV3orF7RioqQgpkZKVJLN9Q0Q5Mrqn+yKzu3Jx5Ciep8f0oG9snqEIE6T/PwCsIfn1t9RiyVIHxxCikRsfiVdrEw6LBjEKXvHRUHBTr5f90WD1MSpPN0VpUKciSCnI0PXHVrVDLRV72vWo=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1776449919; c=relaxed/simple;\n bh=iTGEOzPhwRbwdsCdlkOI+OB4zk+5dekPQPRG//2hWp0=;\n h=DKIM-Signature:Message-ID:From:Date:Subject:To;\n b=MKC6yJDFuReQPGIchWsCZhI2GQmZ0awQQlXlDf5L5lLFtAo/NUYhSEiUiiwsSypci8Ub3e85RbW1AxM4QQfKuTYigoo7rtlGfo7LYUTVW9hxTZSWyLOzb4uA5GmFoIykGvTlU79jhKuaYCbxqIGRnJtuHC4xiB7TVyYURAG5wpI=","ARC-Authentication-Results":"i=1; server2.sourceware.org","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n s=mimecast20190719; t=1776449918;\n h=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n to:to:cc:content-type:content-type:in-reply-to:in-reply-to:\n references:references; bh=LMY0h7Z3pjJfGjyPuByYP67T04CZ/fbXSTtqgnzeWWg=;\n b=CihkHv9F6HvJgltF51tG5NkSLZjlHoJVu6vdyptwX8oP6B3Jsm9Zm7a4zOoNMD+rt8hxCw\n hkl+5ymqX9gvhaQ0OYCCAsGX2fFsPlnzravevpX7Ab+G/+uzGirmewGOiluAwNB5GFxfhd\n oTQOM25dhOpwB8EszuQfaiFJgUVdAUg=","X-MC-Unique":"u9p4Y1TlNjO7Apagn_D_mw-1","X-Mimecast-MFC-AGG-ID":"u9p4Y1TlNjO7Apagn_D_mw_1776449916","Message-ID":"\n <f2c3955f106f9ce2401a97c392d3bb3575b10b0b.1776449736.git.dj@redhat.com>","In-Reply-To":"<cover.1776449736.git.dj@redhat.com>","References":"<cover.1776449736.git.dj@redhat.com>","From":"DJ Delorie <dj@redhat.com>","Date":"Wed, 21 Feb 2024 18:49:50 -0500","Subject":"[PATCH v7 3/4] Add system-wide tunables: Apply tunables part","To":"libc-alpha@sourceware.org","X-Scanned-By":"MIMEDefang 3.0 on 10.30.177.12","X-Mimecast-Spam-Score":"2","X-Mimecast-MFC-PROC-ID":"lLifmqQHuqjN21ueM01Kuem39zbRGg_cxTtHiMoKr6E_1776449916","X-Mimecast-Originator":"redhat.com","Content-type":"text/plain; charset=UTF-8","X-BeenThere":"libc-alpha@sourceware.org","X-Mailman-Version":"2.1.30","Precedence":"list","List-Id":"Libc-alpha mailing list <libc-alpha.sourceware.org>","List-Unsubscribe":"<https://sourceware.org/mailman/options/libc-alpha>,\n <mailto:libc-alpha-request@sourceware.org?subject=unsubscribe>","List-Archive":"<https://sourceware.org/pipermail/libc-alpha/>","List-Post":"<mailto:libc-alpha@sourceware.org>","List-Help":"<mailto:libc-alpha-request@sourceware.org?subject=help>","List-Subscribe":"<https://sourceware.org/mailman/listinfo/libc-alpha>,\n <mailto:libc-alpha-request@sourceware.org?subject=subscribe>","Errors-To":"libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org"},"content":"Load ld.so.cache and fetch the tunables extension.  Apply\nthose tunables to the current program.  We do not yet apply\nsecurity policies.\n---\n elf/dl-cache.c    | 38 ++++++++++++++++++++++++++++\n elf/dl-tunables.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++\n elf/tunconf.h     |  3 +++\n 3 files changed, 104 insertions(+)","diff":"diff --git a/elf/dl-cache.c b/elf/dl-cache.c\nindex 9d5fc05cd6..1aa64e4102 100644\n--- a/elf/dl-cache.c\n+++ b/elf/dl-cache.c\n@@ -27,6 +27,7 @@\n #include <dl-isa-level.h>\n #include <fcntl.h>\n #include <sys/stat.h>\n+#include \"tunconf.h\"\n \n /* This is the starting address and the size of the mmap()ed file.  */\n static struct cache_file *cache;\n@@ -606,3 +607,40 @@ _dl_unload_cache (void)\n      now.  */\n }\n #endif\n+\n+const struct tunable_header_cached *\n+_dl_load_cache_tunables (const char **data)\n+{\n+  struct cache_extension_all_loaded ext;\n+  struct tunable_header_cached *thc;\n+  struct tunable_entry_cached *tec;\n+  int count;\n+\n+  if (_dl_check_ldsocache_needs_loading ())\n+    _dl_maybe_load_ldsocache ();\n+\n+  if (cache_new)\n+    *data = (const char *) cache_new;\n+  else\n+    return NULL;\n+\n+  if (!cache_extension_load (cache_new, cache, cachesize, &ext))\n+    return NULL;\n+\n+  /* Validate length/contents here. */\n+  if (ext.sections[cache_extension_tag_tunables].size\n+      < sizeof(struct tunable_header_cached))\n+    return NULL;\n+\n+  thc = (struct tunable_header_cached *)\n+    ext.sections[cache_extension_tag_tunables].base;\n+  tec = thc->tunables;\n+  count = thc->num_tunables;\n+\n+  if (ext.sections[cache_extension_tag_tunables].base\n+      + ext.sections[cache_extension_tag_tunables].size\n+      < (void *) & tec[count])\n+    return NULL;\n+\n+  return thc;\n+}\ndiff --git a/elf/dl-tunables.c b/elf/dl-tunables.c\nindex 5c65e8b458..20e4056d74 100644\n--- a/elf/dl-tunables.c\n+++ b/elf/dl-tunables.c\n@@ -37,6 +37,7 @@\n \n #define TUNABLES_INTERNAL 1\n #include \"dl-tunables.h\"\n+#include \"tunconf.h\"\n \n static char **\n get_next_env (char **envp, char **name, char **val, char ***prev_envp)\n@@ -302,6 +303,68 @@ __tunables_init (char **envp)\n   if (MALLOC_DEFAULT_THP_PAGESIZE > 0)\n     TUNABLE_SET (glibc, malloc, hugetlb, 1);\n \n+#if defined(SHARED) && defined (USE_LDCONFIG)\n+  const struct tunable_header_cached *thc;\n+  const char *td;\n+\n+  thc = _dl_load_cache_tunables (&td);\n+  if (thc != NULL)\n+    {\n+      for (int t = 0; t < thc->num_tunables; ++ t)\n+\t{\n+\t  const struct tunable_entry_cached *tec = &( thc->tunables[t] );\n+\t  int tid = tec->tunable_id;\n+\t  const char *name = td + tec->name_offset;\n+\t  const char *value = td + tec->value_offset;\n+\n+\t  /* Check that we have the correct tunable, and search by\n+\t     name if needed.  We rely on order of operations here to\n+\t     avoid mis-indexing tunables[].  */\n+\t  if (tid < 0 || tid >= tunables_list_size\n+\t      || strcmp (name, tunable_list[tid].name) != 0)\n+\t    {\n+\t      /* It does not, search by name instead.  */\n+\t      tid = -1;\n+\t      for (int i = 0; i < tunables_list_size; i++)\n+\t\t{\n+\t\t  if (strcmp (name, tunable_list[i].name) == 0)\n+\t\t    {\n+\t\t      tid = i;\n+\t\t      break;\n+\t\t    }\n+\t\t}\n+\t      if (tid == -1)\n+\t\tcontinue;\n+\t    }\n+\t  /* At this point, TID is valid for the tunable we want.  See\n+\t     if the parsed type matches the desired type.  */\n+\n+\t  if (tunable_list[tid].type.type_code == TUNABLE_TYPE_STRING)\n+\t    {\n+\t      /* This is a memory leak but there's no easy way around\n+\t\t it, as the mapping will go away.  */\n+\t      tunable_list[tid].val.strval.str = __strdup (value);\n+\t      tunable_list[tid].val.strval.len = strlen (value);\n+\t    }\n+\t  else\n+\t    {\n+\t      tunable_val_t tval;\n+\t      if (tec->flags & TUNCONF_FLAG_PARSED)\n+\t\t{\n+\t\t  tval.numval = tec->parsed_value;\n+\t\t  do_tunable_update_val (& tunable_list[tid],\n+\t\t\t\t\t &tval, NULL, NULL);\n+\t\t}\n+\t      else\n+\t\t{\n+\t\t  tunable_initialize (& tunable_list[tid],\n+\t\t\t\t      value, strlen (value));\n+\t\t}\n+\t    }\n+\t}\n+    }\n+#endif /* defined(SHARED) && defined (USE_LDCONFIG) */\n+\n   /* Ignore tunables for AT_SECURE programs.  */\n   if (__libc_enable_secure)\n     return;\ndiff --git a/elf/tunconf.h b/elf/tunconf.h\nindex 7578605c5a..9551119167 100644\n--- a/elf/tunconf.h\n+++ b/elf/tunconf.h\n@@ -38,3 +38,6 @@ void parse_tunconf (const char *filename, char *opt_chroot);\n struct tunable_header_cached * get_tunconf_ext (uint32_t str_offset);\n #define TUNCONF_SIZE(thc_p) (sizeof(struct tunable_header_cached)\t\t\\\n \t\t     + thc_p->num_tunables * sizeof (struct tunable_entry_cached))\n+\n+extern const struct tunable_header_cached *\n+_dl_load_cache_tunables (const char **data);\n","prefixes":["v7","3/4"]}