From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from antelope.dogwood.relay.mailchannels.net (antelope.dogwood.relay.mailchannels.net [23.83.211.4]) by sourceware.org (Postfix) with ESMTPS id C1B233851C04 for ; Wed, 14 Apr 2021 05:04:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org C1B233851C04 Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 50AFA341C50; Wed, 14 Apr 2021 05:04:56 +0000 (UTC) Received: from pdx1-sub0-mail-a20.g.dreamhost.com (100-96-16-47.trex.outbound.svc.cluster.local [100.96.16.47]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id E09F5341BD7; Wed, 14 Apr 2021 05:04:45 +0000 (UTC) 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.16.47 (trex/6.1.1); Wed, 14 Apr 2021 05:04:56 +0000 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 A84D87EFB7; Tue, 13 Apr 2021 22:04:45 -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 02B327EFBB; Tue, 13 Apr 2021 22:04:43 -0700 (PDT) X-DH-BACKEND: pdx1-sub0-mail-a20 From: Siddhesh Poyarekar To: libc-stable@sourceware.org Cc: Carlos O'Donell Subject: [COMMITTED 2.33 6/7] Enhance setuid-tunables test Date: Wed, 14 Apr 2021 10:34:21 +0530 Message-Id: <20210414050422.981607-6-siddhesh@sourceware.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210414050422.981607-1-siddhesh@sourceware.org> References: <20210414050422.981607-1-siddhesh@sourceware.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-3495.0 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, 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:05:02 -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 4b92f8b305..28e18aea5d 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -1658,8 +1658,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 50bef8683d..3d523875b1 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