From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dormouse.elm.relay.mailchannels.net (dormouse.elm.relay.mailchannels.net [23.83.212.50]) by sourceware.org (Postfix) with ESMTPS id 71A553858CD1 for ; Tue, 3 Oct 2023 18:49:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 71A553858CD1 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gotplt.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gotplt.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 407DD3626AF; Tue, 3 Oct 2023 18:48:59 +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 B9DD93626C9; Tue, 3 Oct 2023 18:48:58 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1696358938; a=rsa-sha256; cv=none; b=P1pjnKayG65QuakxKj74Yaxws6u5sxiqoeo36jLbwDvQVyzEURUynuRVvzn8Fga4268U52 Xg0Tja9nsYDLLfy0eAIr1l+NoPowJHuV9gQ/jm/4Pb8rUEIOG0IlUm3oUnlblNwUxsmP7c NBDmB7J+P63dEIAlZd9JEzI5DVTVvS1lr9hpU8ELeGtvRgtxW6O+urzKSIyKVm3VYCTwp7 wa7sLiBgUMvnp6oPJmQRt/32Sd6Qrd36q88f2qUDm/Xq1GdEAsVj+altIJMegkRQagPoqT 0x4JbZ7cDm6g6CkbMXhp5lSAOAT4b2MliSBqqx9L/bYJUkxKiFCcej10BriMQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1696358938; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=bkwZeGsP7MZ1L1SmTXEtey+H5qwyAtwu+bAxIeElrsw=; b=OlTgB9g+aftow9j0pjXy8rHv4ptjqvna9kDIGzIna3GR+HIElrNFmZCWSfX9z8mme0FETf BeVR7jKhJNYpKcaV1TiloZl/Tmy9mTR3eZ/+QAmbDioRm5p6zYjmLDmP56KCrqcDAjHT4P uKp5Acqvx8uYPVjPY0DE69SGZI7qBmyjZIWBBnmZg8Ua9HW9y2IWu0KJMqMnlOQKi+g2TW ZcSZ9PQBmRr7RBnbWZ/uZu2TC2Ccmf4EviiHFSJA0ESDl53GHdI55VWSGUm4JJ7gnlVis3 xRE0/qaKIAtYSXImEjJ0SGyT2fv6FmViJVT0U0iM+dXdVcf5unrhqXkgVjcgGw== ARC-Authentication-Results: i=1; rspamd-7c449d4847-kphpl; auth=pass smtp.auth=dreamhost smtp.mailfrom=siddhesh@gotplt.org X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Snatch-Rock: 767fd89f39f926e8_1696358938992_1226502547 X-MC-Loop-Signature: 1696358938992:35813326 X-MC-Ingress-Time: 1696358938992 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.104.112.136 (trex/6.9.1); Tue, 03 Oct 2023 18:48:58 +0000 Received: from [192.168.2.12] (bras-vprn-toroon4834w-lp130-02-142-113-138-41.dsl.bell.ca [142.113.138.41]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a208.dreamhost.com (Postfix) with ESMTPSA id 4S0RgG2n2Pzn8; Tue, 3 Oct 2023 11:48:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gotplt.org; s=dreamhost; t=1696358938; bh=bkwZeGsP7MZ1L1SmTXEtey+H5qwyAtwu+bAxIeElrsw=; h=Date:Subject:To:From:Content-Type:Content-Transfer-Encoding; b=XTwx6+fir0RNKSuby+Bgl9AiZA8SPZvMaPjOApmuiZqMxe7PyLL0UVZPpgCFA6aK/ dRiJnX24K/5KItyXXjzGUO22w8NVgERpqSc4jDDwbCc81SOLxqZGPgZ/1hdoaka+Aj bqkzKmrM8ozsb2My1OM6/LNl8COp6gIImgX0geEuHmkcbX1VChJ0a3a5jTkzir1Xs8 SAKGVdhfXKfPSHnzOTIMaN0y0oQWRUpZoD2fDNo3Rxl5l+d95ebccUHcicfgGcAtG3 p/KS6755PqIyRCexiHwXTkeJNAhR0rEHImyj032jw6BbKQAeLE+Nk7hCv3zZrlb7lF IJJJwcM5qj8Zg== Message-ID: Date: Tue, 3 Oct 2023 14:48:56 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [PATCH] debug: Add regression tests for BZ 30932 Content-Language: en-US To: Adhemerval Zanella , libc-alpha@sourceware.org References: <20231003181346.3726845-1-adhemerval.zanella@linaro.org> From: Siddhesh Poyarekar In-Reply-To: <20231003181346.3726845-1-adhemerval.zanella@linaro.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3036.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_NUMSUBJECT,KAM_SHORT,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS,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: On 2023-10-03 14:13, Adhemerval Zanella wrote: > Checked on x86_64-linux-gnu. > --- Reviewed-by: Siddhesh Poyarekar > debug/Makefile | 5 ++ > debug/tst-sprintf-fortify-rdonly.c | 82 ++++++++++++++++++++++++++++++ > 2 files changed, 87 insertions(+) > create mode 100644 debug/tst-sprintf-fortify-rdonly.c > > diff --git a/debug/Makefile b/debug/Makefile > index 434e52f780..d7e021a1c8 100644 > --- a/debug/Makefile > +++ b/debug/Makefile > @@ -178,6 +178,7 @@ CFLAGS-tst-longjmp_chk3.c += -fexceptions -fasynchronous-unwind-tables > CPPFLAGS-tst-longjmp_chk3.c += $(no-fortify-source),-D_FORTIFY_SOURCE=1 > CPPFLAGS-tst-realpath-chk.c += $(no-fortify-source),-D_FORTIFY_SOURCE=2 > CPPFLAGS-tst-chk-cancel.c += $(no-fortify-source),-D_FORTIFY_SOURCE=2 > +CFLAGS-tst-sprintf-fortify-rdonly.c += $(no-fortify-source),-D_FORTIFY_SOURCE=2 > > # _FORTIFY_SOURCE tests. > # Auto-generate tests for _FORTIFY_SOURCE for different levels, compilers and > @@ -284,6 +285,7 @@ tests = \ > tst-longjmp_chk \ > tst-longjmp_chk2 \ > tst-realpath-chk \ > + tst-sprintf-fortify-rdonly \ > tst-sprintf-fortify-unchecked \ > # tests > > @@ -291,6 +293,9 @@ tests-time64 += \ > $(tests-all-time64-chk) \ > # tests-time64 > > +tests-container += \ > + # tests-container > + > ifeq ($(have-ssp),yes) > tests += tst-ssp-1 > endif > diff --git a/debug/tst-sprintf-fortify-rdonly.c b/debug/tst-sprintf-fortify-rdonly.c > new file mode 100644 > index 0000000000..7d5c447598 > --- /dev/null > +++ b/debug/tst-sprintf-fortify-rdonly.c > @@ -0,0 +1,82 @@ > +/* Testcase for BZ 30932. > + Copyright (C) 2023 Free Software Foundation, Inc. > + This file is part of the GNU C Library. > + > + The GNU C Library is free software; you can redistribute it and/or > + modify it under the terms of the GNU Lesser General Public > + License as published by the Free Software Foundation; either > + version 2.1 of the License, or (at your option) any later version. > + > + The GNU C Library is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + Lesser General Public License for more details. > + > + You should have received a copy of the GNU Lesser General Public > + License along with the GNU C Library; if not, see > + . */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include > +#include > +#include > + > +jmp_buf chk_fail_buf; > +bool chk_fail_ok; > + > +const char *str2 = "F"; > +char buf2[10] = "%s"; > + > +static int > +do_test (void) > +{ > + struct rlimit rl; > + int max_fd = 24; > + > + if (getrlimit (RLIMIT_NOFILE, &rl) == -1) > + FAIL_EXIT1 ("getrlimit (RLIMIT_NOFILE): %m"); > + > + max_fd = (rl.rlim_cur < max_fd ? rl.rlim_cur : max_fd); > + rl.rlim_cur = max_fd; > + > + if (setrlimit (RLIMIT_NOFILE, &rl) == 1) > + FAIL_EXIT1 ("setrlimit (RLIMIT_NOFILE): %m"); > + > + /* Exhaust the file descriptor limit with temporary files. */ > + int nfiles = 0; > + for (; nfiles < max_fd; nfiles++) > + { > + int fd = create_temp_file ("tst-spawn3.", NULL); > + if (fd == -1) > + { > + if (errno != EMFILE) > + FAIL_EXIT1 ("create_temp_file: %m"); > + break; > + } > + } > + TEST_VERIFY_EXIT (nfiles != 0); > + > + /* When the format string is writable and contains %n, > + with -D_FORTIFY_SOURCE=2 it causes __chk_fail. However, if libc can not > + open procfs to check if the input format string in within a writable > + memory segment, the fortify version can not perform the check. */ > + char buf[128]; > + int n1; > + int n2; > + > + strcpy (buf2 + 2, "%n%s%n"); > + if (sprintf (buf, buf2, str2, &n1, str2, &n2) != 2 > + || n1 != 1 || n2 != 2) > + FAIL_EXIT1 ("sprintf failed: %s %d %d", buf, n1, n2); > + > + return 0; > +} > + > +#include