From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firebrick.apple.relay.mailchannels.net (firebrick.apple.relay.mailchannels.net [23.83.208.59]) by sourceware.org (Postfix) with ESMTPS id B13273987C07 for ; Wed, 14 Apr 2021 05:41:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org B13273987C07 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 A7FBC219A5; Wed, 14 Apr 2021 05:41:49 +0000 (UTC) Received: from pdx1-sub0-mail-a20.g.dreamhost.com (100-96-11-98.trex.outbound.svc.cluster.local [100.96.11.98]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 1781A21B74; Wed, 14 Apr 2021 05:41:49 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from pdx1-sub0-mail-a20.g.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384) by 100.96.11.98 (trex/6.1.1); Wed, 14 Apr 2021 05:41:49 +0000 X-MC-Relay: Good X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Zesty-Chemical: 0b557b7b0b1e95dd_1618378909429_3075491599 X-MC-Loop-Signature: 1618378909429:2233211165 X-MC-Ingress-Time: 1618378909428 Received: from pdx1-sub0-mail-a20.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a20.g.dreamhost.com (Postfix) with ESMTP id D027D7EFB7; Tue, 13 Apr 2021 22:41:48 -0700 (PDT) Received: from rhbox.intra.reserved-bit.com (unknown [1.186.101.110]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a20.g.dreamhost.com (Postfix) with ESMTPSA id 6CA637EFBE; Tue, 13 Apr 2021 22:41:46 -0700 (PDT) X-DH-BACKEND: pdx1-sub0-mail-a20 From: Siddhesh Poyarekar To: libc-stable@sourceware.org Cc: Carlos O'Donell Subject: [COMMITTED 2.29 5/6] Enhance setuid-tunables test Date: Wed, 14 Apr 2021 11:11:27 +0530 Message-Id: <20210414054128.1249310-5-siddhesh@sourceware.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210414054128.1249310-1-siddhesh@sourceware.org> References: <20210414054128.1249310-1-siddhesh@sourceware.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-3494.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_NONE, KAM_DMARC_STATUS, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-stable@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-stable mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 14 Apr 2021 05:41:52 -0000 Instead of passing GLIBC_TUNABLES via the environment, pass the environment variable from parent to child. This allows us to test multiple variables to ensure better coverage. The test list currently only includes the case that's already being tested. More tests will be added later. Reviewed-by: Carlos O'Donell (cherry picked from commit 061fe3f8add46a89b7453e87eabb9c4695005ced) --- elf/Makefile | 2 - elf/tst-env-setuid-tunables.c | 90 +++++++++++++++++++++++++++-------- 2 files changed, 69 insertions(+), 23 deletions(-) diff --git a/elf/Makefile b/elf/Makefile index 70b9d368e3..ea3a160024 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -1465,8 +1465,6 @@ $(objpfx)tst-nodelete-dlclose.out: $(objpfx)tst-nod= elete-dlclose-dso.so \ =20 tst-env-setuid-ENV =3D MALLOC_CHECK_=3D2 MALLOC_MMAP_THRESHOLD_=3D4096 \ LD_HWCAP_MASK=3D0x1 -tst-env-setuid-tunables-ENV =3D \ - GLIBC_TUNABLES=3Dglibc.malloc.check=3D2:glibc.malloc.mmap_threshold=3D4= 096 =20 $(objpfx)tst-debug1: $(libdl) $(objpfx)tst-debug1.out: $(objpfx)tst-debug1mod1.so diff --git a/elf/tst-env-setuid-tunables.c b/elf/tst-env-setuid-tunables.= c index e92e9f5fbf..4681a60494 100644 --- a/elf/tst-env-setuid-tunables.c +++ b/elf/tst-env-setuid-tunables.c @@ -25,35 +25,50 @@ #include "config.h" #undef _LIBC =20 -#define test_parent test_parent_tunables -#define test_child test_child_tunables - -static int test_child_tunables (void); -static int test_parent_tunables (void); - -#include "tst-env-setuid.c" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +const char *teststrings[] =3D +{ + "glibc.malloc.check=3D2:glibc.malloc.mmap_threshold=3D4096", +}; =20 -#define CHILD_VALSTRING_VALUE "glibc.malloc.mmap_threshold=3D4096" -#define PARENT_VALSTRING_VALUE \ - "glibc.malloc.check=3D2:glibc.malloc.mmap_threshold=3D4096" +const char *resultstrings[] =3D +{ + "glibc.malloc.mmap_threshold=3D4096", +}; =20 static int -test_child_tunables (void) +test_child (int off) { const char *val =3D getenv ("GLIBC_TUNABLES"); =20 #if HAVE_TUNABLES - if (val !=3D NULL && strcmp (val, CHILD_VALSTRING_VALUE) =3D=3D 0) + if (val !=3D NULL && strcmp (val, resultstrings[off]) =3D=3D 0) return 0; =20 if (val !=3D NULL) - printf ("Unexpected GLIBC_TUNABLES VALUE %s\n", val); + printf ("[%d] Unexpected GLIBC_TUNABLES VALUE %s\n", off, val); =20 return 1; #else if (val !=3D NULL) { - printf ("GLIBC_TUNABLES not cleared\n"); + printf ("[%d] GLIBC_TUNABLES not cleared\n", off); return 1; } return 0; @@ -61,15 +76,48 @@ test_child_tunables (void) } =20 static int -test_parent_tunables (void) +do_test (int argc, char **argv) { - const char *val =3D getenv ("GLIBC_TUNABLES"); + /* Setgid child process. */ + if (argc =3D=3D 2) + { + if (getgid () =3D=3D getegid ()) + /* This can happen if the file system is mounted nosuid. */ + FAIL_UNSUPPORTED ("SGID failed: GID and EGID match (%jd)\n", + (intmax_t) getgid ()); =20 - if (val !=3D NULL && strcmp (val, PARENT_VALSTRING_VALUE) =3D=3D 0) - return 0; + int ret =3D test_child (atoi (argv[1])); =20 - if (val !=3D NULL) - printf ("Unexpected GLIBC_TUNABLES VALUE %s\n", val); + if (ret !=3D 0) + exit (1); =20 - return 1; + exit (EXIT_SUCCESS); + } + else + { + int ret =3D 0; + + /* Spawn tests. */ + for (int i =3D 0; i < array_length (teststrings); i++) + { + char buf[INT_BUFSIZE_BOUND (int)]; + + printf ("Spawned test for %s (%d)\n", teststrings[i], i); + snprintf (buf, sizeof (buf), "%d\n", i); + if (setenv ("GLIBC_TUNABLES", teststrings[i], 1) !=3D 0) + exit (1); + + int status =3D support_capture_subprogram_self_sgid (buf); + + /* Bail out early if unsupported. */ + if (WEXITSTATUS (status) =3D=3D EXIT_UNSUPPORTED) + return EXIT_UNSUPPORTED; + + ret |=3D status; + } + return ret; + } } + +#define TEST_FUNCTION_ARGV do_test +#include --=20 2.29.2