From patchwork Wed Nov 22 12:35:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 746024 Delivered-To: patch@linaro.org Received: by 2002:a5d:6706:0:b0:32d:baff:b0ca with SMTP id o6csp273642wru; Wed, 22 Nov 2023 04:36:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IHNB1M13gEO2WGoUNk15RnWKTSK/XU/wEjhvG2RvQe0F+eUJz31sZ8fq2OYJJf+Gd5HfdOh X-Received: by 2002:a05:620a:414b:b0:778:a4a5:8bc5 with SMTP id k11-20020a05620a414b00b00778a4a58bc5mr2380155qko.6.1700656598757; Wed, 22 Nov 2023 04:36:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1700656598; cv=pass; d=google.com; s=arc-20160816; b=ncFKhdqyLkWr0lLljZ5ThZ1nbYk5WajoOwtlMGjbpCU3/Q1iNpLPHo4kVgQyyJF9r8 IwEKkpRjDvRKAozM4RDGT7SVy4fGLAMCaSrmlARjh9ffyTAqWRYTdlocvUJ8AnMCNPgf RpgQyU7utjppcJJJUNDtljLxQXZ2PRa6bdUvY3lyFniEnSwwjnRv4p4uvIYqpqUJq1u2 dIZtpOXLD6LclAKobdpUDnrWzxs0kv5TeWL6cH8K1AlJ8rWD1Wn9hxXwGUL74B8SL6PE 1nuyXHxRSe6Y7hbrQR6uk0gpuRDp0IL0gN1/3m53HKFH6EEPix96VItcxovdNrVL87gQ 1Wmw== 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=r0JELEmXkNYK1D5+oPH6/PjQPc+9XVWx78eLFGTAuDsQxML6USMqrZ76fVZh9OiKwN DFKoWCofGJmjWyD6owr5x9cBn2nTkKPPcTvOfWBxDAa25bDUbJXO0uoTVwf7r2p2JKsf EpntxK7sFjB9EeNrZpku8ln0zrENyscdyo0bgv/p4m6tNRU+Itpybvam6cSFpyWRHdJt H0VW+4KeE58NFlD1rG6pbDOWeQtyiAKaYhkVIhCPaX987hMC+YgDc/Ek75xwA6hWeoXi 9RGpcBh3FbponCMWGM6lbFyUvezJMK44qJqJeYUAIEUXJVBUTrXDh4k0oU83cmAfA5ph 8pVw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tV8p6lKB; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 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. [8.43.85.97]) by mx.google.com with ESMTPS id i22-20020a05620a27d600b00779fe883db1si11435650qkp.514.2023.11.22.04.36.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 04:36:38 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tV8p6lKB; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 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 6A8A7385AC09 for ; Wed, 22 Nov 2023 12:36:38 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com [IPv6:2607:f8b0:4864:20::52e]) by sourceware.org (Postfix) with ESMTPS id 26CAF385800B for ; Wed, 22 Nov 2023 12:36:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 26CAF385800B 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 26CAF385800B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::52e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700656573; cv=none; b=AKyll82OJyJEqGEhDM9ft9v+PcSngnCRpW5ezqVtOGzJP8fOW5B55hZ7uP4fMeR6NfnuQviJCa0oaddA7aL3jouksuyZ971/tdnn09dIP+OvvrdqQ/775ewGIzH4DWdzQtBsKTinlAIEzN/jDK/ZNOxgbFL2+jd0HD9kOg8C1bE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700656573; c=relaxed/simple; bh=pnipUWtW/9+iYyWUu/tGomUPc2c4lB5nvX4BL6cRAPM=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=eIDpM08yzOqLGi0xiWPmle1S+l2OcqE1OSHs8YQqfqxqfknmQFH++3v+A6qw6+apfGpZ1EpiiaDhNfRhy9phxj/di9d+atch/YKRC3YQmqbNEt4XmtlJfe3ngonu1gYm7hUTGZR4DsSZIrzpTYW7myRY2i+WFP5mxU/z03a1VYs= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pg1-x52e.google.com with SMTP id 41be03b00d2f7-5c194b111d6so5127639a12.0 for ; Wed, 22 Nov 2023 04:36:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1700656570; x=1701261370; 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=tV8p6lKB9ccLPj0dWIr6g7pxAI9egA87fJtWhCVjm526S/d9zxaUddqGF260nierf5 bb7V28+r/9tKp9AxRvTZ/8RGqq6qFaRZ7Z8UJybd0jGDEwvVxzan6HRPFSvX461rsOqg mX5CgHXmAmNEm8eICpWMFzcQgPahEYKv1XrfkMfhmyV1wyba9pdsRUDs4CCBxRN2ZslG UV14NT84fWMSKiKHZqTMGLLW5Dr3XxFU43hOXKtCF5HmkleUP3WNXj2TUjWVoR42maCj KlNjJawG8l/SHlCFsTXzK447dJMw8KIrb9jMOg+eJfgLwOl2tsD3iD4TE1mUuYiUjL5y uGzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700656570; x=1701261370; 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=fncx/6WhNZGC0YfNquOvh9HzMVbEVX7h5puoY8Yz4mCkx7C1JHXf5WTzBw36P5vGga i8FijaNTrbYHT4tlESU4GtGetM+hiTewG/Dy3KA6uSUBxBO9KbJsUPDydYNfxrDcu85M YginQh4qeLq74JAaOnNBMBUQzHSEbI76PcksrpR7I2ztclHDreeXFtmE39q1NCKEDAKZ 84a7pHuh72d2unb3Q2KFB3OnQ7CDI8P72wc2eqBazBQeskcozhS7SZs/kRC+FUdEktgE JR6FR43YdRVwLFzSsNEy6sBurEoqBPqlDHSnIJVcDBSYaIgTS5bdNUGEY2Au38mCHbvr LiHg== X-Gm-Message-State: AOJu0YycltL/tqWdXB6yrpYda0+KOTYXYmV4x1ooqbnNx7+5AvDZICnS PshYy7+Df7h5c01Y9ab7c69QvdUDKg4FyQtGe7K0oA== X-Received: by 2002:a17:90a:e7ca:b0:27d:3f08:cc21 with SMTP id kb10-20020a17090ae7ca00b0027d3f08cc21mr2446373pjb.5.1700656570385; Wed, 22 Nov 2023 04:36:10 -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.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 04:36:09 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org, siddhesh@sourceware.org Subject: [PATCH v4 2/4] elf: Ignore loader debug env vars for setuid Date: Wed, 22 Nov 2023 09:35:59 -0300 Message-Id: <20231122123601.603315-3-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.4 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. --- 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" \