From patchwork Mon May 6 16:18:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 795023 Delivered-To: patch@linaro.org Received: by 2002:adf:a453:0:b0:34e:ceec:bfcd with SMTP id e19csp1007232wra; Mon, 6 May 2024 09:21:24 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXQWTXzRtp1B9MO2eFOcY5JV7uEvSFywqN28tISxpmlOrruCeznb+DWvueab3H4RKv8wI7vUxwj8fuos6TErH7H X-Google-Smtp-Source: AGHT+IH50JUpHYciRPCYhkZZidjuShk/eDYdG4x6CcA1VTaPhM7idVs7NRaFmTwWcqqvV/GPZ+bW X-Received: by 2002:a05:6102:32c1:b0:47c:1269:600a with SMTP id o1-20020a05610232c100b0047c1269600amr314562vss.13.1715012483861; Mon, 06 May 2024 09:21:23 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715012483; cv=pass; d=google.com; s=arc-20160816; b=B+2YpCBkQz5jln+6k4Me2R86AsI9McyhVViUL6gjJZK+PcB5SKRmm+mg+sNsohGC0Y a4uuxX4KuZ6AomkkIk4AqA5IXmv8Pq3DqxFn5cIHHPxhB2Ou9NxcTB4ApPRlKzVqylLx oILlLI7I8BQvSs6YAH4T3EpFjGwwfQwH6RJui7eRIc4l5rESPxeiRaeT58rWPQdG1FCw C7wHG+DMqHvVKmstIoWf5CkMngmuQh6IRf3WD43vq5FH+wyLjr+BQ/oRI060aRhDgVXT v02cFkDA/UD2Qg5g5JXUIzBGfknWQ/jwgaoKl4460pF4NgqEYLzSEF2791DIWqXepfHl rAFQ== 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=0VNjQcIqE8KEHGE39WjBxjj2g/lBRHQnTlB8w6dGiRu+TwyD++3rGhVXY4N4/TRxa7 P9zZYoj7TBvfLJNCDV0/QxdCvG48Ir4kUXXzPX7SYTnhLOKjo42/XdX4QJVlXR5mXe4L q7U3J4jUzOWOPelB12VQJUcFwLQljtEQhc0Mt3YsXEX0t+AF0+BODIAbBERhFguBe1C/ inldrLS2KWnD6SKC5eOCbgh60DN7cj9onoBAH5IVuMg+mE1o+MPGyzUm8dRd/2ROXpq/ ovrkfYFtYVGigIJIXlqd7/xf2L9picz7xDfuaTwSrROrgE1kkjDIMWaAzAVVRi0VhdRV 343g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Gwikuyu0; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 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. [8.43.85.97]) by mx.google.com with ESMTPS id f19-20020a67ea93000000b0047b88bb9837si1682480vso.793.2024.05.06.09.21.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 09:21:23 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Gwikuyu0; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 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 5D930385841E for ; Mon, 6 May 2024 16:21:23 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by sourceware.org (Postfix) with ESMTPS id B9FA23858D1E for ; Mon, 6 May 2024 16:20:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B9FA23858D1E 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 B9FA23858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::435 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715012411; cv=none; b=f3MjoSJttF0KfTAHilcngJ/HsGii0VnXlxtAqXLjFxnx0M07Nz1Y4kMVk2zmV+2DA9mCfsmkVkC/wlysShSF4WglXBpuvVrjhacZ7ReB2rVpvcsflx0d6AGWGghXzBd3la2eUpidNYWL8R5VxEpYo/tCYhxag+mzrBMnotwdCXg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715012411; c=relaxed/simple; bh=pEMGJzEXOr1M1CokR16EYy+o8E5rQZM7d+ndftfT7AA=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=McRzf7/0K1bA9GDjWR/9Quu5UfUpp+w5/aarWuBYpnO78lXixoF5LYP8+Ig34sLqNMVJ/mj3v7Z4YZoxsIuVbRXfI0aSrF018uBL0vCPElsyo1emzTWqgBTIVQ1BWBVN6GsFQf/Jhojyd0e5ymg6gvaKRDaBAuPYW2PQqBMlC6I= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-6f460e05101so1200160b3a.1 for ; Mon, 06 May 2024 09:20:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1715012408; x=1715617208; 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=Gwikuyu0nIiQU23xHeh3FKR0YtKdan65buoxvFPZsqIF7nyQpVEDIdluQER3FbEfEK clFlHdBKzQhoO+tUzg/c6MyqdhjNLtpg4aekS6nsrZM2VK6J2F3oH8RfCKzgxO9c7lYm vJEad+0Ql5uHIz0aAlPl40w8lZUqEZxqiq2JtHgoRsNn1/7lVzeS+VcHsaBv7GgsfVdO 1fqwDzbaU8PNfqi4+yY5tfuiRTkXWiLcTRbYDYgdOIjF1wIvIuHS2SbzQlpT2JepUkLm 8jfVRsoJAVKmxXkMa/NqnlTQaxpyrYPXUoU/YySNnF5dmc7WJi6odaH+vlBBlmGW5K9d rEaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715012408; x=1715617208; 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=lKA9BS4speDhdcrPhR71isYDy9DyZKaJ0c8efhlo4iPLSV/2zimbguJZw3fmVoeORP XliE0IiLKxD8P9EtFJKdTT8dTrqMADj3o4TT9Bjm0M3GFH4TTnrT/2uBLA4YUM3hMhqg 1ryad/s0mvDH5QshmBegUAUugus3Ha4STKQQTNTyCQ4U+G10dujilFIA/koPJJTpom1S PAOgbbCeETm4zabHj6czjRphA/pE//z4CmHXDxr+u7PX1CN01x1AfJdutgDhTrUUSB+k eNAN1vmxFM/zSV2tJFYBUQS4tbI1+ABRoaYp6as5Czo1W/iB3jXBkeauf6YDBzq34Ctd fF+g== X-Gm-Message-State: AOJu0YwYV6/w9n6M0B1GO6Bl1u81sMEwRSVSD9cC/OIf83UusE/aM+Ul hCuTtpurYtss3HQAv2X1r0mOPi22EewOXVKBIsellTGiK2fKkvB9+FgTuyR9FBA3VBtJsWjA9+5 xbyc= X-Received: by 2002:a05:6a20:1059:b0:1aa:954f:d466 with SMTP id gt25-20020a056a20105900b001aa954fd466mr163344pzc.23.1715012408006; Mon, 06 May 2024 09:20:08 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c2:6e56:fc45:bb45:8b35:9b81]) by smtp.gmail.com with ESMTPSA id ll12-20020a056a00728c00b006ed0b798f1fsm7883347pfb.119.2024.05.06.09.20.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 09:20:07 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Joe Simmons-Talbott , Siddhesh Poyarekar Subject: [PATCH v3 2/4] elf: Remove glibc.rtld.enable_secure check from parse_tunables_string Date: Mon, 6 May 2024 13:18:46 -0300 Message-ID: <20240506161955.1570278-3-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240506161955.1570278-1-adhemerval.zanella@linaro.org> References: <20240506161955.1570278-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=unavailable 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]); } }