From patchwork Tue Mar 17 01:39:18 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: DJ Delorie X-Patchwork-Id: 131848 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 2D5404C3187E for ; Tue, 17 Mar 2026 01:41:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2D5404C3187E Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=EOYCfpSo X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 3C4664B0A6F8 for ; Tue, 17 Mar 2026 01:39:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3C4664B0A6F8 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 3C4664B0A6F8 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1773711567; cv=none; b=K3t2u7pLR6Y9x/ERXVEZpvu4gQF1qyiw5n+Bb6yokNDF6Pp5nJOOBQJutFbgldc7ZPL91us0B6GiOT7jlt7i0gU3zlXEXPXouX65gWZ0xf2a6faOKIUJ8Gh5O024khDR8gJiJc5EryYs1CUS4iLneQweYtNKA66gZSWXU4bXp30= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1773711567; c=relaxed/simple; bh=VBqJvG5fOdQzBCp/HF0+JccdeuVOU6oqGdgKaccUIbQ=; h=DKIM-Signature:Date:Message-Id:From:To:Subject; b=JfuLh9ZTNRHl+ILDIil93bxPm2GQC/1FekrYPozRiKXKGPJ/aHcth0CGJIxqxIFuV6LDL6xNDHc7IrOudTPSelblQxINiEdZmPl7lhxRqdqG41JFc1I4JrHyLsuDBJbLEIQEBTDD2Xm42U92Ua56kZAU/+02CN59Aam4KPjMhdE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3C4664B0A6F8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1773711566; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:content-type:content-type; bh=vKoPxA8vIVtnH2ekOlkJuVHBHPZrcW8Tcuj78sjW+fU=; b=EOYCfpSoV+t/Huwz0uMQ9Kx7y67enLHGJxn3TRnf4kCnCH6fqLGzHMTUcuNIZdcC9okQOY 24I3SbAerhZqK/su/zhUpGYLcoEjrL4RHwApWisVqME0v3STrsBlvkc3Z73cq0u/IoUm0z jL2c4Bl5EDW/2C2lacc4HFxH+jALKeM= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-191-eh9QBVglNPCqJEk3hH56Iw-1; Mon, 16 Mar 2026 21:39:21 -0400 X-MC-Unique: eh9QBVglNPCqJEk3hH56Iw-1 X-Mimecast-MFC-AGG-ID: eh9QBVglNPCqJEk3hH56Iw_1773711560 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B234B19560A6 for ; Tue, 17 Mar 2026 01:39:20 +0000 (UTC) Received: from greed.delorie.com (unknown [10.22.88.83]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 53CEB1800361 for ; Tue, 17 Mar 2026 01:39:20 +0000 (UTC) Received: from greed.delorie.com.redhat.com (localhost [127.0.0.1]) by greed.delorie.com (8.16.1/8.16.1) with ESMTP id 62H1dIxd1583425 for ; Mon, 16 Mar 2026 21:39:18 -0400 Date: Mon, 16 Mar 2026 21:39:18 -0400 Message-Id: From: DJ Delorie To: libc-alpha@sourceware.org Subject: [PATCH v6 3/4] Add system-wide tunables: Apply tunables part X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: kQc3rwpC6yDzbGR6-cHuvCVD3rzKCkGuy6-pcPpAxAo_1773711560 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-9.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_PASS, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org Load ld.so.cache and fetch the tunables extension. Apply those tunables to the current program. We do not yet apply security policies. --- elf/dl-cache.c | 25 +++++++++++++++++++ elf/dl-tunables.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++ elf/tunconf.h | 3 +++ 3 files changed, 91 insertions(+) diff --git a/elf/dl-cache.c b/elf/dl-cache.c index aa8a2c6a88..539bf38905 100644 --- a/elf/dl-cache.c +++ b/elf/dl-cache.c @@ -27,6 +27,7 @@ #include #include #include +#include "tunconf.h" /* This is the starting address and the size of the mmap()ed file. */ static struct cache_file *cache; @@ -606,3 +607,27 @@ _dl_unload_cache (void) now. */ } #endif + +const struct tunable_header_cached * +_dl_load_cache_tunables (const char **data) +{ + struct cache_extension_all_loaded ext; + + /* This loads the cache (temporary). */ + if (_dl_check_ldsocache_needs_loading ()) + _dl_maybe_load_ldsocache (); + + if (cache_new) + *data = (const char *) cache_new; + else + return NULL; + + if (!cache_extension_load (cache_new, cache, cachesize, &ext)) + return NULL; + + /* Validate length/contents here. */ + if (ext.sections[cache_extension_tag_tunables].size + < sizeof(struct tunable_header_cached)) + return NULL; + return ext.sections[cache_extension_tag_tunables].base; +} diff --git a/elf/dl-tunables.c b/elf/dl-tunables.c index bdb1de4ceb..29fcd4504b 100644 --- a/elf/dl-tunables.c +++ b/elf/dl-tunables.c @@ -36,6 +36,7 @@ #define TUNABLES_INTERNAL 1 #include "dl-tunables.h" +#include "tunconf.h" static char ** get_next_env (char **envp, char **name, char **val, char ***prev_envp) @@ -296,6 +297,68 @@ __tunables_init (char **envp) char *envval = NULL; char **prev_envp = envp; +#if defined(SHARED) && defined (USE_LDCONFIG) + const struct tunable_header_cached *thc; + const char *td; + + thc = _dl_load_cache_tunables (&td); + if (thc != NULL) + { + for (int t = 0; t < thc->num_tunables; ++ t) + { + const struct tunable_entry_cached *tec = &( thc->tunables[t] ); + int tid = tec->tunable_id; + const char *name = td + tec->name_offset; + const char *value = td + tec->value_offset; + + /* Check that we have the correct tunable, and search by + name if needed. We rely on order of operations here to + avoid mis-indexing tunables[]. */ + if (tid < 0 || tid >= tunables_list_size + || strcmp (name, tunable_list[tid].name) != 0) + { + /* It does not, search by name instead. */ + tid = -1; + for (int i = 0; i < tunables_list_size; i++) + { + if (strcmp (name, tunable_list[i].name) == 0) + { + tid = i; + break; + } + } + if (tid == -1) + continue; + } + /* At this point, TID is valid for the tunable we want. See + if the parsed type matches the desired type. */ + + if (tunable_list[tid].type.type_code == TUNABLE_TYPE_STRING) + { + /* This is a memory leak but there's no easy way around + it, as the mapping will go away. */ + tunable_list[tid].val.strval.str = __strdup (value); + tunable_list[tid].val.strval.len = strlen (value); + } + else + { + tunable_val_t tval; + if (tec->flags & TUNCONF_FLAG_PARSED) + { + tval.numval = tec->parsed_value; + do_tunable_update_val (& tunable_list[tid], + &tval, NULL, NULL); + } + else + { + tunable_initialize (& tunable_list[tid], + value, strlen (value)); + } + } + } + } +#endif /* defined(SHARED) && defined (USE_LDCONFIG) */ + /* Ignore tunables for AT_SECURE programs. */ if (__libc_enable_secure) return; diff --git a/elf/tunconf.h b/elf/tunconf.h index 7578605c5a..9551119167 100644 --- a/elf/tunconf.h +++ b/elf/tunconf.h @@ -38,3 +38,6 @@ void parse_tunconf (const char *filename, char *opt_chroot); struct tunable_header_cached * get_tunconf_ext (uint32_t str_offset); #define TUNCONF_SIZE(thc_p) (sizeof(struct tunable_header_cached) \ + thc_p->num_tunables * sizeof (struct tunable_entry_cached)) + +extern const struct tunable_header_cached * +_dl_load_cache_tunables (const char **data);