From patchwork Fri Feb 16 16:44:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 1900189 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=YncHzLua; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Tbyc83rGgz23hm for ; Sat, 17 Feb 2024 03:50:48 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 576883857C4F for ; Fri, 16 Feb 2024 16:50:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 576883857C4F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1708102246; bh=pnnBMEmnhvBT/yhmyHhJA3sl4N7yjewDVjfzUR73iFQ=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=YncHzLua0LvTUD5HRGeZKWjTc75/iQbdI2VhqNNa2EahhbqeAeXcQ3Ks7Y7WKWbi3 qbkUULWE0GeITQMtPA44Ec0/3E+GlCe0z5yr3gdoYpcomxvsw+tNk6hf+LVoh/y2Mc g3Ltl4O2Rkkb58rRoACK5cfiKypIkT2ji81Pifyw= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from bumble.maple.relay.mailchannels.net (bumble.maple.relay.mailchannels.net [23.83.214.25]) by sourceware.org (Postfix) with ESMTPS id 58F97385800C for ; Fri, 16 Feb 2024 16:50:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 58F97385800C Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=sourceware.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=sourceware.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 58F97385800C Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=23.83.214.25 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1708102223; cv=pass; b=tKbZS2ydlWIw0dxidq6xt5WB4LNYBCG26K0O24rjHdp7j7TIQyegZ+102/PyOftW3i5lsAlrY/xdt95CH0TO26HFEYg357m3hZAdEG4/xbvFrQj3FdBY4fSRuTc6mWeiHbLxLHizS2oBFjkZrCtz1i4PV2ynMuGTtFNXLaFiYVY= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1708102223; c=relaxed/simple; bh=kajrRO/1q7JjPatAPAkM8v/7w+jsGEMQtXeIV4BSyNA=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=oj90DAv0YcQhvD1UfjSTckctCXrRn+8VCrpi3f9/Wdu4sqEbzt4+Fhcqby8mmUQZo7qV6S85pBH44EP7QyU1/Jnkj7bs0CBWfOi6yx/aGpZO37mk/dJOV9preQ67nRKMiMmGA0Gl8fPKa/9DgEldK5829virTLxxpmxgnUx5c4E= ARC-Authentication-Results: i=2; server2.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 1E5C3103FE6 for ; Fri, 16 Feb 2024 16:44:19 +0000 (UTC) Received: from pdx1-sub0-mail-a232.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 4D29D1040C7 for ; Fri, 16 Feb 2024 16:44:17 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1708101857; a=rsa-sha256; cv=none; b=plkzxDR+b0u3ug1aBFPGmcru97WR3tvvY4wPYmMJGAas9jZ1k6tZLwVMQxmskV9AOgqxAo 2YMMo085kbqc3lCEQGqgqE/Hz5cvJ95dnFYtquS6nZkjQwjiQTCwV2I5sxZL+qZ4JISyug tSHm/afKZzZ8VjhpSCN1WEgViA+PVj9gjYfTAeMKnSs3D3KIzB+Hhm2gKuw6QTbEUhDlzO Bfkjud0S4RQCGLGQYk62UfcOtEhRmfSdrMfjYpO9ChXsaruenCCzbEtobyJqLRAkHzHzt2 rIvzb1+IAhtJBR3FJGPzod+hZv/SKutskNM612Urmt8KmsSjZ9HaDPnldiSceQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1708101857; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pnnBMEmnhvBT/yhmyHhJA3sl4N7yjewDVjfzUR73iFQ=; b=17+icSZ5ZhaQZEYiBUh4bSJK/rQL9N30drTNgaiZfpQxRv8O2ufrppdIZXEm3AUycQJj7e kQNKCA5f+UXauxBibzhgZd0NvNnmsRfNDRSPPDHQM8lNPp9Vfz/SdnxTnjmoMIhMRisgnl TUfd+qviLBNtv3C5ZBmLfHYngegFiMk/hHHrl8b03neyhwFQs6dHWQiOHeC4xkPEC+qdJe XpX/V0sjOzOpt2vlkHS3A0J9CYc4YvTJDBF5SlX5wgbqCIVofXXmsw0JZfh+PpGT1S+IDV ZA5tiAvZY/b8HoO1NpYJGhXsuqkb3vgDNZ2urO8xc8X8ZwAL3g3IZqBGjzJkTA== ARC-Authentication-Results: i=1; rspamd-55b4bfd7cb-pj7rr; auth=pass smtp.auth=dreamhost smtp.mailfrom=siddhesh@sourceware.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-Vacuous-Wipe: 2f0fa7ca3c763412_1708101857532_767739413 X-MC-Loop-Signature: 1708101857532:1624126886 X-MC-Ingress-Time: 1708101857532 Received: from pdx1-sub0-mail-a232.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.126.119.136 (trex/6.9.2); Fri, 16 Feb 2024 16:44:17 +0000 Received: from fedora.redhat.com (unknown [76.68.24.30]) (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-a232.dreamhost.com (Postfix) with ESMTPSA id 4TbySd09sHz1y for ; Fri, 16 Feb 2024 08:44:16 -0800 (PST) From: Siddhesh Poyarekar To: libc-alpha@sourceware.org Subject: [PATCH v2] cdefs: Drop access attribute for _FORTIFY_SOURCE=3 (BZ #31383) Date: Fri, 16 Feb 2024 11:44:01 -0500 Message-ID: <20240216164401.3184063-1-siddhesh@sourceware.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240215171506.3154505-1-siddhesh@sourceware.org> References: <20240215171506.3154505-1-siddhesh@sourceware.org> MIME-Version: 1.0 X-Spam-Status: No, score=-1171.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_SOFTFAIL, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org When passed a pointer to a zero-sized struct, the access attribute without the third argument misleads -Wstringop-overflow diagnostics to think that a function is writing 1 byte into the zero-sized structs. The attribute doesn't add that much value in this context, so drop it completely for _FORTIFY_SOURCE=3. Resolves: BZ #31383 Signed-off-by: Siddhesh Poyarekar --- Changes from v1: - Adjust test to read from /dev/zero io/Makefile | 1 + io/tst-read-zero.c | 40 ++++++++++++++++++++++++++++++++++++++++ misc/sys/cdefs.h | 6 +++--- 3 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 io/tst-read-zero.c diff --git a/io/Makefile b/io/Makefile index 54d950d51f..2a52b66255 100644 --- a/io/Makefile +++ b/io/Makefile @@ -215,6 +215,7 @@ tests := \ tst-openat \ tst-posix_fallocate \ tst-posix_fallocate64 \ + tst-read-zero \ tst-readlinkat \ tst-renameat \ tst-stat \ diff --git a/io/tst-read-zero.c b/io/tst-read-zero.c new file mode 100644 index 0000000000..9442f94e5d --- /dev/null +++ b/io/tst-read-zero.c @@ -0,0 +1,40 @@ +/* read smoke test for 0-sized structures. + Copyright The GNU Toolchain Authors. + 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 + . */ + +/* Zero-sized structures should not result in any overflow warnings or + errors when fortification is enabled. */ +#define _FORTIFY_SOURCE 3 +#include +#include +#include +#include + +int +do_test (void) +{ + struct test_st {} test_info[16]; + int fd = open ("/dev/zero", O_RDONLY, 0); + + if (fd == -1) + FAIL_UNSUPPORTED ("Unable to open /dev/zero: %m"); + + TEST_VERIFY_EXIT (read (fd, test_info, sizeof(test_info)) == 0); + return 0; +} + +#include diff --git a/misc/sys/cdefs.h b/misc/sys/cdefs.h index 520231dbea..800c44640f 100644 --- a/misc/sys/cdefs.h +++ b/misc/sys/cdefs.h @@ -683,10 +683,10 @@ _Static_assert (0, "IEEE 128-bits long double requires redirection on this platf # define __attr_access(x) __attribute__ ((__access__ x)) /* For _FORTIFY_SOURCE == 3 we use __builtin_dynamic_object_size, which may use the access attribute to get object sizes from function definition - arguments, so we can't use them on functions we fortify. Drop the object - size hints for such functions. */ + arguments, so we can't use them on functions we fortify. Drop the access + attribute for such functions. */ # if __USE_FORTIFY_LEVEL == 3 -# define __fortified_attr_access(a, o, s) __attribute__ ((__access__ (a, o))) +# define __fortified_attr_access(a, o, s) # else # define __fortified_attr_access(a, o, s) __attr_access ((a, o, s)) # endif