From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from butterfly.birch.relay.mailchannels.net (butterfly.birch.relay.mailchannels.net [23.83.209.27]) by sourceware.org (Postfix) with ESMTPS id 18F893854833 for ; Tue, 16 Mar 2021 07:08:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 18F893854833 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 6CA0F34205D; Tue, 16 Mar 2021 07:08:10 +0000 (UTC) Received: from pdx1-sub0-mail-a59.g.dreamhost.com (100-96-133-30.trex.outbound.svc.cluster.local [100.96.133.30]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id F05B93420D1; Tue, 16 Mar 2021 07:08:09 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from pdx1-sub0-mail-a59.g.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384) by 100.96.133.30 (trex/6.1.1); Tue, 16 Mar 2021 07:08:10 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Illegal-Duck: 6b6cb37624f50bb7_1615878490272_3274836416 X-MC-Loop-Signature: 1615878490272:3523254573 X-MC-Ingress-Time: 1615878490272 Received: from pdx1-sub0-mail-a59.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a59.g.dreamhost.com (Postfix) with ESMTP id AAA478A69D; Tue, 16 Mar 2021 00:08:09 -0700 (PDT) Received: from rhbox.redhat.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-a59.g.dreamhost.com (Postfix) with ESMTPSA id 582978A69F; Tue, 16 Mar 2021 00:08:07 -0700 (PDT) X-DH-BACKEND: pdx1-sub0-mail-a59 From: Siddhesh Poyarekar To: libc-alpha@sourceware.org Subject: [PATCH 3/4] Enhance setuid-tunables test Date: Tue, 16 Mar 2021 12:37:54 +0530 Message-Id: <20210316070755.330084-4-siddhesh@sourceware.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210316070755.330084-1-siddhesh@sourceware.org> References: <20210316070755.330084-1-siddhesh@sourceware.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-3495.1 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_H2, 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-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 16 Mar 2021 07:08:18 -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. --- 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 3b8e13e066..4e04c26eea 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -1653,8 +1653,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