From patchwork Thu May 2 16:35:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 794112 Delivered-To: patch@linaro.org Received: by 2002:adf:a153:0:b0:34d:5089:5a9e with SMTP id r19csp345610wrr; Thu, 2 May 2024 09:37:49 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVS5qjYr038pNyxnrt1jRswn6p1jvEIzdBQebuUgf9+Fuwp5RSeKAuZg5ybMfuihdSicfzZa6bTakYuGOYGDtvH X-Google-Smtp-Source: AGHT+IFruFDl1pWBTnhqmaiL+PF8NvC6V7sdFRx72sPiLi17gN9n7UnKiw87oy0G7i6QnZjQfsJs X-Received: by 2002:a05:620a:13c1:b0:790:f5b3:a186 with SMTP id g1-20020a05620a13c100b00790f5b3a186mr506391qkl.8.1714667869367; Thu, 02 May 2024 09:37:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714667869; cv=pass; d=google.com; s=arc-20160816; b=d5Dnp8XrOIMMBim4ZiidRHOfYSDDnH8pD0aRVGH104iLDHNbr1ctzQq8bIaPTgKMrL UuxMA8PEpFVMIoRQPvMNRGrAvTeU1xBUWJN9gUXnTGMkyxejr0vrS/YuVYmsQierGXJY CQPqP+oto8yyzG2gQ/xPI2QFq6/52tm401mZP+XWuiizXU+6yMzoGeJNFe95nGX6vK3Z iefdkDhlnuLWhzHult8axbuRQ94LS4PrTXjQxIKqam5kUn+S8gH0xkjCvgaXtLcJacQ+ hZ9r/rRDUtYzBInMOBZa03UaLc0xKCFPvZo7c9UUXjLrcfeI7DzUOAyNAtRD2hQXPwW5 V67Q== 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=sGd9zb7IAiLLy2yVbpl8UkwGDSrGWYwhIDZaoLKhuwA=; fh=Fj4D3X8lmeg8caKyS1psvSc6iiuGGH95h/ZziX55t10=; b=szB8bSF0QJRZdB39reJuKnVFad0s6jVSQMVC1ZXFMqCEKKRQSaHZgtu6nDBxN052ME oomqIfRNmvVCp9lrFLonKJFyKNrV9x3tmjq7mPdDjSAW841f0e0QWnzg2a80ryiVqomm T+wUHZDhWHetSamRMgyvqVQtGM1RHorS880UZhxvIZhCFbnIzf4Yo1PRj/YT7dlGY09L ak/obt7Th52pVOILpWSkmxf9RZqCh5ikuSSbshpDVsT0wlKtnd5mFig1cjwViPTa0utz iNiY41yHm1lV2zUeAoihfkFCD2O0Eg1td0mNuvgo2wyU3lP7mumdn1aDo8gxR6Cf9zWe fdjg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FjyX9W3Q; 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 vk42-20020a05620a70ea00b0079068b4760asi1280438qkn.45.2024.05.02.09.37.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 May 2024 09:37:49 -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=FjyX9W3Q; 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 F349C3858408 for ; Thu, 2 May 2024 16:37:48 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by sourceware.org (Postfix) with ESMTPS id B4F7A385840F for ; Thu, 2 May 2024 16:37:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B4F7A385840F 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 B4F7A385840F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::42e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714667856; cv=none; b=K/q1Npia1CSWx43ue/HwTfgcL1K5qkHXgcyGhBzZh2SCWp1S+0lsZd2lbCgvLtsXYOYkezhfVU/TYEICUlIMb32gN0ZVMDcUYjKL7+mONar7Iszk0z+gJRmC011b2Mvyi3yQmfLxrPTfxWnZm9FL+VsPGKE2f7X333KSwaOIcwk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714667856; c=relaxed/simple; bh=pEMGJzEXOr1M1CokR16EYy+o8E5rQZM7d+ndftfT7AA=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=yDfvhwmpHxcpEBQ7uvF7cjp0CyX1E6Hx30p7fAVPfG9OWTjkURXA1MlXLo3kQKUZyKtGftFoqT8DLoDhx9QwTj1B73T4qpgAfCaad4xMb74TR9QLTttNYeP7DTPHuyUjNRwJ2h286TBFTVbIAARInDs/9phdCz+hvKZ759P/wDo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-6f0aeee172dso1514270b3a.1 for ; Thu, 02 May 2024 09:37:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1714667853; x=1715272653; 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=sGd9zb7IAiLLy2yVbpl8UkwGDSrGWYwhIDZaoLKhuwA=; b=FjyX9W3QHRhuUY/54S12Afxtf1n2SX18JUCpOX0dSKKSP6++yYDSGm6YYb0RUVQx8C 36hcxToC8Ef8FPZ3y7yABxqEuSivEkAuHYxNhUD2lh405BvCje7/dO13qeMXdu6H7eqr 6WVt+eJf6+Zb87UV2C3eKbmAvVfig2cK0pHzwV3yEmRe7jHLpGMu6OAtYQ1cxTR4SBUx GE1ZQATVEP6D4jBStQBtIRQQmI2ecqnZBeiKPca3lN4cuFYJoWYdzQWWhyss34yi7JXG zQ16qQxaZw7n6A3RMRZVUvCGj/NcjjZD3GeaLTiKFm7xjoXNtZbGCne1U6FbIG6i3Yqx Y/1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714667853; x=1715272653; 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=sGd9zb7IAiLLy2yVbpl8UkwGDSrGWYwhIDZaoLKhuwA=; b=X22UBuESiLmpVY7G0aUnFf8+g6B4ksz5EY0UY7xOuhKB9AsrcqtgxJmaWbuycKlF8M AZWfWiQFLvOxhL6+W9re9QeVGpoltIOEtIcHOTs5JoVT/oBt+GyOhUZGja1wZw7M5+c8 8NKUGSkTIMbae5ShnnLPZHsfIwJeXzd+rCwCu7OPZ1I1wKgKFECEqJqkIWeY+iUiXfME gTRORBFDlaKBluKCvr1xqsk1MJwk62P7PoX0o97DpN5ZTqtE8XE5FigeGmvq6DrQMwod P6grQVVK/F5+rsmZqgSeEiiMk9DTisTSheEWuuGj1D1x8Gb52dmBs3p2oGap334IDaHG 5RDw== X-Gm-Message-State: AOJu0YxWXnXlCypWXcETp1wohPk88v7CLlXPFB/VZGKLpgBhzN1FGCDO eBVZQ/7PyCIawLOFICW2oNvY2nOyRx/DGh+DwwlF99PB0kUZc8qcn8Jp5aHSWAPZTDHzvKDvsQC u X-Received: by 2002:a05:6a00:1385:b0:6ed:825b:30c0 with SMTP id t5-20020a056a00138500b006ed825b30c0mr4583227pfg.15.1714667853144; Thu, 02 May 2024 09:37:33 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c1:e3c5:e62b:fe17:6851:b93]) by smtp.gmail.com with ESMTPSA id j4-20020a62b604000000b006ecfa91a210sm1439524pff.100.2024.05.02.09.37.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 May 2024 09:37:32 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Joe Simmons-Talbott , Siddhesh Poyarekar Subject: [PATCH v2 2/4] elf: Remove glibc.rtld.enable_secure check from parse_tunables_string Date: Thu, 2 May 2024 13:35:57 -0300 Message-ID: <20240502163716.1107975-3-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240502163716.1107975-1-adhemerval.zanella@linaro.org> References: <20240502163716.1107975-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.5 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]); } }