[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Tue, 8 Aug 2023 17:54:30 +0200
From: Florian Westphal <fw@...len.de>
To: "GONG, Ruiqi" <gongruiqi@...weicloud.com>
Cc: Pablo Neira Ayuso <pablo@...filter.org>,
Jozsef Kadlecsik <kadlec@...filter.org>,
Florian Westphal <fw@...len.de>, Roopa Prabhu <roopa@...dia.com>,
Nikolay Aleksandrov <razor@...ckwall.org>,
Kees Cook <keescook@...omium.org>, netfilter-devel@...r.kernel.org,
coreteam@...filter.org, netdev@...r.kernel.org,
linux-hardening@...r.kernel.org, linux-kernel@...r.kernel.org,
Wang Weiyang <wangweiyang2@...wei.com>,
Xiu Jianfeng <xiujianfeng@...wei.com>
Subject: Re: [PATCH] netfilter: ebtables: fix fortify warnings
GONG, Ruiqi <gongruiqi@...weicloud.com> wrote:
> From: "GONG, Ruiqi" <gongruiqi1@...wei.com>
>
> 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 <gongruiqi1@...wei.com>
> ---
> 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.
Powered by blists - more mailing lists