From patchwork Wed Nov 22 20:43:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 746044 Delivered-To: patch@linaro.org Received: by 2002:a5d:6706:0:b0:32d:baff:b0ca with SMTP id o6csp533334wru; Wed, 22 Nov 2023 12:47:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IH9HPxeExZ1dWiWbO6am8LPsQldL8dpk4X5yY3Mre2johfc1ihZf1KTWcUdXn2XkWiHpS8K X-Received: by 2002:a05:6870:ebc3:b0:1ea:746d:1703 with SMTP id cr3-20020a056870ebc300b001ea746d1703mr4719334oab.7.1700686029955; Wed, 22 Nov 2023 12:47:09 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1700686029; cv=pass; d=google.com; s=arc-20160816; b=GcOdiew+Wc/9hqrwwaYWKaWa3CZkRPv64tMR6tMM8DMg/0CDjf/EpH9S2f/X2Cl3SE +j1XLr/h2mlm0JY4KptIL1gR8fKCyYewQYVtK6JWVTA4wqn4fb1LxNEDJkQZqKgCRd6x YXkZi69atu486VHJXf+cvbIYXRZdf07l2xgltA3Wu9VF25gbR9xYkbOXnz56lRVt31ZJ lr1C3WFejEXf49gmyaVQ+BRCbrWapF+/7gmu1AR1GBNw01qJ1S7Nk2sMi29gkvWAa+9/ IFPNx8INmVqwv7Gzb2AuS4ad4s/lqbsJ4bTq8Z400oNbdKvSHSSHL9C5wfBrlUy2OcUL hI+A== 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=qCGRE8g3Yo7uLVWHXUPnuPKW4mRSbmeSX+GgKu6M4bo=; fh=Eoh12rOA3G9+1wWUpSCqABE4OFO6OiQ5dhxZkiORJq4=; b=LtfKh9kcpWIBQ/4YiywB9xMRRkqsJQPmHN6GVo94BzOY6BocfMrGPihphcl6lKKmjf ykKP+NDAjxeHuKee/hVBFgVtY/SrNlTyJVW5JOHVZrtNrkvSWxKFGhQdFbPbyUBnZClb +uHR0SMxfe0zjbKyP2b+B3Rc1UCc+glwe44t2whjRarqGMnKgv1y44x7aLpFN2CH0Qqp XAXGfVTLtJnZkh8PiSWHtMh5/X51a20eODpv4PA6QD7nIpgpzDlpEl/QaE6AAmxxSfFp YGoIUBHLECA7XHNNl4Ewn5R+JvjH3/2FDASLZPuhrqtMwntTMOykgmg9JMEjcHPstZVP acgQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qPxh1b3e; 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 p1-20020a05622a00c100b00423806a58bfsi275662qtw.30.2023.11.22.12.47.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 12:47:09 -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=qPxh1b3e; 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 2066F3948828 for ; Wed, 22 Nov 2023 20:44:13 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by sourceware.org (Postfix) with ESMTPS id 482C1385829E for ; Wed, 22 Nov 2023 20:43:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 482C1385829E 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 482C1385829E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::42a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700685834; cv=none; b=bvTn8R8JZn97/uuLdcvYvJLvFXc8SKml1rAsEXX50SKidLPoNTDrWBBQcPYzgp57fGWIjQu69New+CmQyElIGLxRf0zGGmFDsulGFLxdOMKPLHHFxlID/Gym2QRBMLhR2eMPeqabNKEvnrJNdfikgvjRydMThyPauJDKJd8Gfk8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700685834; c=relaxed/simple; bh=pnipUWtW/9+iYyWUu/tGomUPc2c4lB5nvX4BL6cRAPM=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=IYG3mu85yI5z7SpMeB3nl+JxFD/5nR3ssNGql/CCZbkgQdP7ZxvnVz2rD5Esp/7dorwXYerYsAelc6X0ht+a39m7GkGQqmKQWPhP1mWaOuKt37Gv+6FMZzAFyhCzBdtRDkZ+oolQlTWFN500tFkwjL8t3OlaqI0KHO0gddb8Pdc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-6bee11456baso234191b3a.1 for ; Wed, 22 Nov 2023 12:43:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1700685816; x=1701290616; 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=qCGRE8g3Yo7uLVWHXUPnuPKW4mRSbmeSX+GgKu6M4bo=; b=qPxh1b3elTCURGxf1bj9sKaSEbwcDASpWJTiARNUshyEqPGJz5ME02N/HESQNa9SAZ 3xQdF+2ZvEqR6gpD/AY4Rp9ZiDbjUlaOzNBvEMPmk62Yi7E3CxMdsZkv2y4VqoawmZeG nd2wA0YQI0ukkgeMu15StzHmWRuWFujRUpZmFpG8lM0l2k0LcBPh7rHa6lDaeoohTc8z d6c2i/ASyqdOeG1c4oDxpyUFPQlxAu6v7fFyEPyHy2SO9pgctAjyOl4LLOsR6GH1rfWH ES+JpPZdSiVCE7KMGbsok8cxJ82QXvnInWKMzrE80UCjtV3dAFeX5FSjUKWD9vMyUR0w K6PA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700685816; x=1701290616; 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=qCGRE8g3Yo7uLVWHXUPnuPKW4mRSbmeSX+GgKu6M4bo=; b=gBEuyrmNX2NTf/8goLrP3+abbv05bwbn7/NoVG6y5X3keeeCKzY528xL8Ui7r56aZ5 fyye/y23rxehUMqQ/z/ydDFIhYKbP03/8be8Qixe0xJUxQAawlyx38FbpA4xvo8iKHUb U0zmQ7idcqAy5HE8VlaBNBMF6CFM0PERjgt2UeeV5/av284M58NCODgowZVhbOr7MMxc 8CV4eO7lVtO5Pu/0XVa7T/Bj9sxqhIuhMkKCi0f+Abcqn1gYefLyx/vVzXx8cQpD/uKM +Uv+hzLbEi+5lGCItYZm3hNo/ySMedUw1VGujmf9+0JMOwiI0OX/NiUwyPorZPqtS8pV WFRw== X-Gm-Message-State: AOJu0YxTJqv+I5mA2SxazPa7OOgHeQzM3qUJ3+LxBoBGFUgkv1DN0i8P //iufpbJI2A3KuvTb4KnzCnS4HvwrM92THHcNxK6Kg== X-Received: by 2002:a05:6a20:8421:b0:187:eb60:d6ef with SMTP id c33-20020a056a20842100b00187eb60d6efmr3864413pzd.1.1700685815647; Wed, 22 Nov 2023 12:43:35 -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.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 12:43:35 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org, siddhesh@sourceware.org Subject: [PATCH v5 3/5] elf: Ignore loader debug env vars for setuid Date: Wed, 22 Nov 2023 17:43:23 -0300 Message-Id: <20231122204325.4058222-4-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 Loader already ignores LD_DEBUG, LD_DEBUG_OUTPUT, and LD_TRACE_LOADED_OBJECTS. Both LD_WARN and LD_VERBOSE are similar to LD_DEBUG, in the sense they enable additional checks and debug information, so it makes sense to disable them. Also add both LD_VERBOSE and LD_WARN on filtered environment variables for setuid binaries. Checked on x86_64-linux-gnu. Reviewed-by: Siddhesh Poyarekar --- elf/rtld.c | 22 ++++++++++++++-------- elf/tst-env-setuid.c | 4 ++++ sysdeps/generic/unsecvars.h | 2 ++ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/elf/rtld.c b/elf/rtld.c index 0553c05edb..d1017ba9e9 100644 --- a/elf/rtld.c +++ b/elf/rtld.c @@ -2550,13 +2550,15 @@ process_envvars (struct dl_main_state *state) { case 4: /* Warning level, verbose or not. */ - if (memcmp (envline, "WARN", 4) == 0) + if (!__libc_enable_secure + && memcmp (envline, "WARN", 4) == 0) GLRO(dl_verbose) = envline[5] != '\0'; break; case 5: /* Debugging of the dynamic linker? */ - if (memcmp (envline, "DEBUG", 5) == 0) + if (!__libc_enable_secure + && memcmp (envline, "DEBUG", 5) == 0) { process_dl_debug (state, &envline[6]); break; @@ -2571,7 +2573,8 @@ process_envvars (struct dl_main_state *state) case 7: /* Print information about versions. */ - if (memcmp (envline, "VERBOSE", 7) == 0) + if (!__libc_enable_secure + && memcmp (envline, "VERBOSE", 7) == 0) { state->version_info = envline[8] != '\0'; break; @@ -2630,7 +2633,8 @@ process_envvars (struct dl_main_state *state) } /* Where to place the profiling data file. */ - if (memcmp (envline, "DEBUG_OUTPUT", 12) == 0) + if (!__libc_enable_secure + && memcmp (envline, "DEBUG_OUTPUT", 12) == 0) { debug_output = &envline[13]; break; @@ -2651,7 +2655,8 @@ process_envvars (struct dl_main_state *state) case 20: /* The mode of the dynamic linker can be set. */ - if (memcmp (envline, "TRACE_LOADED_OBJECTS", 20) == 0) + if (!__libc_enable_secure + && memcmp (envline, "TRACE_LOADED_OBJECTS", 20) == 0) { state->mode = rtld_mode_trace; state->mode_trace_program @@ -2673,9 +2678,10 @@ process_envvars (struct dl_main_state *state) } while (*nextp != '\0'); - GLRO(dl_debug_mask) = 0; - - if (state->mode != rtld_mode_normal) + if (GLRO(dl_debug_mask) != 0 + || GLRO(dl_verbose) != 0 + || state->mode != rtld_mode_normal + || state->version_info) _exit (5); } /* If we have to run the dynamic linker in debugging mode and the diff --git a/elf/tst-env-setuid.c b/elf/tst-env-setuid.c index 76b8e1fb45..b1d64ac085 100644 --- a/elf/tst-env-setuid.c +++ b/elf/tst-env-setuid.c @@ -59,6 +59,10 @@ static const struct envvar_t filtered_envvars[] = { "MALLOC_TRACE", FILTERED_VALUE }, { "MALLOC_TRIM_THRESHOLD_", FILTERED_VALUE }, { "RES_OPTIONS", FILTERED_VALUE }, + { "LD_DEBUG", "all" }, + { "LD_DEBUG_OUTPUT", "/tmp/some-file" }, + { "LD_WARN", FILTERED_VALUE }, + { "LD_VERBOSE", FILTERED_VALUE }, }; static const struct envvar_t unfiltered_envvars[] = diff --git a/sysdeps/generic/unsecvars.h b/sysdeps/generic/unsecvars.h index f7ebed60e5..8975df4a14 100644 --- a/sysdeps/generic/unsecvars.h +++ b/sysdeps/generic/unsecvars.h @@ -16,6 +16,8 @@ "LD_PRELOAD\0" \ "LD_PROFILE\0" \ "LD_SHOW_AUXV\0" \ + "LD_VERBOSE\0" \ + "LD_WARN\0" \ "LOCALDOMAIN\0" \ "LOCPATH\0" \ "MALLOC_ARENA_MAX\0" \