From patchwork Thu Feb 15 17:15:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 1899506 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=WLvg5JII; 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 4TbMCQ41Pfz23hm for ; Fri, 16 Feb 2024 04:15:46 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 554273865C22 for ; Thu, 15 Feb 2024 17:15:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 554273865C22 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1708017344; bh=EEqSR3Kt2hsypxBq+9uTSletkTe0FOVRoIXEEvaFW4c=; h=From:To:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=WLvg5JII5OuleFkhRTowL75szAQvF+6PcKmDAwEW5ep+2bl1YVumQnyk4qiEYm3X+ gwl24jGMN88QpSsqc+NATgR6dpi+GB+CCNGWHBAGx64WNsKkslooZrTQKfkZmuT+Vc 53TNgA3tmav/KLibNHo99IrF/ZSE60umnUfJ0OZI= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from caracal.birch.relay.mailchannels.net (caracal.birch.relay.mailchannels.net [23.83.209.30]) by sourceware.org (Postfix) with ESMTPS id 469A7386C588 for ; Thu, 15 Feb 2024 17:15:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 469A7386C588 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 469A7386C588 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=23.83.209.30 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1708017324; cv=pass; b=CY4Sn7e1sgRmLgCNtG4l3CeOZ3qq8s9BdrFZqoOK6QbDNw2qTfc36ThOWxwDaAsnZowr4KVk0sR+1Jf8gqYQHceN4A8c/2qDrfFkfid8XRHedskGOYM9NVYC+1K//0Py5bB9ZJ+WG4996Rx7vdBqWk94x/Btna1jguySa7L5KAE= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1708017324; c=relaxed/simple; bh=Us4k70BqS6jioNCmqY9jdgmvBych4vqTDGXfL97BqQI=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=AQOoIUvvTwyWpDiNe5sGmNjDYVehs00xYZUW6Ix5nPet230ktGhP2DvASv/HGqBtLEnqNy5ejtPRVAaMR9RNabPYbpY2UVFRlhKotc95eVX7W3RqcIBtRJkhB68Sw5Q9/fGK57MzLGXa4/3qrfAbZeYOT2RLfjLmr20Fo/zmdfw= 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 CB7722C1D14 for ; Thu, 15 Feb 2024 17:15:19 +0000 (UTC) Received: from pdx1-sub0-mail-a259.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 39CCA2C202F for ; Thu, 15 Feb 2024 17:15:19 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1708017319; a=rsa-sha256; cv=none; b=DvVOFpp3aYEY0HnLtxctcENo56e2I8sk/k4dTx+KxGsbjod/GMk7OKAZ71LhE0a5RquMps f59i0qocszPDD13ICqPzoth4asPVjPvBWngSPYuHyrHekiWAH8qVy95wvyF/0h6VajwUPw Bd41IqW2mLQVqkp8r2X5VwZ3P6KWAayVMfuQ5InNoT6A7+NI8cab/KcCS87gB9xwoPK+tD mAuzOhwztIpI0ueOuw6bFnj9rwhUhJ39rr3ato+MeB+J2SRHkH2lJ58mmXO89CEWNWXbkc IklyuLBDhBOQ5Jc+9LYY7FjLpdGrIt2fXZgKjgNPfYYtF9jPuGlZeMwHPurnlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1708017319; 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; bh=EEqSR3Kt2hsypxBq+9uTSletkTe0FOVRoIXEEvaFW4c=; b=JRp7X/R2r7441Iv78eMFnbDjkYl4pADJN5UBFyXb4KLyzS8UxSF0mcXDQHe8arblQgDP7j yvKdoaxX2+GCrOWF7+wtCJDLb0g0BOItzwyriQv/wqUuFgFKbZAzIF1FH4f+tWAThI5E84 aphFYb2mQFwRHmuSi0qyXCdWlkdj6LKLVkux4Gs9VN7or0steh8cGwVPnIfVJTiVovzKj1 WdcN5y6a6wLeABo2I2qT4hW4qVwBMT/JxB65RXSmn1IvD7D2flWFDeoQPPFPatUVLbC1xz d265r0I2xglgLpOXVZJfG4xh83QtXYzFmrmWLM3BGu9Uol4g8c4w6TaNlPAOIQ== ARC-Authentication-Results: i=1; rspamd-55b4bfd7cb-v5lrx; 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-Slimy-Gusty: 618326be2e4ff09e_1708017319454_2502250287 X-MC-Loop-Signature: 1708017319454:76962005 X-MC-Ingress-Time: 1708017319454 Received: from pdx1-sub0-mail-a259.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.126.181.84 (trex/6.9.2); Thu, 15 Feb 2024 17:15:19 +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-a259.dreamhost.com (Postfix) with ESMTPSA id 4TbMBt6gXhzFY for ; Thu, 15 Feb 2024 09:15:18 -0800 (PST) From: Siddhesh Poyarekar To: libc-alpha@sourceware.org Subject: [PATCH] cdefs: Drop access attribute for _FORTIFY_SOURCE=3 (BZ #31383) Date: Thu, 15 Feb 2024 12:15:06 -0500 Message-ID: <20240215171506.3154505-1-siddhesh@sourceware.org> X-Mailer: git-send-email 2.43.0 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 --- Tested on x86_64 io/Makefile | 1 + io/tst-read-zero.c | 35 +++++++++++++++++++++++++++++++++++ misc/sys/cdefs.h | 6 +++--- 3 files changed, 39 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..b7657837e2 --- /dev/null +++ b/io/tst-read-zero.c @@ -0,0 +1,35 @@ +/* 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 + +int +do_test (void) +{ + struct test_st {} test_info[16]; + + TEST_VERIFY_EXIT (read (0, 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