* [PATCH] net: ipv4: Avoid bounds check warning
@ 2022-05-24 7:23 Genjian Zhang
2022-05-26 8:22 ` Paolo Abeni
0 siblings, 1 reply; 2+ messages in thread
From: Genjian Zhang @ 2022-05-24 7:23 UTC (permalink / raw)
To: edumazet, davem, yoshfuji, dsahern, kuba, pabeni
Cc: netdev, linux-kernel, huhai, zhanggenjian123
From: huhai <huhai@kylinos.cn>
Fix the following build warning when CONFIG_IPV6 is not set:
In function ‘fortify_memcpy_chk’,
inlined from ‘tcp_md5_do_add’ at net/ipv4/tcp_ipv4.c:1211:2:
./include/linux/fortify-string.h:328:4: error: call to ‘__write_overflow_field’ declared with attribute warning: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Werror=attribute-warning]
328 | __write_overflow_field(p_size_field, size);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Signed-off-by: huhai <huhai@kylinos.cn>
---
net/ipv4/tcp_ipv4.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 457f5b5d5d4a..ed03b8c48443 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -1207,9 +1207,14 @@ int tcp_md5_do_add(struct sock *sk, const union tcp_md5_addr *addr,
key->prefixlen = prefixlen;
key->l3index = l3index;
key->flags = flags;
+#if IS_ENABLED(CONFIG_IPV6)
memcpy(&key->addr, addr,
(family == AF_INET6) ? sizeof(struct in6_addr) :
sizeof(struct in_addr));
+#else
+ memcpy(&key->addr, addr, sizeof(struct in_addr));
+#endif
+
hlist_add_head_rcu(&key->node, &md5sig->head);
return 0;
}
--
2.27.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] net: ipv4: Avoid bounds check warning
2022-05-24 7:23 [PATCH] net: ipv4: Avoid bounds check warning Genjian Zhang
@ 2022-05-26 8:22 ` Paolo Abeni
0 siblings, 0 replies; 2+ messages in thread
From: Paolo Abeni @ 2022-05-26 8:22 UTC (permalink / raw)
To: Genjian Zhang, edumazet, davem, yoshfuji, dsahern, kuba
Cc: netdev, linux-kernel, huhai
On Tue, 2022-05-24 at 15:23 +0800, Genjian Zhang wrote:
> From: huhai <huhai@kylinos.cn>
>
> Fix the following build warning when CONFIG_IPV6 is not set:
>
> In function ‘fortify_memcpy_chk’,
> inlined from ‘tcp_md5_do_add’ at net/ipv4/tcp_ipv4.c:1211:2:
> ./include/linux/fortify-string.h:328:4: error: call to ‘__write_overflow_field’ declared with attribute warning: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Werror=attribute-warning]
> 328 | __write_overflow_field(p_size_field, size);
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> Signed-off-by: huhai <huhai@kylinos.cn>
> ---
> net/ipv4/tcp_ipv4.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
> index 457f5b5d5d4a..ed03b8c48443 100644
> --- a/net/ipv4/tcp_ipv4.c
> +++ b/net/ipv4/tcp_ipv4.c
> @@ -1207,9 +1207,14 @@ int tcp_md5_do_add(struct sock *sk, const union tcp_md5_addr *addr,
> key->prefixlen = prefixlen;
> key->l3index = l3index;
> key->flags = flags;
> +#if IS_ENABLED(CONFIG_IPV6)
> memcpy(&key->addr, addr,
> (family == AF_INET6) ? sizeof(struct in6_addr) :
> sizeof(struct in_addr));
I'm wondering if you could avoid the extra compiler conditional with
something alike:
memcpy(&key->addr, addr,
(IS_ENABLED(CONFIG_IPV6) && family == AF_INET6) ? sizeof(struct in6_addr) :
sizeof(struct in_addr));
Thanks!
Paolo
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-05-26 8:22 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-24 7:23 [PATCH] net: ipv4: Avoid bounds check warning Genjian Zhang
2022-05-26 8:22 ` Paolo Abeni
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.