From patchwork Tue Oct 17 13:05:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 734393 Delivered-To: patch@linaro.org Received: by 2002:adf:f0cd:0:b0:32d:baff:b0ca with SMTP id x13csp469606wro; Tue, 17 Oct 2023 06:08:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEXMaTtklT0jwK77c/OsktDiYDh0RwBRIls4iXUYWfZejR1vx7MD8PlXUIKxXNFIxX80M1V X-Received: by 2002:a81:5d43:0:b0:592:5def:5c0d with SMTP id r64-20020a815d43000000b005925def5c0dmr2335448ywb.45.1697548102409; Tue, 17 Oct 2023 06:08:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697548102; cv=pass; d=google.com; s=arc-20160816; b=JaKmlZ9PoUQB5ZCo91c/g2q5lPxazESDfJ24cK4180seAIGZ5NAmZeFI/rFmvSNQE8 XTjS+CUeRJVmxdW2d2M7kRROFueSjGtWVmzaYGqoKKI7TjOsQp30eHRG19ZqD7z0WIG1 LzY3pGqrwkmvNRHGYtrZU8eoA96evFOQaNCy1zxE2NKyKujVAVRR1zFu5n3lzid7J6sG SxA/h6On24hfw8XJD8UET2MMbfY9b10YCmQmxTYAPUrz/CLxvXHQYrEkB4VWo02uyVnZ cjeykUlHh+HBwRyhKnze3Egr8ZRpPRE8HtqpWQU+LaT/T94yvBTxodXIMsRkinqZVK7N 0pow== 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=+4GDbFUmw1Mr9IXcIz740H4haKsPlYiuLewlNhU0zqc=; fh=+FUb54tScwW7D3lvWhZcQBi30wyNNn2DusdH7ahfqKk=; b=aJNnCo/UvYTv5emBvMZWOA6ZocwLhROC0L6OB3b415ZueCX2MGal1Sw46K0Vmwwhup sZIMXT9Vpqbju+HKVDfxOaVvm6gQCkQskRM4NiXFyQPTUdAW15c5KCN53gHUo8n7oWat xTH4cJd7bv2CBa+SrUI0l27+I0vRAoPoL5Lp65tfYktizN+SIouWFpPd9nW37P3Ntbpw 5F364HxCjsh6riLf9/IS1g/6UpeFoYU3beoASHrOV66mS6mQ8zAT29cSHx3Fx/KkJ1jU D9nKIhCIgWtPYkpD7jPL0b+Y8gPsmi+t0piU0j+YD5nqkXvKGOuFQ+gUJ4QT04c/To2n AgrQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hHp6hJ6D; 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 v2-20020a056102226200b00450f9ec172esi109156vsd.185.2023.10.17.06.08.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 06:08:22 -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=hHp6hJ6D; 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 70965385C6F7 for ; Tue, 17 Oct 2023 13:08:01 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by sourceware.org (Postfix) with ESMTPS id 90727385276F for ; Tue, 17 Oct 2023 13:06:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 90727385276F 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 90727385276F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::535 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697548014; cv=none; b=dcbqOZzQSjuPhzjAy9gIpVtxTdCSk0U4Qy6cyK7/Q3yuPG709BUCwoC/8l77rfSdovIOEE2RgLr4cjyissXRCXIGUuoeM64lxvp6dahSC2xlEtuTPenPd90JK1iazrknPR+azrJ0+M+LD8bMjm8MOD0gUTaSxs1SmoKvkjeNquo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697548014; c=relaxed/simple; bh=Rk1BxMlwimWl0kYqwXPVTuQKRCggvqczoUCnIMXiGsc=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=N4jtXDjVnsORYnEfHgop2xrdqD+W1KgPETlTTc7PuPc+eAOFDRbZdYvHkUO/Jb8N0mUNkFpyhugOHIWu2krEB22Lfd+tPB9+7QbUr6WdgFj5Vt8RPJP8ctPT1OiKmnCR+YCxkbFuYior7vWqIr75DnuAwtP2sMgiH/+nZvIFF+4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pg1-x535.google.com with SMTP id 41be03b00d2f7-5ab53b230f1so2532774a12.3 for ; Tue, 17 Oct 2023 06:06:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697548012; x=1698152812; 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=+4GDbFUmw1Mr9IXcIz740H4haKsPlYiuLewlNhU0zqc=; b=hHp6hJ6DjIefpCP7rA3zn0vrrC38dq5PCkUXidZDFwvLl3s2HDFJ/dTVuQIaBv9vKv JD35bcF+NqqZwdbsCJJV7R+0UG9cOorpLufcB+PD+jGBbNlN4r3noNhGBxdRJ4zH3cz/ WQTHYvPngP9TNCpWliW2q5QYdMjxruSXVUy4jnOwFHbKMgookWDyPjWIZJYcUqN9WKqY pDf8dauf1QBqOzeK3gfoU9ithqArzQKK4e8mn63xvBKoQUoBN+Ls2lf7wxwARuiFvIOs zh4EdefSCBraHD+J4/y6rBtpvsNzF2WHXkRbU1/vmDVCTMHKwLlohvBUcDEMWWO8wW3X AdYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697548012; x=1698152812; 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=+4GDbFUmw1Mr9IXcIz740H4haKsPlYiuLewlNhU0zqc=; b=TNRk45+QsBTVAanmsH96viatM+7mvrwScAUlgwEz2m/r1f2vhNN32DR+YN95RY2E+3 qUmxdXevfZatVZ+v4dzOD5objAT+1ZCWqYLulMzAglGC1ZBCNdI9Mdy4lnmr3Cm19oba NjOBlZ74G2dnLUSw0byMxKEUIB9TIKqNHuNN/rqBF2yALSBRIMoiy1MWRNnmAFNPSozH IXkh8oTZ1Dg4gZh5VX+g77N2uJWoCWYwiEWz+FiJBrTWxYPFB6Wsg3Z867I1W+A/SjJu GxJRkn6O3hUmxGepacohLuFz6z71VLcx4r6p3KBEX8C4gosODXt+xe0Z46LNc6c9NNOn LiWA== X-Gm-Message-State: AOJu0YylFmFsxlf3O4WodlskMbT2LO0kUy+73L8uY/5MWY9vk8TSmrqX wQRjltnVrw1RRrbZlGATX5+b5HvyhLuMbPjVFfRZ2w== X-Received: by 2002:a05:6a20:7494:b0:161:2bed:6b3a with SMTP id p20-20020a056a20749400b001612bed6b3amr1875315pzd.17.1697548011879; Tue, 17 Oct 2023 06:06:51 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c3:7f2e:11d:92b4:4d78:4197]) by smtp.gmail.com with ESMTPSA id l28-20020a635b5c000000b0056b6d1ac949sm1309788pgm.13.2023.10.17.06.06.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 06:06:51 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org, Siddhesh Poyarekar Subject: [PATCH v2 18/19] elf: Ignore LD_BIND_NOW and LD_BIND_NOT for setuid binaries Date: Tue, 17 Oct 2023 10:05:25 -0300 Message-Id: <20231017130526.2216827-19-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231017130526.2216827-1-adhemerval.zanella@linaro.org> References: <20231017130526.2216827-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.8 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 To avoid any environment variable to change setuid binaries semantics. Checked on x86_64-linux-gnu. --- 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 dcf213a4cd..eb9613d717 100644 --- a/elf/tst-env-setuid.c +++ b/elf/tst-env-setuid.c @@ -61,12 +61,12 @@ static const struct envvar_t filtered_envvars[] = { "RES_OPTIONS", FILTERED_VALUE }, { "LD_DEBUG", "all" }, { "LD_DEBUG_OUTPUT", "/tmp/some-file" }, + { "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 f7ebed60e5..c71b70ed95 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" \