From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from quail.birch.relay.mailchannels.net (quail.birch.relay.mailchannels.net [23.83.209.151]) by sourceware.org (Postfix) with ESMTPS id A39A53858413 for ; Mon, 20 Nov 2023 22:47:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A39A53858413 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=sourceware.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=sourceware.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A39A53858413 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=23.83.209.151 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1700520445; cv=pass; b=WQz3NytFFPfXY90oqumHhFKDv6OZctJtaXMRxi1oINamjgLS4nmfAjCe+lDsoJz6Tr/85FPC9c2jAbaoHooou4Q+qZt9Bue9YV/IGmPQMrYZLFGJdpiJwfAzve8Du0GVjcfZ0eeGqdQTg+euLTB3dEHud+/wgxhHoAuwzJw5VwA= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1700520445; c=relaxed/simple; bh=HkN38Jl+DbTy8QisCD20GeUFOqRTh5vtIg8iJzjp3lY=; h=Message-ID:Date:MIME-Version:Subject:To:From; b=fu69wDbE5uA0MIQdSEuz51iHNJn/j9Sp6urD/D7Quic0P9tc20JAr2T29KZ3Xe2WQWZ+mw8T8HrSVSS7cCQ/X+qnc1RdjUD7LlH1zIiHZKZB1DYhvY4p1QDCtjysoI3Hi5wmBS0YlP2AF/Jx3zm/PtFih5bc0rDCBjqHK7E2/48= ARC-Authentication-Results: i=2; server2.sourceware.org X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 43F20822E1; Mon, 20 Nov 2023 22:47:22 +0000 (UTC) Received: from pdx1-sub0-mail-a272.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id E53A982396; Mon, 20 Nov 2023 22:47:21 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1700520441; a=rsa-sha256; cv=none; b=qonpxS8PdcfQEzAbgsCCKDd5V7H8C8Ep6AHlAHUqhD6tVrn6QLixpD9W0kBKiJ/tIZpdD4 ZVUzpl+hj6oBFLUIxaMR2NOhW6VAnYdo1fHnCvrLkq1RAgLBBmqtD76wfN3x0IaXj6TNcU QZTkNZPARANh+i9aSYuLmGjdh2CzSqEJKywhw3K90AlnTFX1JAxnlpeDylviJX5+u90dr2 HA+QYDegrNJk4FKYAOIXhJs9SQAwUyj0h1leONRzqkl1l5q/Is5qzzWGkB2hKsRMRdM+J3 tmAmHSq5A619B1PFGqjm7te5BH2+FKAJRVHB46VOoHCiWXMtKCa8Fnzx3lRn2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1700520441; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IHG6XMsnW2+f0PzcXDdA+kWxhle524LCgoOqYecv9io=; b=iLPigJnKIGI01zop2GCeP22jeG2Rjakteq+M9uXjfx/SuRkmHTPUdyMrQC0xNmsay/d3j5 rj5NuOEL95PvT5fdHWUr9I1ZZSgr5sGfDrInm+nUvWdnX9MJbrwK/oLw2OKg2UJHGK4uuM RO8wYWi1ySvng27TaVwa87hZeRxmOV2ACrPcYC2/Pcd+o6VZ1pYYtPWeZwxOK/Y2wPHjIk gD1gJPYI1R1M+jSunWA7hfWHyRXVwydfy7Qx2w+gM0GBBJHSsqHg1iAthRCruA8gH+g5/t VOi08Rj+R41np3aiWP3fAkJvWp/N42VxidGYYxtbosIiXDAEADGBLpfPGQDQ4Q== ARC-Authentication-Results: i=1; rspamd-55bcb54c45-vf4dl; auth=pass smtp.auth=dreamhost smtp.mailfrom=siddhesh@sourceware.org X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Troubled-Wide-Eyed: 72bbc5db2a87fad5_1700520442061_3911706867 X-MC-Loop-Signature: 1700520442061:2140904928 X-MC-Ingress-Time: 1700520442061 Received: from pdx1-sub0-mail-a272.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.117.100.100 (trex/6.9.2); Mon, 20 Nov 2023 22:47:22 +0000 Received: from [192.168.2.12] (bras-vprn-toroon4834w-lp130-02-142-113-138-136.dsl.bell.ca [142.113.138.136]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a272.dreamhost.com (Postfix) with ESMTPSA id 4SZ2h94KQRz6n; Mon, 20 Nov 2023 14:47:21 -0800 (PST) Message-ID: <9e6ff19a-e299-4a80-87dd-719d934a3862@sourceware.org> Date: Mon, 20 Nov 2023 17:47:19 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 12/19] elf: Ignore LD_PROFILE for setuid binaries Content-Language: en-US To: Adhemerval Zanella , libc-alpha@sourceware.org References: <20231106202552.3404059-1-adhemerval.zanella@linaro.org> <20231106202552.3404059-13-adhemerval.zanella@linaro.org> From: Siddhesh Poyarekar In-Reply-To: <20231106202552.3404059-13-adhemerval.zanella@linaro.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1172.1 required=5.0 tests=BAYES_00,GIT_PATCH_0,KAM_DMARC_NONE,KAM_DMARC_STATUS,KAM_SHORT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_SOFTFAIL,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 2023-11-06 15:25, Adhemerval Zanella wrote: > Loader does not ignore LD_PROFILE in secure-execution mode (different > than man-page states [1]), rather it uses a different path > (/var/profile) and ignore LD_PROFILE_OUTPUT. > > Allowing secure-execution profiling is already a non good security > boundary, since it enables different code paths and extra OS access by > the process. But by ignoring LD_PROFILE_OUTPUT, the resulting profile > file might also be acceded in a racy manner since the file name does not > use any process-specific information (such as pid, timing, etc.). > > Another side-effect is it forces lazy binding even on libraries that > might be with DF_BIND_NOW. > > [1] https://man7.org/linux/man-pages/man8/ld.so.8.html > --- LGTM. Reviewed-by: Siddhesh Poyarekar > elf/Makefile | 3 +++ > elf/rtld.c | 8 +++----- > elf/tst-env-setuid.c | 12 +++++++++++- > 3 files changed, 17 insertions(+), 6 deletions(-) > > diff --git a/elf/Makefile b/elf/Makefile > index 52981c19d0..08896bb895 100644 > --- a/elf/Makefile > +++ b/elf/Makefile > @@ -2983,3 +2983,6 @@ $(objpfx)tst-dlclose-lazy.out: \ > $(objpfx)tst-dlclose-lazy-mod1.so $(objpfx)tst-dlclose-lazy-mod2.so > > tst-env-setuid-ARGS = -- $(host-test-program-cmd) > + > +# Reuse a module with a SONAME, to specific as the LD_PROFILE. > +$(objpfx)tst-env-setuid: $(objpfx)tst-sonamemove-runmod2.so > diff --git a/elf/rtld.c b/elf/rtld.c > index 51b6d9f326..a09cf2a9df 100644 > --- a/elf/rtld.c > +++ b/elf/rtld.c > @@ -361,6 +361,7 @@ struct rtld_global_ro _rtld_global_ro attribute_relro = > ._dl_fpu_control = _FPU_DEFAULT, > ._dl_pagesize = EXEC_PAGESIZE, > ._dl_inhibit_cache = 0, > + ._dl_profile_output = "/var/tmp", > > /* Function pointers. */ > ._dl_debug_printf = _dl_debug_printf, > @@ -2534,10 +2535,6 @@ process_envvars (struct dl_main_state *state) > char *envline; > char *debug_output = NULL; > > - /* This is the default place for profiling data file. */ > - GLRO(dl_profile_output) > - = &"/var/tmp\0/var/profile"[__libc_enable_secure ? 9 : 0]; > - > while ((envline = _dl_next_ld_env_entry (&runp)) != NULL) > { > size_t len = 0; > @@ -2586,7 +2583,8 @@ process_envvars (struct dl_main_state *state) > } > > /* Which shared object shall be profiled. */ > - if (memcmp (envline, "PROFILE", 7) == 0 && envline[8] != '\0') > + if (!__libc_enable_secure > + && memcmp (envline, "PROFILE", 7) == 0 && envline[8] != '\0') > GLRO(dl_profile) = &envline[8]; > break; > > diff --git a/elf/tst-env-setuid.c b/elf/tst-env-setuid.c > index ba295a6a14..76b8e1fb45 100644 > --- a/elf/tst-env-setuid.c > +++ b/elf/tst-env-setuid.c > @@ -34,6 +34,9 @@ static char SETGID_CHILD[] = "setgid-child"; > > #define FILTERED_VALUE "some-filtered-value" > #define UNFILTERED_VALUE "some-unfiltered-value" > +/* It assumes no other programs is being profile with a library with same > + SONAME using the default folder. */ > +#define PROFILE_LIB "tst-sonamemove-runmod2.so" > > struct envvar_t > { > @@ -50,7 +53,7 @@ static const struct envvar_t filtered_envvars[] = > { "LD_HWCAP_MASK", FILTERED_VALUE }, > { "LD_LIBRARY_PATH", FILTERED_VALUE }, > { "LD_PRELOAD", FILTERED_VALUE }, > - { "LD_PROFILE", FILTERED_VALUE }, > + { "LD_PROFILE", "tst-sonamemove-runmod2.so" }, > { "MALLOC_ARENA_MAX", FILTERED_VALUE }, > { "MALLOC_PERTURB_", FILTERED_VALUE }, > { "MALLOC_TRACE", FILTERED_VALUE }, > @@ -87,6 +90,13 @@ test_child (void) > ret |= !(env != NULL && strcmp (env, e->value) == 0); > } > > + /* Also check if no profile file was created. */ > + { > + char *profilepath = xasprintf ("/var/tmp/%s.profile", PROFILE_LIB); > + ret |= !access (profilepath, R_OK); > + free (profilepath); > + } > + > return ret; > } >