From patchwork Wed Nov 22 12:36:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 746023 Delivered-To: patch@linaro.org Received: by 2002:a5d:6706:0:b0:32d:baff:b0ca with SMTP id o6csp273564wru; Wed, 22 Nov 2023 04:36:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IFFyrvDHEFhmUtRcCTNloxy5++e+uaeS86v97xCHy1xoyFvg0V2Za/uZ3wtypOm9oah24kO X-Received: by 2002:a05:622a:64e:b0:418:11ab:1bf7 with SMTP id a14-20020a05622a064e00b0041811ab1bf7mr3293784qtb.30.1700656587675; Wed, 22 Nov 2023 04:36:27 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1700656587; cv=pass; d=google.com; s=arc-20160816; b=agCIDCM2vr2kl4hqnXSOq9Lcqgldj6wgdkXa9zfpVLP+zjnE/swYYmPYVFDWtqYtuL TqJgmNACz1Ml6Jq6zy27vNQzUzTl9qO+14G/RbSKE8DJvWEwZPo3OWm+VVUgaou8QPod LnzoTb+PLzKFx3DCzkzmTROeEi2tbtZuw5Ha3eI6nF+BJ+lFheg9F1QE31BByw+G2jae gz2ABVUzj21j0I3J/jln2ky7iVd5SS8qnkfOssM+I4tdrXSc7vtwDLzKnKCh7Q038nSt RnjEmuaW3OidHm+VAKxjLhMTdqCAeqJqYJdRVglQsOd7ruh6RmW0M4ZoYVVO4mIS920R XaEA== 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:to:from :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=faHuK8MJzR/AXsZ8DcQ0yPd0/TPrcer3vn58v0ETYa8=; fh=Eoh12rOA3G9+1wWUpSCqABE4OFO6OiQ5dhxZkiORJq4=; b=gsTREwLMiUrlA80aLCXsUEFVm9fpgwmLvtnfERCY2448+vDpIwN0CWlBhppcXrD4Y4 MytHcnG+QPDNURIkpkyvU4obLFgfTr0lKkxTKXKZulPHMWedG+XH2YarH1dlBFKLIWXb rtp6DgBpDOhj/5BtE3zeE1q7GXVR2r8ktNZhoFL/ywAEfi7HljePHEZZHUFXKdu6eYAt 47oTSYI2w8uFxAVAkGLaYofdwPbzI07JmZsRxmEgunkbjWT9si0AshC2i9I70AkYQhsw NPkYz5f2zsAUUsYEL4RSyS1m4qsxOZl0ATDHrmH5kmSnrGbaaMgQRP/to7Ib9ROOJDKe vi+A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=s8jMDLqw; 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 gd26-20020a05622a5c1a00b00423761cea07si2269187qtb.628.2023.11.22.04.36.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 04:36:27 -0800 (PST) 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=s8jMDLqw; 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 552BA3857719 for ; Wed, 22 Nov 2023 12:36:27 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by sourceware.org (Postfix) with ESMTPS id 383173858409 for ; Wed, 22 Nov 2023 12:36:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 383173858409 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 383173858409 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::635 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700656576; cv=none; b=wP5ZuYFxqjRmxS0M7wU9yUPLQ9owhfjk0RY8bE+aGhU4RLUtnZxqXQyjmlJbhgGYRdK/JvmE82bzzWPS7Wr8zeKAT7hkubnfnjXC2oRKBBIMjnQlECYYSrj4GZ6KhVapLFhKe0ubhLehEd5JXapXb2aeDZdwbgxIYnNWlkV2iiQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700656576; c=relaxed/simple; bh=bi6191wWt6vf3zE6sLhEOBKmtK8k13IzBrC/l97nbjQ=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=MswaRoZOw9JKWoe0Lyci+QROtTsMBPq5rErc9r27jAHWz9jQEfssvQNVUgd2HgetMZWIb8v1d2anHeWZqewZzkL4ZaEOt/yYmqBbnKfdtA+qGtmk0WQKGEmDErANNwKv4ipDFjpGoANayKwTQApQLmZKR01CjIqaLtYItBXi7Gs= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1ce5e65ba37so6121745ad.1 for ; Wed, 22 Nov 2023 04:36:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1700656574; x=1701261374; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=faHuK8MJzR/AXsZ8DcQ0yPd0/TPrcer3vn58v0ETYa8=; b=s8jMDLqwHH04WNRhDcajU3gYKh84IZrTwinDGiwj77UwbZEJSliKoqjettwvDebybw ro8kvZaCKnkkDjWBSqqDunK5ehvkRYzDwXMoVL8l5NG4Rv3ysTwbOMI6d1T1jwI5rdFk 6eR3wrsGglZ2SIapNHbxorKV9kaVYXI1VwBOzMu02RDFKHMKcMDRLuE8+DZNnZUPc0fl tv3vZURCmDp203adGF3eHe0LBYEELekvdEthcUz/nHQ6ZGSAWUPGf7GyiTPflbvvsJaK BgKHzSTly/i9X6HPINHRmJ8o7aAnf1Nhge+74F4LgpJKzFWfU9oYg2FxiJRGAUdYczQU KFiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700656574; x=1701261374; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=faHuK8MJzR/AXsZ8DcQ0yPd0/TPrcer3vn58v0ETYa8=; b=atceuh7mrXnfnFfg3iOwsgFVMABR1zN/frrIBLWUZUyGgsg6kZln0TTyTEooxPqTdN BBfDrCjidG2quiIKXqRchFjjthx6pIKlsRybvhH7a30mycAIwf6/8qPykFbXMa5gdLNN KNAQaJXs7HvOBMudKcQRIdSCGNNCBfXIW1KtNpHHZdX7c9rbJRP7kq8LRINQYqpisUIC 0xWU1bU3iqhkHlN/2ATO6+pqnjz1L1zg7tSBbSZ0zZ2KY4qqL3B4dm6oscO+Zh7mqj6P 75u2Ulgy//m/4D2z9eF2SolWK2fsw6mvPnXEm9L5xA38SVZX5JhDRdbWlOAzj7jD8iDO H/Kw== X-Gm-Message-State: AOJu0YxZqLl+qNI1bZi94LJ1y/AH0jU887SIfd1dYM4i31UwnTlzbv2j 1BhwpKQW1rHzh8yKGOb1jP9av/HzMR417RPtIsptKA== X-Received: by 2002:a17:902:ccce:b0:1cd:f823:456d with SMTP id z14-20020a170902ccce00b001cdf823456dmr4128717ple.20.1700656573865; Wed, 22 Nov 2023 04:36:13 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:94e:ee04:b0d3:203c:7e3]) by smtp.gmail.com with ESMTPSA id a4-20020a170902ee8400b001c9d011581dsm9736021pld.164.2023.11.22.04.36.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 04:36:13 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org, siddhesh@sourceware.org Subject: [PATCH v4 3/4] elf: Ignore LD_BIND_NOW and LD_BIND_NOT for setuid binaries Date: Wed, 22 Nov 2023 09:36:00 -0300 Message-Id: <20231122123601.603315-4-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231122123601.603315-1-adhemerval.zanella@linaro.org> References: <20231122123601.603315-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.6 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, T_SCC_BODY_TEXT_LINE 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 To avoid any environment variable to change setuid binaries semantics. Checked on x86_64-linux-gnu. Reviewed-by: Siddhesh Poyarekar --- elf/rtld.c | 8 ++++++-- elf/tst-env-setuid.c | 4 ++-- sysdeps/generic/unsecvars.h | 2 ++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/elf/rtld.c b/elf/rtld.c index d1017ba9e9..cfba30eba0 100644 --- a/elf/rtld.c +++ b/elf/rtld.c @@ -2598,12 +2598,14 @@ process_envvars (struct dl_main_state *state) case 8: /* Do we bind early? */ - if (memcmp (envline, "BIND_NOW", 8) == 0) + if (!__libc_enable_secure + && memcmp (envline, "BIND_NOW", 8) == 0) { GLRO(dl_lazy) = envline[9] == '\0'; break; } - if (memcmp (envline, "BIND_NOT", 8) == 0) + if (! __libc_enable_secure + && memcmp (envline, "BIND_NOT", 8) == 0) GLRO(dl_bind_not) = envline[9] != '\0'; break; @@ -2680,6 +2682,8 @@ process_envvars (struct dl_main_state *state) if (GLRO(dl_debug_mask) != 0 || GLRO(dl_verbose) != 0 + || GLRO(dl_lazy) != 1 + || GLRO(dl_bind_not) != 0 || state->mode != rtld_mode_normal || state->version_info) _exit (5); diff --git a/elf/tst-env-setuid.c b/elf/tst-env-setuid.c index b1d64ac085..9fa591a136 100644 --- a/elf/tst-env-setuid.c +++ b/elf/tst-env-setuid.c @@ -63,12 +63,12 @@ static const struct envvar_t filtered_envvars[] = { "LD_DEBUG_OUTPUT", "/tmp/some-file" }, { "LD_WARN", FILTERED_VALUE }, { "LD_VERBOSE", FILTERED_VALUE }, + { "LD_BIND_NOW", "0" }, + { "LD_BIND_NOT", "1" }, }; static const struct envvar_t unfiltered_envvars[] = { - { "LD_BIND_NOW", "0" }, - { "LD_BIND_NOT", "1" }, /* Non longer supported option. */ { "LD_ASSUME_KERNEL", UNFILTERED_VALUE }, }; diff --git a/sysdeps/generic/unsecvars.h b/sysdeps/generic/unsecvars.h index 8975df4a14..f1724efe0f 100644 --- a/sysdeps/generic/unsecvars.h +++ b/sysdeps/generic/unsecvars.h @@ -7,6 +7,8 @@ "GLIBC_TUNABLES\0" \ "HOSTALIASES\0" \ "LD_AUDIT\0" \ + "LD_BIND_NOT\0" \ + "LD_BIND_NOW\0" \ "LD_DEBUG\0" \ "LD_DEBUG_OUTPUT\0" \ "LD_DYNAMIC_WEAK\0" \