From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3BA53C001DB for ; Tue, 8 Aug 2023 16:41:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233264AbjHHQlw (ORCPT ); Tue, 8 Aug 2023 12:41:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232268AbjHHQlI (ORCPT ); Tue, 8 Aug 2023 12:41:08 -0400 Received: from Chamillionaire.breakpoint.cc (Chamillionaire.breakpoint.cc [IPv6:2a0a:51c0:0:237:300::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2EE415B8C; Tue, 8 Aug 2023 08:54:50 -0700 (PDT) Received: from fw by Chamillionaire.breakpoint.cc with local (Exim 4.92) (envelope-from ) id 1qTP2U-0001Au-Qj; Tue, 08 Aug 2023 17:54:30 +0200 Date: Tue, 8 Aug 2023 17:54:30 +0200 From: Florian Westphal To: "GONG, Ruiqi" Cc: Pablo Neira Ayuso , Jozsef Kadlecsik , Florian Westphal , Roopa Prabhu , Nikolay Aleksandrov , Kees Cook , netfilter-devel@vger.kernel.org, coreteam@netfilter.org, netdev@vger.kernel.org, linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, Wang Weiyang , Xiu Jianfeng Subject: Re: [PATCH] netfilter: ebtables: fix fortify warnings Message-ID: <20230808155430.GB9741@breakpoint.cc> References: <20230808014821.241688-1-gongruiqi@huaweicloud.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20230808014821.241688-1-gongruiqi@huaweicloud.com> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org GONG, Ruiqi wrote: > From: "GONG, Ruiqi" > > When compiling with gcc 13 and CONFIG_FORTIFY_SOURCE=y, the following > warning appears: > > In function ‘fortify_memcpy_chk’, > inlined from ‘size_entry_mwt’ at net/bridge/netfilter/ebtables.c:2118:2: > ./include/linux/fortify-string.h:592:25: error: call to ‘__read_overflow2_field’ > declared with attribute warning: detected read beyond size of field (2nd parameter); > maybe use struct_group()? [-Werror=attribute-warning] > 592 | __read_overflow2_field(q_size_field, size); > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > The compiler is complaining: > > memcpy(&offsets[1], &entry->watchers_offset, > sizeof(offsets) - sizeof(offsets[0])); > > where memcpy reads beyong &entry->watchers_offset to copy > {watchers,target,next}_offset altogether into offsets[]. Silence the > warning by wrapping these three up via struct_group(). > > Signed-off-by: GONG, Ruiqi > --- > include/uapi/linux/netfilter_bridge/ebtables.h | 14 ++++++++------ > net/bridge/netfilter/ebtables.c | 3 +-- > 2 files changed, 9 insertions(+), 8 deletions(-) > > diff --git a/include/uapi/linux/netfilter_bridge/ebtables.h b/include/uapi/linux/netfilter_bridge/ebtables.h > index a494cf43a755..e634da196d08 100644 > --- a/include/uapi/linux/netfilter_bridge/ebtables.h > +++ b/include/uapi/linux/netfilter_bridge/ebtables.h > @@ -182,12 +182,14 @@ struct ebt_entry { > unsigned char sourcemsk[ETH_ALEN]; > unsigned char destmac[ETH_ALEN]; > unsigned char destmsk[ETH_ALEN]; > - /* sizeof ebt_entry + matches */ > - unsigned int watchers_offset; > - /* sizeof ebt_entry + matches + watchers */ > - unsigned int target_offset; > - /* sizeof ebt_entry + matches + watchers + target */ > - unsigned int next_offset; > + struct_group(offsets, > + /* sizeof ebt_entry + matches */ This is an UAPI header, I think you need to use __struct_group here.