From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from fly.ash.relay.mailchannels.net (fly.ash.relay.mailchannels.net [23.83.222.61]) by sourceware.org (Postfix) with ESMTPS id 6FC6F3865C27 for ; Tue, 3 Oct 2023 17:08:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6FC6F3865C27 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=sourceware.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=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 37E2A82964; Tue, 3 Oct 2023 17:08:46 +0000 (UTC) Received: from pdx1-sub0-mail-a208.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id C31588187B; Tue, 3 Oct 2023 17:08:45 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1696352925; a=rsa-sha256; cv=none; b=H05MyfB4yjw+qRJN6pjeOUrSQ80/NtrU0nOZEod0JdLPbuqcNPIU9JzoUrP5QHGcu4pjpe 00Jf+TuFG1yMuh8a7E6W19PNy3w7D8rzni/ha84hFCLlVikTQgoFD3tdZ9XVpYtXW/V+dE XBetFsqlt7WgrD9W7y91CH6C86eI0usMenzMtAjNrAEORTSjLpLCMxhh5KSyKv8OuS5V4x dNzA/UIZq1SgIZbzNkniZQR6tyodwa+wdS+R/yCiywUln5VSgLTlOHN2k5wWro1sZl2bPd rmy2IKM71BrE+8DQyEmdizm/4fue/mESF/WXsIMVms6fCfvhtjMRmTq45vuUhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1696352925; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EyT6amY706fnOb8tyz4K6Ps988LHu0Y9QviEpq9cpwA=; b=4ebn0qAoq8FLG2slc0TWy1XeCcTTsqREpMxSSBCLjhAYPXPySqMWc3NHzGntbSPHesKhnd ADeZprQw6P+1xrgmyeckO006zEAOpqUcriVHwLMXAfxx3119YkaIu6B8lAAMEl99Men2Hc 1TMc9v868NsEHnUDV3+lUDzfek1ytKCd620lvR6TTtejERLU5Iv9gXeF1wifIG0LUkww1r Mpwd0smAVjC/SoGRSK7rusWa8m+WfgQG+z+BXlOg1HAu//wwmhWOh9b6/cOoUWtlJP8MRH FeOJjnoe6dS7E40GbTGuEpH0hsqj2tcjxPB01LUN2OjBDw5NPYFml1UcLfrquQ== ARC-Authentication-Results: i=1; rspamd-7d5dc8fd68-cnbrx; auth=pass smtp.auth=dreamhost smtp.mailfrom=siddhesh@sourceware.org X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org X-MC-Relay: Neutral X-MC-Copy: stored-urls X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-White-Whimsical: 02da3539272cc339_1696352926069_3223694567 X-MC-Loop-Signature: 1696352926069:2497710470 X-MC-Ingress-Time: 1696352926069 Received: from pdx1-sub0-mail-a208.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.120.41.146 (trex/6.9.1); Tue, 03 Oct 2023 17:08:46 +0000 Received: from fedora.redhat.com (bras-vprn-toroon4834w-lp130-02-142-113-138-41.dsl.bell.ca [142.113.138.41]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 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-a208.dreamhost.com (Postfix) with ESMTPSA id 4S0PRd36YdzM7; Tue, 3 Oct 2023 10:08:45 -0700 (PDT) From: Siddhesh Poyarekar To: libc-stable@sourceware.org Cc: Carlos O'Donell Subject: [committed 2.34] tunables: Terminate if end of input is reached (CVE-2023-4911) Date: Tue, 3 Oct 2023 13:08:33 -0400 Message-ID: <20231003170837.64992-3-siddhesh@sourceware.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003170837.64992-1-siddhesh@sourceware.org> References: <20231003170837.64992-1-siddhesh@sourceware.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1172.5 required=5.0 tests=BAYES_00,GIT_PATCH_0,KAM_DMARC_NONE,KAM_DMARC_STATUS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_SOFTFAIL,TXREP 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: The string parsing routine may end up writing beyond bounds of tunestr if the input tunable string is malformed, of the form name=name=val. This gets processed twice, first as name=name=val and next as name=val, resulting in tunestr being name=name=val:name=val, thus overflowing tunestr. Terminate the parsing loop at the first instance itself so that tunestr does not overflow. This also fixes up tst-env-setuid-tunables to actually handle failures correct and add new tests to validate the fix for this CVE. Signed-off-by: Siddhesh Poyarekar Reviewed-by: Carlos O'Donell (cherry picked from commit 1056e5b4c3f2d90ed2b4a55f96add28da2f4c8fa) --- NEWS | 5 +++++ elf/dl-tunables.c | 17 +++++++++------- elf/tst-env-setuid-tunables.c | 37 +++++++++++++++++++++++++++-------- 3 files changed, 44 insertions(+), 15 deletions(-) diff --git a/NEWS b/NEWS index e16f9968f3..625780a01a 100644 --- a/NEWS +++ b/NEWS @@ -55,6 +55,11 @@ Security related changes: an application calls getaddrinfo for AF_INET6 with AI_CANONNAME, AI_ALL and AI_V4MAPPED flags set. + CVE-2023-4911: If a tunable of the form NAME=NAME=VAL is passed in the + environment of a setuid program and NAME is valid, it may result in a + buffer overflow, which could be exploited to achieve escalated + privileges. This flaw was introduced in glibc 2.34. + The following bugs are resolved with this release: [11053] regex: Wrong results with backreferences diff --git a/elf/dl-tunables.c b/elf/dl-tunables.c index 8009e54ee5..837474b504 100644 --- a/elf/dl-tunables.c +++ b/elf/dl-tunables.c @@ -188,11 +188,7 @@ parse_tunables (char *tunestr, char *valstring) /* If we reach the end of the string before getting a valid name-value pair, bail out. */ if (p[len] == '\0') - { - if (__libc_enable_secure) - tunestr[off] = '\0'; - return; - } + break; /* We did not find a valid name-value pair before encountering the colon. */ @@ -252,9 +248,16 @@ parse_tunables (char *tunestr, char *valstring) } } - if (p[len] != '\0') - p += len + 1; + /* We reached the end while processing the tunable string. */ + if (p[len] == '\0') + break; + + p += len + 1; } + + /* Terminate tunestr before we leave. */ + if (__libc_enable_secure) + tunestr[off] = '\0'; } #endif diff --git a/elf/tst-env-setuid-tunables.c b/elf/tst-env-setuid-tunables.c index 05619c9adc..cd4e843640 100644 --- a/elf/tst-env-setuid-tunables.c +++ b/elf/tst-env-setuid-tunables.c @@ -52,6 +52,8 @@ const char *teststrings[] = "glibc.malloc.perturb=0x800:not_valid.malloc.check=2:glibc.malloc.mmap_threshold=4096", "glibc.not_valid.check=2:glibc.malloc.mmap_threshold=4096", "not_valid.malloc.check=2:glibc.malloc.mmap_threshold=4096", + "glibc.malloc.mmap_threshold=glibc.malloc.mmap_threshold=4096", + "glibc.malloc.check=2", "glibc.malloc.garbage=2:glibc.maoc.mmap_threshold=4096:glibc.malloc.check=2", "glibc.malloc.check=4:glibc.malloc.garbage=2:glibc.maoc.mmap_threshold=4096", ":glibc.malloc.garbage=2:glibc.malloc.check=1", @@ -70,6 +72,8 @@ const char *resultstrings[] = "glibc.malloc.perturb=0x800:glibc.malloc.mmap_threshold=4096", "glibc.malloc.mmap_threshold=4096", "glibc.malloc.mmap_threshold=4096", + "glibc.malloc.mmap_threshold=glibc.malloc.mmap_threshold=4096", + "", "", "", "", @@ -84,11 +88,18 @@ test_child (int off) const char *val = getenv ("GLIBC_TUNABLES"); #if HAVE_TUNABLES + printf (" [%d] GLIBC_TUNABLES is %s\n", off, val); + fflush (stdout); if (val != NULL && strcmp (val, resultstrings[off]) == 0) return 0; if (val != NULL) - printf ("[%d] Unexpected GLIBC_TUNABLES VALUE %s\n", off, val); + printf (" [%d] Unexpected GLIBC_TUNABLES VALUE %s, expected %s\n", + off, val, resultstrings[off]); + else + printf (" [%d] GLIBC_TUNABLES environment variable absent\n", off); + + fflush (stdout); return 1; #else @@ -117,21 +128,26 @@ do_test (int argc, char **argv) if (ret != 0) exit (1); - exit (EXIT_SUCCESS); + /* Special return code to make sure that the child executed all the way + through. */ + exit (42); } else { - int ret = 0; - /* Spawn tests. */ for (int i = 0; i < array_length (teststrings); i++) { char buf[INT_BUFSIZE_BOUND (int)]; - printf ("Spawned test for %s (%d)\n", teststrings[i], i); + printf ("[%d] Spawned test for %s\n", i, teststrings[i]); snprintf (buf, sizeof (buf), "%d\n", i); + fflush (stdout); if (setenv ("GLIBC_TUNABLES", teststrings[i], 1) != 0) - exit (1); + { + printf (" [%d] Failed to set GLIBC_TUNABLES: %m", i); + support_record_failure (); + continue; + } int status = support_capture_subprogram_self_sgid (buf); @@ -139,9 +155,14 @@ do_test (int argc, char **argv) if (WEXITSTATUS (status) == EXIT_UNSUPPORTED) return EXIT_UNSUPPORTED; - ret |= status; + if (WEXITSTATUS (status) != 42) + { + printf (" [%d] child failed with status %d\n", i, + WEXITSTATUS (status)); + support_record_failure (); + } } - return ret; + return 0; } } -- 2.41.0