From patchwork Mon Nov 6 20:25:47 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: 1860457 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=Fbw8HK8V; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SPNF74LL6z1yQ5 for ; Tue, 7 Nov 2023 07:27:23 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A89F6385C422 for ; Mon, 6 Nov 2023 20:27:21 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-yw1-x112d.google.com (mail-yw1-x112d.google.com [IPv6:2607:f8b0:4864:20::112d]) by sourceware.org (Postfix) with ESMTPS id 5A0523858C30 for ; Mon, 6 Nov 2023 20:26:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5A0523858C30 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 5A0523858C30 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::112d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699302389; cv=none; b=gjTEtTSaSeuy/RHbtTGLHQDpgXh8UlbIG4u1NPqsKkhwVIKP1PtO93rpget8WuiLCaPhK/+etOpfAod1nCVEmWDEaFFVr/K29/3D9YDBzQX+C+hkPs+vT13jEME0fpH9rLQXZ4mIVHNPb2R3vJjoknBJVaHKFOpNbKKPlDjbMkU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699302389; c=relaxed/simple; bh=S+KcCnjq4rLBN3SyuYNbx6m/PF7OSvT2JnHhXIKnk6I=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=Zy+ROa/GcP4HtBXayOUlejJtbrq7OoYp24M2pBHrknjkjm0WuQd5DWjW8iNmyMczk4H6a9T7DGuYoxHHqm6pKLH0UMjFnoMDkRylCbxHbsaJsAhRCT/U18N4NuhxTm3oDH2BX+zL5A6KO0p56ca+K4X5w2Xkp2w54fE8yzYlLSw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yw1-x112d.google.com with SMTP id 00721157ae682-5a822f96aedso59176847b3.2 for ; Mon, 06 Nov 2023 12:26:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699302386; x=1699907186; 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=jluY1futqbV0kiB9ZnYNIOlqaz6IeM4BOuQX6u9hb/M=; b=Fbw8HK8VVY3NDaM4v5zW27mu4G0eUZrIv5jx0aw5bQd8Oxr5y1DU1GktEttdsEAcIv S9DJezsiGo4K6Wlcjo1bKiXD4cTu1/AA0RzvKM33ioUs5hv+hgYpt4010Wlx4QSC84L7 faqH8mKKJyj36JMb4drWqsrx1YLCzlSjDYuYg3SmxXW0iqdppKpxDl0/Nnz0hokou4wL M7pLxWn3CtF/JNl6DPxWFQ5suwAKt7Vg8gHjF5t9zBaZdHKI/eLK0Grgqln8kOZ5xdF/ 6NxnAYvJWVi1HhKY0NHQY51GQQHGWxsrr7DCpKcUgwAhg+kQq/8gcvf4SyShuARZw6BS LGbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699302386; x=1699907186; 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=jluY1futqbV0kiB9ZnYNIOlqaz6IeM4BOuQX6u9hb/M=; b=nJZDpeAkhLTgQa985QNnGCJEU11vOx1dFdQ/RIMhC4m6lcMXTLokZrUXlBv4vLjppp VAiyv6TB06pNfTqHLoCMprrkdUtXwEhAFxBmBBiDbSeN7LVEpuc9HaiL0+wpRX73NzFs ZRRY6gRd4DMYVHfr/16MR3gf50qR23fwy3ogRLIbAbeeacZ5e0IiVKQNAlpCCxBvzOUT 8EsNsQRo3s4AxwM336OBl5mh1JfhCfzBRZcV44k54I2YYehIBTjvNKw+2TFAUxImQYqs SD3KfJcL59HBjEzqLn1WS5TZuDh1/ibVKrT288zxzX0McfkYqS0wPiJrWkEDCYNnPhqW QQtA== X-Gm-Message-State: AOJu0YylpoGXiwd4JkQMLbvMomXWkwGY+Jx14hdoq4aSwWFIe7HqgZ+L KJ+IiQjdIs4qm3RLmgX2sF5twZSoVMxFXglgBp0X2w== X-Google-Smtp-Source: AGHT+IH+ZZwx1XDhQ92Rozf8XVLY1NquoRfb8PPZJ+/GwlQ54M7o6s/l624mCFUfBw76RVFfqMHTBA== X-Received: by 2002:a05:690c:fc8:b0:5a7:bbd1:ec21 with SMTP id dg8-20020a05690c0fc800b005a7bbd1ec21mr13657526ywb.0.1699302386331; Mon, 06 Nov 2023 12:26:26 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c0:a715:c1a0:7281:6384:2ee9]) by smtp.gmail.com with ESMTPSA id ci7-20020a05690c0a8700b005a7b8fddfedsm4707154ywb.41.2023.11.06.12.26.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 12:26:24 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org, Siddhesh Poyarekar Subject: [PATCH v3 14/19] elf: Ignore loader debug env vars for setuid Date: Mon, 6 Nov 2023 17:25:47 -0300 Message-Id: <20231106202552.3404059-15-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231106202552.3404059-1-adhemerval.zanella@linaro.org> References: <20231106202552.3404059-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.7 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+incoming=patchwork.ozlabs.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. Checked on x86_64-linux-gnu. --- elf/rtld.c | 22 ++++++++++++++-------- elf/tst-env-setuid.c | 2 ++ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/elf/rtld.c b/elf/rtld.c index a09cf2a9df..e7f90d37e7 100644 --- a/elf/rtld.c +++ b/elf/rtld.c @@ -2552,13 +2552,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; @@ -2569,7 +2571,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; @@ -2625,7 +2628,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; @@ -2646,7 +2650,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 @@ -2668,9 +2673,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..dcf213a4cd 100644 --- a/elf/tst-env-setuid.c +++ b/elf/tst-env-setuid.c @@ -59,6 +59,8 @@ 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" }, }; static const struct envvar_t unfiltered_envvars[] =