pfcp: avoid copy warning by simplifing code
Subsystems (2)
PATCH v2 1/1 pfcp: avoid copy warning by simplifing code
From Arnd comments:
"The memcpy() in the ip_tunnel_info_opts_set() causes a string.h fortification warning, with at least gcc-13:
In function 'fortify_memcpy_chk',
inlined from 'ip_tunnel_info_opts_set' at include/net/ip_tunnels.h:619:3,
inlined from 'pfcp_encap_recv' at drivers/net/pfcp.c:84:2:
include/linux/fortify-string.h:553:25: 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]
553 | __write_overflow_field(p_size_field, size);"
It is a false-positivie caused by ambiguity of the union.
However, as Arnd noticed, copying here is unescessary. The code can be simplified to avoid calling ip_tunnel_info_opts_set(), which is doing copying, setting flags and options_len.
Set correct flags and options_len directly on tun_info.
---
v1 --> v2:
Links: https://lore.kernel.org/netdev/Zg6yMB%2F3w4EBQVDm@mev-dev/
* Add Fixes and Closes tag
--- drivers/net/pfcp.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/net/pfcp.c +2 -3
@@ -80,9 +80,8 @@ static int pfcp_encap_recv(struct sock *sk, struct sk_buff *skb) elsepfcp_node_recv (pfcp ,skb ,md ); -__set_bit (IP_TUNNEL_PFCP_OPT_BIT , flags); -ip_tunnel_info_opts_set (&tun_dst->u.tun_info, md,sizeof (*md), - flags); +__set_bit (IP_TUNNEL_PFCP_OPT_BIT , tun_dst->u.tun_info.key.tun_flags); + tun_dst->u.tun_info.options_len =sizeof (*md); if (unlikely(iptunnel_pull_header(skb, PFCP_HLEN, skb->protocol, !net_eq(sock_net(sk),
Signature · 1 line
2.42.0
Quoted 16 lines · Michal Swiatkowski
Quoted 1 line
From Arnd comments:
"The
memcpy()in theip_tunnel_info_opts_set()causes astring.hfortification warning, with at least gcc-13:In function '
fortify_memcpy_chk',
inlined from 'ip_tunnel_info_opts_set' atinclude/net/ip_tunnels.h:619:3,
inlined from 'pfcp_encap_recv' atdrivers/net/pfcp.c:84:2:
include/linux/fortify-string.h:553:25: error: call to '__write_overflow_field' declared with attribute warning: detected write beyond size of field (1st parameter); maybe usestruct_group()? [-Werror=attribute-warning]
553 |__write_overflow_field(p_size_field, size);"It is a false-positivie caused by ambiguity of the union.
However, as Arnd noticed, copying here is unescessary. The code can be simplified to avoid calling
ip_tunnel_info_opts_set(), which is doing copying, setting flags andoptions_len.
Quoted 7 lines
Set correct flags and
options_lendirectly ontun_info.Fixes 6dd514f48110 ("pfcp: always set pfcp metadata")Reported-by Arnd Bergmann <[email protected]>Acked-by Arnd Bergmann <[email protected]>Signed-off-by Michal Swiatkowski <[email protected]>
I agree that it's nice to avoid a copy.
But I do wonder where else this pattern may exist. And if it might be worth introducing a helper for it.
Regardless, this looks good to me.
...
Quoted 25 lines · Simon Horman
Quoted 16 lines · Michal Swiatkowski
Quoted 1 line
From Arnd comments:
"The
memcpy()in theip_tunnel_info_opts_set()causes astring.hfortification warning, with at least gcc-13:In function '
fortify_memcpy_chk',
inlined from 'ip_tunnel_info_opts_set' atinclude/net/ip_tunnels.h:619:3,
inlined from 'pfcp_encap_recv' atdrivers/net/pfcp.c:84:2:
include/linux/fortify-string.h:553:25: error: call to '__write_overflow_field' declared with attribute warning: detected write beyond size of field (1st parameter); maybe usestruct_group()? [-Werror=attribute-warning]
553 |__write_overflow_field(p_size_field, size);"It is a false-positivie caused by ambiguity of the union.
However, as Arnd noticed, copying here is unescessary. The code can be simplified to avoid calling
ip_tunnel_info_opts_set(), which is doing copying, setting flags andoptions_len.Quoted 7 lines
Set correct flags and
options_lendirectly ontun_info.Fixes 6dd514f48110 ("pfcp: always set pfcp metadata")Reported-by Arnd Bergmann <[email protected]>Acked-by Arnd Bergmann <[email protected]>Signed-off-by Michal Swiatkowski <[email protected]>
Quoted 3 lines
I agree that it's nice to avoid a copy.
But I do wonder where else this pattern may exist. And if it might be worth introducing a helper for it.
Right, the same is done in vxlan, ip_gre and ip6_gre at least. I will send v3 with helper.
Thanks,
Michal
Quoted 6 lines
Regardless, this looks good to me.
Reviewed-by Simon Horman <[email protected]>...
From: Michal Swiatkowski <[email protected]>
Date: Mon, 8 Apr 2024 12:46:42 +0200
Quoted 26 lines · Simon Horman
Quoted 25 lines · Michal Swiatkowski
Quoted 23 lines
Quoted 1 line
From Arnd comments:
"The
memcpy()in theip_tunnel_info_opts_set()causes astring.hfortification warning, with at least gcc-13:In function '
fortify_memcpy_chk',
inlined from 'ip_tunnel_info_opts_set' atinclude/net/ip_tunnels.h:619:3,
inlined from 'pfcp_encap_recv' atdrivers/net/pfcp.c:84:2:
include/linux/fortify-string.h:553:25: error: call to '__write_overflow_field' declared with attribute warning: detected write beyond size of field (1st parameter); maybe usestruct_group()? [-Werror=attribute-warning]
553 |__write_overflow_field(p_size_field, size);"It is a false-positivie caused by ambiguity of the union.
However, as Arnd noticed, copying here is unescessary. The code can be simplified to avoid calling
ip_tunnel_info_opts_set(), which is doing copying, setting flags andoptions_len.Set correct flags and
options_lendirectly ontun_info.Fixes 6dd514f48110 ("pfcp: always set pfcp metadata")Reported-by Arnd Bergmann <[email protected]>Acked-by Arnd Bergmann <[email protected]>Signed-off-by Michal Swiatkowski <[email protected]>
Quoted 6 lines
Quoted 3 lines
I agree that it's nice to avoid a copy.
But I do wonder where else this pattern may exist. And if it might be worth introducing a helper for it.Right, the same is done in vxlan,
ip_greandip6_great least. I will send v3 with helper.
Dave applied v2 already, so send this helper as a general improvement w/o "Fixes:" :D
Quoted 10 lines
Thanks,
MichalQuoted 6 lines
Regardless, this looks good to me.
Reviewed-by Simon Horman <[email protected]>...
Thanks,
Olek
Quoted 33 lines · Alexander Lobakin
From: Michal Swiatkowski <[email protected]>
Date: Mon, 8 Apr 2024 12:46:42 +0200Quoted 30 lines · Simon Horman
Quoted 28 lines · Michal Swiatkowski
Quoted 16 lines
Quoted 1 line
From Arnd comments:
"The
memcpy()in theip_tunnel_info_opts_set()causes astring.hfortification warning, with at least gcc-13:In function '
fortify_memcpy_chk',
inlined from 'ip_tunnel_info_opts_set' atinclude/net/ip_tunnels.h:619:3,
inlined from 'pfcp_encap_recv' atdrivers/net/pfcp.c:84:2:
include/linux/fortify-string.h:553:25: error: call to '__write_overflow_field' declared with attribute warning: detected write beyond size of field (1st parameter); maybe usestruct_group()? [-Werror=attribute-warning]
553 |__write_overflow_field(p_size_field, size);"It is a false-positivie caused by ambiguity of the union.
However, as Arnd noticed, copying here is unescessary. The code can be simplified to avoid calling
ip_tunnel_info_opts_set(), which is doing copying, setting flags andoptions_len.Quoted 7 lines
Set correct flags and
options_lendirectly ontun_info.Fixes 6dd514f48110 ("pfcp: always set pfcp metadata")Reported-by Arnd Bergmann <[email protected]>Acked-by Arnd Bergmann <[email protected]>Signed-off-by Michal Swiatkowski <[email protected]>I agree that it's nice to avoid a copy.
But I do wonder where else this pattern may exist. And if it might be worth introducing a helper for it.
Quoted 6 lines
Quoted 2 lines
Right, the same is done in vxlan,
ip_greandip6_great least. I will send v3 with helper.Dave applied v2 already, so send this helper as a general improvement w/o "Fixes:" :D
I missed that, thanks :) . So, I will send new patch.
Quoted 13 lines
Quoted 10 lines
Thanks,
MichalQuoted 6 lines
Regardless, this looks good to me.
Reviewed-by Simon Horman <[email protected]>...
Thanks,
Olek
This patch was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:
Quoted 11 lines · On Fri, 5 Apr 2024 08:36:05 +0200 you wrote:
From Arnd comments:
"Thememcpy()in theip_tunnel_info_opts_set()causes astring.hfortification warning, with at least gcc-13:In function '
fortify_memcpy_chk',
inlined from 'ip_tunnel_info_opts_set' atinclude/net/ip_tunnels.h:619:3,
inlined from 'pfcp_encap_recv' atdrivers/net/pfcp.c:84:2:
include/linux/fortify-string.h:553:25: error: call to '__write_overflow_field' declared with attribute warning: detected write beyond size of field (1st parameter); maybe usestruct_group()? [-Werror=attribute-warning]
553 |__write_overflow_field(p_size_field, size);"[...]
Here is the summary with links:
- [net-next,v2] pfcp: avoid copy warning by simplifing code
https://git.kernel.org/netdev/net-next/c/cd8a34cbc853
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html