From patchwork Mon Feb 26 16:03:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 86394 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 005753858C62 for ; Mon, 26 Feb 2024 16:04:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 005753858C62 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1708963472; bh=rMadsqvLPlyRQiJqZqX97MFwe5hMwXOEASwe5rTScK4=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=wf2bG95DUJ087SRwAeqS/OrZrbrO3JWm8grjsEJSSAnCwaQz/RalBUfpVI77vbPz1 /anHIvUvuOgiZTCOKJUCRWe55yM9ns5wq2t14lWchod6ly1QXRlYY6k0j7H0dKwphs 4dQJZ3W8CaI1iMd4O01GboSFwxURBH7Ir7itPzvE= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from antelope.banana.relay.mailchannels.net (antelope.banana.relay.mailchannels.net [23.83.217.4]) by sourceware.org (Postfix) with ESMTPS id 75B5D3858414 for ; Mon, 26 Feb 2024 16:03:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 75B5D3858414 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 75B5D3858414 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=23.83.217.4 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1708963436; cv=pass; b=HanZ7Afdv6gYKBgj0GfhFeTQ196aLug+sQR6Ah1wPwRTw5SCPscr8Zm7ZJ6jYzHalU9GTj9dt+ZDLDt4C7Z9Dt7rKGB0EBiqDnBE6uN6Kx8qvnUlEl451OoN2//jLbeWxzXCwMJtU/08v0hw6lQpKGCG+CoCFFdxX1SQrw3H9nk= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1708963436; c=relaxed/simple; bh=SL+5zi782AWGccrRNMmPiob2Cw6ikLYxJgRXfPfv9fM=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=BUd3HLxxwwtlSpiS3xK69zVl9PtSS6ioYL1gX2pDgCGYw3N+Rad/TVo6Y1ZrWfPPhwkw7cZTG3oAbfd+T57uoHA7a65ERcI2kSk5P5GdtFye1bZX1uQKRDolZ10y2zEBnIdSP3MBW124X26MKQ8acPWeCYM/0iByfppkNsKn6C8= 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 5D4D22C28FF for ; Mon, 26 Feb 2024 16:03:53 +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 EA9B62C2A2D for ; Mon, 26 Feb 2024 16:03:52 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1708963432; a=rsa-sha256; cv=none; b=XqR9WImLk9tIuzGRK5SMsDR86cx9U1BJBMijTP4dJeJZ612nZQfvGc55ekRFwKa+l+jfXw RFzFozxl9THkWco8HIef0tdcKyucZRR1uY9n8hmwG18+UT82FtlfMtwBow9B1bZ+M0/c1Y tqBrq1rZJ90zcXrrRbs1oxymyo1Wjgw2AAR1rE/LMX3o5BsXlTPFsTgMFdzKNgO1xP8f0x /o/Ka7RFjB5e1VBzd0Dt2zuVCI301rpdYjFqFS5+HM20e7cf1SODj/GdDR3mZHei8emICs qFAYH257LqFrtAKTtK7TDQqegc6ZLY5rf3t5imAlAeW5e7x6rl4hW+cGUEvmdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1708963432; 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=rMadsqvLPlyRQiJqZqX97MFwe5hMwXOEASwe5rTScK4=; b=wHvq1DSPGGYN7yZu3Y3mzil3NgMAueF31wUBwo7W5m1XZJ0iZyaxmHicoJW2Pv1MyEq9CG VFQxkeoOux4hk2+M0/uh35V8wYjfHqLsRHzFfmRRgk0JvF2H8CW4bSruSszlDYptAR1hSp Jn8/MwJr728d8aJeUPnHeGXemXB8O2JEdLYgcf1sxXzazZswktwVrRhwLte4CGdbffd0cY ilASkRJUPblOtcx4+YkUs8WzGvO5P/7o0J9NbJmT3q9TGvJBr670kKeoC/GomcRzp8Hi9o ppmD0vna1E425pQbidvAcyG5Ek1dAzFMayPtRrYeLfUUZSdsJS+GfLVRHmbAGQ== ARC-Authentication-Results: i=1; rspamd-55b4bfd7cb-hrr5m; auth=pass smtp.auth=dreamhost smtp.mailfrom=siddhesh@sourceware.org X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org X-MC-Relay: Bad X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Spill-Left: 78eb803f0e7964da_1708963433212_207770179 X-MC-Loop-Signature: 1708963433212:3570928166 X-MC-Ingress-Time: 1708963433212 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.124.220.191 (trex/6.9.2); Mon, 26 Feb 2024 16:03:53 +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 4Tk55N4YDxz2k for ; Mon, 26 Feb 2024 08:03:52 -0800 (PST) From: Siddhesh Poyarekar To: libc-alpha@sourceware.org Subject: [PATCH v3] cdefs: Drop access attribute for _FORTIFY_SOURCE=3 (BZ #31383) Date: Mon, 26 Feb 2024 11:03:44 -0500 Message-ID: <20240226160344.3519392-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.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_DNSWL_NONE, 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+patchwork=sourceware.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 Reviewed-by: Adhemerval Zanella --- Changes from v2: - Use supported-fortify to set the right fortification level for the compiler. Changes from v1: - Adjust test to read from /dev/zero io/Makefile | 2 ++ io/tst-read-zero.c | 39 +++++++++++++++++++++++++++++++++++++++ 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..19932d50f7 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 \ @@ -290,6 +291,7 @@ CFLAGS-read.c += -fexceptions -fasynchronous-unwind-tables $(config-cflags-wno-i CFLAGS-write.c += -fexceptions -fasynchronous-unwind-tables $(config-cflags-wno-ignored-attributes) CFLAGS-close.c += -fexceptions -fasynchronous-unwind-tables CFLAGS-lseek64.c += $(config-cflags-wno-ignored-attributes) +CFLAGS-tst-read-zero.c += $(no-fortify-source),-D_FORTIFY_SOURCE=$(supported-fortify) CFLAGS-test-stat.c += -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE CFLAGS-test-lfs.c += -D_LARGEFILE64_SOURCE diff --git a/io/tst-read-zero.c b/io/tst-read-zero.c new file mode 100644 index 0000000000..8d1d30a543 --- /dev/null +++ b/io/tst-read-zero.c @@ -0,0 +1,39 @@ +/* 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. */ +#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