From patchwork Wed Nov 22 20:43:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 746046 Delivered-To: patch@linaro.org Received: by 2002:a5d:6706:0:b0:32d:baff:b0ca with SMTP id o6csp533719wru; Wed, 22 Nov 2023 12:48:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IFV5n63Ohea33IpnBzXxpal4OaeJRRQtWBbnahbCHLFp6hESR513/FEWWnM7S1uqDlh67Zf X-Received: by 2002:a05:687c:218d:b0:1e9:b879:a8e0 with SMTP id yl13-20020a05687c218d00b001e9b879a8e0mr3843194oab.16.1700686096488; Wed, 22 Nov 2023 12:48:16 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1700686096; cv=pass; d=google.com; s=arc-20160816; b=p9UVB3eVGIIBX4DTDPOBLj6O9Je//9ishpMG4fJD75//4xR0eDlx31YbCbtVo/ANMQ PLL9yTGVQpvW2H5VueugVQIcoGDkuDWPL6kanSQRcudhmZh9uyJQdwbMR7vCEQYSormP tYVrkFn2VeGfQKPrSfkKnZ+eN06JnftTDtxdgo8ptdeGuuexiWqPZubAZslvDIdvs2V4 PJlX79nzCXP5CFDxaB/wyF8UbtSEBRb87t2BtMiNNEgLey0IN87MhpYOFDCocxm/uYCZ RW7QAmn+sYFHP7Vf1LWuLN4smgD7hDBv2hpbbSdAPfYXNyuV289iazsp0OMoQD58Tc02 FZbw== 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=K3GtaSLTDXOT37xceyqZVCCpTNpiFHlPuyh3xrw7DQM1waGuKJzHKuxFP5OhB+4/ow 78rBcHF8OHWUxbt7Y2m51h85/zDp7TN/YqtpZquIKUFlLYnlY+LTVJYEF7M2KBPIusD0 S9ymrMU1I5eAfI8eAWuZJ3rb0dwaivh7EsDtbcpb3fpYTVXIPzbGAAY9Vy5/uU0Um3Q2 yCv48VVKPGKhkUccHYKDjevPGt1DYaaVXiuYckuStXV57AondR4CzxSabxSdSiDyH8E6 eq4paA4MBU69/L2DT1whauXeCQX+NOold53FpxVix8x9vw8yE6oG9sNIuYFjwQnoehMx sjnQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Chz9j7jU; 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 o13-20020a05622a008d00b004237346b2e2si247900qtw.474.2023.11.22.12.48.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 12:48:16 -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=Chz9j7jU; 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 42BDD3952537 for ; Wed, 22 Nov 2023 20:44:22 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by sourceware.org (Postfix) with ESMTPS id 2E354385EC55 for ; Wed, 22 Nov 2023 20:43:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2E354385EC55 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 2E354385EC55 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::42d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700685835; cv=none; b=Wl7x2p0R/jSi7BhTLgG2+dpDd817MTxf4iQ05gTnI+awXbuPjOY+6XTSKKOjHm3EGdGWKUdymmErEBRWkBkgWaKkc7qEmiU43VE4Yzd6VWsvvzMonXDqhZOIPkOuOOJsSQoSnlqemWXVYqSED7MxalPs4UzIfZNYjPKMI3dDw+g= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700685835; c=relaxed/simple; bh=bi6191wWt6vf3zE6sLhEOBKmtK8k13IzBrC/l97nbjQ=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=Cilkjn5bgw+wfuvYGl6ridAQe6M1hisboA5b4RS4OROXxU7ORgHEbUpnyrNpZWpA5IjQjsFH2gMB9p6FQLGVAnJLL3LpCidS8lFwA8uDtrH3WSwyAP3H7+ZH52KuxMNMdhYIV36d0jyKpiXn/EXNibO0OGlEmOooI8Hr2rxlod0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-6c4eb5fda3cso220590b3a.2 for ; Wed, 22 Nov 2023 12:43:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1700685822; x=1701290622; 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=Chz9j7jUoyjWIUyLuG3IBiZbvoytmbRiecG3QJu+jC7hZJ+/FwoFMVQ9Q9ZU/yVZcX alJ4J38gohCTXcogJS2AFZQfClezir61/vi6lOhus3a+BqgX9KMYjTEHBHzrak1RNUvH gLmDW6MJt5OOcmwaGXp8dHOPZLsUaMN25pga2HP2N5nG+yJWcFD7snoFJ+r+USI7IwwD soTyKi2odrD2WNTz4Tu2qxQi+JIbxq8GSVNIA/WAnN0EqaGIEyG5Q+8SYarUfv0iurLq JGx3suVhmuASYuKXTfyxnR/2AFMPvkfK9sEGZHeSn2mpuM6300D4TMvp8iwMIxUtVs9X WEew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700685822; x=1701290622; 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=kyD49O8C7fcDmLIJqZ39mLnCmcSooyq/SWXBO2H9B43hElvXmwPPxVfGTIa0qvjjlr 4oK9HGQolip6PSxnMJmYAS5dH991KXOjGpKUb48iekXoO1eh9V/VED/lJWwgFxrn8/9m k/Bm0zQi6pnw1MdVc+9eYnti8brDZ5N6xG2WEmNtyOhk1c5rT6ZghR/mr+CouoIdDqOt 97T7LW6Mrq+hageVyM0Vkfljw+lzWLTZ94Tt+tAKG+mDcaI/3IGOaUAcaPOpgdFXpEL1 j1c5apaAr6sqi1pCHnVtG/bf/rbnWboidq/0dK4BP3nbhfTwROskyfMavUKWVrvpJyIS HNJA== X-Gm-Message-State: AOJu0Yw+arAPwQ8nSrGN79X2JNplIp9iHxexFUvTRfmLiD4TkVZuLfHz 2yZ6JWlOdBoVeCucSnFXfc2P0GIH+AzV1IYfoFfsJA== X-Received: by 2002:a05:6a20:1456:b0:18a:f462:5d3c with SMTP id a22-20020a056a20145600b0018af4625d3cmr4277591pzi.12.1700685822497; Wed, 22 Nov 2023 12:43:42 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:94e:ee04:b0d3:203c:7e3]) by smtp.gmail.com with ESMTPSA id ei45-20020a056a0080ed00b006cb6119f516sm138389pfb.163.2023.11.22.12.43.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 12:43:42 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org, siddhesh@sourceware.org Subject: [PATCH v5 4/5] elf: Ignore LD_BIND_NOW and LD_BIND_NOT for setuid binaries Date: Wed, 22 Nov 2023 17:43:24 -0300 Message-Id: <20231122204325.4058222-5-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231122204325.4058222-1-adhemerval.zanella@linaro.org> References: <20231122204325.4058222-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=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 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" \