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: 1930728 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=FjyX9W3Q; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VVfkJ37NMz20fb for ; Fri, 3 May 2024 02:38:00 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9E9BC384AB4C for ; Thu, 2 May 2024 16:37:58 +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-Google-Smtp-Source: AGHT+IGhYbF+oGBALSBDhuGN7PG7/vpckhi4ImhZLfYx4cSFDuGE82lyfBsk0Ug4B7NAiKB4bYWYMQ== 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+incoming=patchwork.ozlabs.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]); } }