From patchwork Mon Nov 6 20:25:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 741465 Delivered-To: patch@linaro.org Received: by 2002:adf:fd90:0:b0:32d:baff:b0ca with SMTP id d16csp1294822wrr; Mon, 6 Nov 2023 12:27:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IETkD8n/EZDQF8gw160O/DEfzwoBtVSIyQ1qM3RuZZTJo3wBUJ7/M3mgQIuFFWlo8DfHim5 X-Received: by 2002:a05:620a:472c:b0:775:6695:b10f with SMTP id bs44-20020a05620a472c00b007756695b10fmr34382521qkb.56.1699302462801; Mon, 06 Nov 2023 12:27:42 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1699302462; cv=pass; d=google.com; s=arc-20160816; b=ZIZR/o/zJ7TksDtrGkvfJyEueHe6oi2Kd1Yr7+K8Dy0sdlApFVDmAiFKr/Xl99AZSS F5sKIH+bnm5iXJ0hSSiF1JvTkJZUERzwXOf9g76xTSH+C5zfseinEHH8SwjRNUOsNqDY vomWTO1BsLhyks994FR8iM6AkBI1yiEFGUi0n5rui96eIaJ5nTYjgLjrNtg2Lhuq7vBU Ij75I9mhgY8pzeLOE5dms7J8b6qzyGosw+z+cQPo+U0eGmKKabtLJwRIRudJ89Y6a+ta MDW86K162lC3/ncudp3SGxJuA6QRbwLJ55kMWkG/icH9BhwkXrGNHHcSt9dm/ISsI4JX nLgA== 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=+4GDbFUmw1Mr9IXcIz740H4haKsPlYiuLewlNhU0zqc=; fh=+FUb54tScwW7D3lvWhZcQBi30wyNNn2DusdH7ahfqKk=; b=eroHNEkueXhCCeGE4xBctphvSzSL/Xyn5XDM52bvXClL1+NjSouHkklZM4bm8goYxS YsIE0TGaMGl/60LL962Mlh2z6J4/uVj70+tpoAvovr4ZbVEaex8izMeO2sv4OGPNZHuZ 24hKLFDVo/TvIYRfehN11N1tDKU8gjKbdnUXfXnA7ULgYIlv9kA13HpxbIYYIUdD7Gdq 7PRW5lTAgBfXdKz5riKY47zG9pZytDdypX8zK5Y1bI1UjSbn1BDRpcaLHIXERCMa2Ztz V0tyNnvg7q3vhAwHabNaKbUIXPYWeBWIL7uH3OP0ukdMkhkBIg5vvwvc54oGpWdqShh7 1a4w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IAqSYtq2; 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 t15-20020a05620a450f00b007770bfd349fsi6305946qkp.603.2023.11.06.12.27.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 12:27:42 -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=IAqSYtq2; 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 6D0023852770 for ; Mon, 6 Nov 2023 20:27:42 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-yw1-x1133.google.com (mail-yw1-x1133.google.com [IPv6:2607:f8b0:4864:20::1133]) by sourceware.org (Postfix) with ESMTPS id A11E73858023 for ; Mon, 6 Nov 2023 20:26:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A11E73858023 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 A11E73858023 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1133 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699302395; cv=none; b=EGtTPDNYxWTW6PktdGU6NuoWR0wV5hisXb1TG6xVI0XZ4YODVC2knw0bGNgV2Qo5ithPMC9p+gKWbXSPAn3+SnYgjODcnyvbEJnu2CBFAggLtnPPUu5gDW4bX9mkmwxXm5WnBNC4VdJ/YF5dChJ7Mwz3CW+6zyjY5NUARO1FkLk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699302395; c=relaxed/simple; bh=Rk1BxMlwimWl0kYqwXPVTuQKRCggvqczoUCnIMXiGsc=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=IouvMmReLBUF1TElewdcIZOZir+4EQOAeDkRSamSwP32U52zupazYlmIsnG18vJe8Mb2N3AIwe+uIzVsIzMt+QPvhEKXvrTmwCZvm0wrPPvTf51wwvraws4bzekrtxk1A7gK7v9yONXGluj9+Tn8sGD3MjoJJ/Eh8UNWMoxGgrU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yw1-x1133.google.com with SMTP id 00721157ae682-5a7eef0b931so57909057b3.0 for ; Mon, 06 Nov 2023 12:26:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699302393; x=1699907193; 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=+4GDbFUmw1Mr9IXcIz740H4haKsPlYiuLewlNhU0zqc=; b=IAqSYtq2hbyNI8Ja8Hag/KWxeemQ4z5N39V+rJ9liN6e/Z3OHxan3OHxdXIbIbatR9 D0EospEKwuY4oqOU+0xYzreenRFt5MGgssVz8YnWSMFu3cBVykpdhcPDhNYqyOPN6vtF k/ohbS18mJ+t9ERbsH+gZ7BqqnErP4DJPkRsbyq8xpWN2h/KB0NrRZbz5wtnrQXs+2GG 3+J4NTilNv2BEb2JXQO/eE0ezjLiANCYdQ+M4StKTNyIy+jhnRUkJmLvZhWNhM8RlHOx /2yY2SfqK66jYWAjSBDXF9TMK4kNx9oNCRFPIYm/gnOD9/AsW+2v6sv8LZ7sRBYRH9bX 65eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699302393; x=1699907193; 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=+4GDbFUmw1Mr9IXcIz740H4haKsPlYiuLewlNhU0zqc=; b=vLU5XTC52ntxHUystjBLTLvrAlzMScDeKbGBSh3+ErLMWxanwJsmGyourEVoV450xd LOJr2Z0qmSdnGu+QlU42bNBSecb2WWRbXrHt+gbaEPkA/FITdyr0ChL6z0zJGiY+9xun uwrr0Jt3fQAopwEo+FyX8WB5y26kIxTRBasd9O63kKF6YlLvGDBfrh/P0fhblz8DHWrf SSXUnkvMOGoAREaMt7wpMbThZuD8VtdMQefYTlEbUOALBYoKL9wSQabKSCr3jCsLDcfR PfL0F/F5W6VBXMWpA6IP90aRhem/F9GFnqCd902gNkUfxoD/Urp0bhpYyId+OuKqmtAS zvig== X-Gm-Message-State: AOJu0YxIy/7tJvptQkRZ7/o/coeeWLDj2gE9LbiAfL0wnAXJBw3BwHGu BfVxDU6eTxiWrQGRD4iUTc4zRvMbl4EjePD8wbREjw== X-Received: by 2002:a81:a00a:0:b0:59b:fda7:9d7f with SMTP id x10-20020a81a00a000000b0059bfda79d7fmr12088615ywg.49.1699302393422; Mon, 06 Nov 2023 12:26:33 -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.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 12:26:32 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org, Siddhesh Poyarekar Subject: [PATCH v3 18/19] elf: Ignore LD_BIND_NOW and LD_BIND_NOT for setuid binaries Date: Mon, 6 Nov 2023 17:25:51 -0300 Message-Id: <20231106202552.3404059-19-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+patch=linaro.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 dcf213a4cd..eb9613d717 100644 --- a/elf/tst-env-setuid.c +++ b/elf/tst-env-setuid.c @@ -61,12 +61,12 @@ static const struct envvar_t filtered_envvars[] = { "RES_OPTIONS", FILTERED_VALUE }, { "LD_DEBUG", "all" }, { "LD_DEBUG_OUTPUT", "/tmp/some-file" }, + { "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 f7ebed60e5..c71b70ed95 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" \