From patchwork Tue Apr 30 19:25:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 793359 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:54f:b0:34d:5089:5a9e with SMTP id b15csp434651wrf; Tue, 30 Apr 2024 12:33:54 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVNO1W5t6W1a4n9ccDeritMVMM3cTON+1jaJ611ROSD85UvGU0TcwWaBpz8+JFNNAmb2mY8xtEw5WG58UbD/r35 X-Google-Smtp-Source: AGHT+IHCDtRWAwO1OmnjU5GobL54v83JBhUCE4sRsv8F/Z703DPYgG5ImoVYNIp7Z3xDepyjnw6g X-Received: by 2002:a05:6214:f0f:b0:696:8f17:2ccb with SMTP id gw15-20020a0562140f0f00b006968f172ccbmr328670qvb.17.1714505634016; Tue, 30 Apr 2024 12:33:54 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714505634; cv=pass; d=google.com; s=arc-20160816; b=C1n+635WBlp7AetqsqH6VMAovA/6gNqCjSgi1g5bEAgIa+ucQ6nsSDondyLDTbWEbB WNM0ezG7oFnglP3AeYO3Vljdl0qhgKjpto4V3monbuKgKPFw7bWwWjJ8pv50uQuhS8TT 30ZyfnRmxFKtvJdBPg5iuKjOGEr1JrI4ATUQxSJOgUeiC0/W4sgUWPeW4p6tPpbh/IQu iYS2b4VbZK5bGefbuqWkJmBi7/zJR05DasD9h5Jg3CuG/YeJRYdC+hFKH7Txg7F0O5LL YJ/n+PD2jmaqXEo3fd56wQsSftkZa6eJKZJVVzOI5iPKlgVnDKQhPGohOTQycJBicvCa k+aw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=sFGLpsj9SY2jBhCIr6HxukXoa+9hkLNBQPPFFnVmwA8=; fh=Fj4D3X8lmeg8caKyS1psvSc6iiuGGH95h/ZziX55t10=; b=h6XP8zZ3wnaVV0FdsDI3OYMhiibjzUK2xazR4CymYlt7lfOsZqArVS9wG1gn1RpSJZ PK86KLkDlftPb/5ZULuUB9kraif2w6kAq6mOfv1dVztmDkKt6l0bbNqnYHXNvLcLiyPZ Rkmy4LCpSm5DvABnurBG3RAjruvRx7XFX14SDX3+NdRdaL71ddS5KIcuGBGj+7ILEMn4 RSrmi3fc3La9VaPfAIff+jXLFEuiFUWUyOHh6+S3oZYYdqP3GObz86/h3x9ZfF375UMx AHn6ijNl52qPQJhM53pkOAr2LbyA1PlxEvtYFfmZ8jTJRc6eiD4Zbbt1Q8oQ9bEwHdIN L+WA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LbUS+Xoz; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id jn6-20020ad45de6000000b006a0ac2a2463si10974080qvb.449.2024.04.30.12.33.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 12:33:53 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LbUS+Xoz; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 998D03858429 for ; Tue, 30 Apr 2024 19:33:53 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oa1-x29.google.com (mail-oa1-x29.google.com [IPv6:2001:4860:4864:20::29]) by sourceware.org (Postfix) with ESMTPS id 50B72385842C for ; Tue, 30 Apr 2024 19:32:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 50B72385842C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 50B72385842C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:4860:4864:20::29 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714505577; cv=none; b=lg5qNFGd4Yr+T3snEOsJ4N6QGhGdI4CDoEtLF9tNWexWXf5q/JZ9BZH+WPjTKP3fE7+gAg7lFxE7LqR14Fd6h/EudC5m4Ec0426r4Dk4c5pk74gPGNJ5HDS/L60aQrEoQmD9VS8tucsjjDOW0WIzPy96JiBbj32ktc1XTgFYVV4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714505577; c=relaxed/simple; bh=+4DqfOn4hKsm4Av6t01QQbtNi9B67WnvXnQH5sTGuPw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=XgkRMKdwdmXxiealBmtB+xCzcqU99Sjqbp1Cqe/WiJuLMbD2SNpPTVdMKHPpyqBs9Icg7gRrMkhAJ4PihoputOjIfnlJ6jpxRXk5RNXGf++wp+cEyCJC/+StjN3eRwkHbmi0vBSsOxL3Vy+yGfYuOW3i3ODdxdRa9Ou0Vx2Oo4M= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-oa1-x29.google.com with SMTP id 586e51a60fabf-22ed075a629so2331701fac.3 for ; Tue, 30 Apr 2024 12:32:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1714505574; x=1715110374; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=sFGLpsj9SY2jBhCIr6HxukXoa+9hkLNBQPPFFnVmwA8=; b=LbUS+XoziUsxzOCsyJGzc7hZqjQLccAHry4nl3vHoMeSCxTrzD0UElkh+dP09IyPw+ 7xmgGwoe1SIzVUtQGTlrUiRmxHPc+N3ceh8yoeSRip3fUCBvnZsclgmpMl1ODhgmcWL/ m6w6vTr9RzfMfR84++TLku3jI/Ia/cBvWkwSzYQeqRyk6TWPTQoCVpbLhShnm8xvBhVC O8uWkKI7YkgLwOxnXedD5D0MjE+jAnD3f33AkGnVqx2p3w2un89gHamMhuP/yVN7SJff +d6NYv9o6ID3+luNDBTmRahSe/qs2Mg4+SfPTA5qKH4UnWHw+v98fLFwsAfYVxYHwhJe B0KA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714505574; x=1715110374; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sFGLpsj9SY2jBhCIr6HxukXoa+9hkLNBQPPFFnVmwA8=; b=cWoppHmBkbaj8Yxx651MIA1sxfcdB3Kgr+y9gXyM3Qf7tgys4ArqMg1gITZO2drld3 /SMz+0acLYd9G5u5dgpkhKzorr7EBhVvNUApqv+YZMRunikxxH1uyGx9I0DtYHLquGgg /7lFJumWyFw2QB9xdTTLcCW/S3GyR+HL3x8TCZiiJXpbdmTTGPqELV2blcYKUNwcBg6b koDGBPiV31xQTo5FZ1Zs56S94/P8MG1jATzeS7q6vhoBKxThKyxKPGRF2n9mDkNG+sZW +05PmCYqp/WfVMfBlQlZAUd3RXT3FC8l72kT4nBm6+fCrOBytuakBSCCd88b74tJ2VUH JL7g== X-Gm-Message-State: AOJu0Yyn26jC6qySg3sQwrzNHsE9l++7qvkddhY7I0XQOEGIMuFV6Ben v5RY0juaYf+pRF3kUO+Rz3rC8vYJDyXg/ncSvZS44EzVdtV7L1t0iErqmAvcjk+5Zf1lVuygcUj 9 X-Received: by 2002:a05:6870:a3c5:b0:239:c163:a400 with SMTP id h5-20020a056870a3c500b00239c163a400mr257969oak.29.1714505573976; Tue, 30 Apr 2024 12:32:53 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c1:e3c5:c9b5:f382:64ea:c32b]) by smtp.gmail.com with ESMTPSA id gr6-20020a056a004d0600b006ed1ea5219csm21449143pfb.130.2024.04.30.12.32.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 12:32:53 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Joe Simmons-Talbott , Siddhesh Poyarekar Subject: [PATCH 2/4] elf: Remove glibc.rtld.enable_secure check from parse_tunables_string Date: Tue, 30 Apr 2024 16:25:03 -0300 Message-ID: <20240430192739.1032549-3-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240430192739.1032549-1-adhemerval.zanella@linaro.org> References: <20240430192739.1032549-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.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+patch=linaro.org@sourceware.org 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 --- elf/dl-tunables.c | 58 +++++++++++++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 20 deletions(-) diff --git a/elf/dl-tunables.c b/elf/dl-tunables.c index 1db80e0f92..63cf8c7ab5 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; } } @@ -242,6 +239,16 @@ parse_tunables_string (const char *valstring, struct tunable_toset_t *tunables) return ntunables; } +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) { @@ -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]); } }