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 Netto X-Patchwork-Id: 80586 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2F2503959C57 for ; Wed, 22 Nov 2023 20:44:29 +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-Google-Smtp-Source: AGHT+IEhNDRqFyjldGI6oBu614mc9oJqsRUKiRTis3D/TME7cuSU/W8DNmzxHDhAsQoN1jVmohAaaA== 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+patchwork=sourceware.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" \