netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: asix: fix fortify warning
@ 2023-12-06 13:38 Dmitry Antipov
  2023-12-09  0:07 ` Jakub Kicinski
  0 siblings, 1 reply; 5+ messages in thread
From: Dmitry Antipov @ 2023-12-06 13:38 UTC (permalink / raw)
  To: Łukasz Stelmach; +Cc: netdev, Dmitry Antipov

When compiling with gcc version 14.0.0 20231129 (experimental) and
CONFIG_FORTIFY_SOURCE=y, I've noticed the following warning:

...
In function 'fortify_memcpy_chk',
    inlined from 'ax88796c_tx_fixup' at drivers/net/ethernet/asix/ax88796c_main.c:287:2:
./include/linux/fortify-string.h:588:25: warning: call to '__read_overflow2_field'
declared with attribute warning: detected read beyond size of field (2nd parameter);
maybe use struct_group()? [-Wattribute-warning]
  588 |                         __read_overflow2_field(q_size_field, size);
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...

This call to 'memcpy()' is interpreted as an attempt to copy TX_OVERHEAD
(which is 8) bytes from 4-byte 'sop' field of 'struct tx_pkt_info' and
thus overread warning is issued. Since we actually wants to copy both
'sop' and 'seg' fields at once, use the convenient 'struct_group()' here.

Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
---
 drivers/net/ethernet/asix/ax88796c_main.c | 2 +-
 drivers/net/ethernet/asix/ax88796c_main.h | 6 ++++--
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/asix/ax88796c_main.c b/drivers/net/ethernet/asix/ax88796c_main.c
index e551ffaed20d..11e8996b33d7 100644
--- a/drivers/net/ethernet/asix/ax88796c_main.c
+++ b/drivers/net/ethernet/asix/ax88796c_main.c
@@ -284,7 +284,7 @@ ax88796c_tx_fixup(struct net_device *ndev, struct sk_buff_head *q)
 	ax88796c_proc_tx_hdr(&info, skb->ip_summed);
 
 	/* SOP and SEG header */
-	memcpy(skb_push(skb, TX_OVERHEAD), &info.sop, TX_OVERHEAD);
+	memcpy(skb_push(skb, TX_OVERHEAD), &info.tx_overhead, TX_OVERHEAD);
 
 	/* Write SPI TXQ header */
 	memcpy(skb_push(skb, spi_len), ax88796c_tx_cmd_buf, spi_len);
diff --git a/drivers/net/ethernet/asix/ax88796c_main.h b/drivers/net/ethernet/asix/ax88796c_main.h
index 4a83c991dcbe..678b47b29042 100644
--- a/drivers/net/ethernet/asix/ax88796c_main.h
+++ b/drivers/net/ethernet/asix/ax88796c_main.h
@@ -549,8 +549,10 @@ struct tx_eop_header {
 };
 
 struct tx_pkt_info {
-	struct tx_sop_header sop;
-	struct tx_segment_header seg;
+	struct_group(tx_overhead,
+		struct tx_sop_header sop;
+		struct tx_segment_header seg;
+	);
 	struct tx_eop_header eop;
 	u16 pkt_len;
 	u16 seq_num;
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] net: asix: fix fortify warning
  2023-12-06 13:38 [PATCH] net: asix: fix fortify warning Dmitry Antipov
@ 2023-12-09  0:07 ` Jakub Kicinski
  2023-12-11  9:05   ` [PATCH] [v2] " Dmitry Antipov
  0 siblings, 1 reply; 5+ messages in thread
From: Jakub Kicinski @ 2023-12-09  0:07 UTC (permalink / raw)
  To: Dmitry Antipov; +Cc: Łukasz Stelmach, netdev

On Wed,  6 Dec 2023 16:38:04 +0300 Dmitry Antipov wrote:
> When compiling with gcc version 14.0.0 20231129 (experimental) and
> CONFIG_FORTIFY_SOURCE=y, I've noticed the following warning:
> 
> ...
> In function 'fortify_memcpy_chk',
>     inlined from 'ax88796c_tx_fixup' at drivers/net/ethernet/asix/ax88796c_main.c:287:2:
> ./include/linux/fortify-string.h:588:25: warning: call to '__read_overflow2_field'
> declared with attribute warning: detected read beyond size of field (2nd parameter);
> maybe use struct_group()? [-Wattribute-warning]
>   588 |                         __read_overflow2_field(q_size_field, size);
>       |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ...
> 
> This call to 'memcpy()' is interpreted as an attempt to copy TX_OVERHEAD
> (which is 8) bytes from 4-byte 'sop' field of 'struct tx_pkt_info' and
> thus overread warning is issued. Since we actually wants to copy both
> 'sop' and 'seg' fields at once, use the convenient 'struct_group()' here.

Can we change the definition of TX_OVERHEAD to be
sizeof_field(... tx_overhead), to make it clear that
the two are indeed identical?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] [v2] net: asix: fix fortify warning
  2023-12-09  0:07 ` Jakub Kicinski
@ 2023-12-11  9:05   ` Dmitry Antipov
       [not found]     ` <CGME20231212093305eucas1p1efe0774516346de77142dc1ab427122d@eucas1p1.samsung.com>
  2023-12-12 22:10     ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 5+ messages in thread
From: Dmitry Antipov @ 2023-12-11  9:05 UTC (permalink / raw)
  To: Jakub Kicinski; +Cc: Łukasz Stelmach, netdev, Dmitry Antipov

When compiling with gcc version 14.0.0 20231129 (experimental) and
CONFIG_FORTIFY_SOURCE=y, I've noticed the following warning:

...
In function 'fortify_memcpy_chk',
    inlined from 'ax88796c_tx_fixup' at drivers/net/ethernet/asix/ax88796c_main.c:287:2:
./include/linux/fortify-string.h:588:25: warning: call to '__read_overflow2_field'
declared with attribute warning: detected read beyond size of field (2nd parameter);
maybe use struct_group()? [-Wattribute-warning]
  588 |                         __read_overflow2_field(q_size_field, size);
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...

This call to 'memcpy()' is interpreted as an attempt to copy TX_OVERHEAD
(which is 8) bytes from 4-byte 'sop' field of 'struct tx_pkt_info' and
thus overread warning is issued. Since we actually want to copy both
'sop' and 'seg' fields at once, use the convenient 'struct_group()' here.

Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
---
v2: prefer 'sizeof_field(struct tx_pkt_info, tx_overhead)' over the
hardcoded constant (Jakub Kicinski)
---
 drivers/net/ethernet/asix/ax88796c_main.c | 2 +-
 drivers/net/ethernet/asix/ax88796c_main.h | 8 +++++---
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/asix/ax88796c_main.c b/drivers/net/ethernet/asix/ax88796c_main.c
index e551ffaed20d..11e8996b33d7 100644
--- a/drivers/net/ethernet/asix/ax88796c_main.c
+++ b/drivers/net/ethernet/asix/ax88796c_main.c
@@ -284,7 +284,7 @@ ax88796c_tx_fixup(struct net_device *ndev, struct sk_buff_head *q)
 	ax88796c_proc_tx_hdr(&info, skb->ip_summed);
 
 	/* SOP and SEG header */
-	memcpy(skb_push(skb, TX_OVERHEAD), &info.sop, TX_OVERHEAD);
+	memcpy(skb_push(skb, TX_OVERHEAD), &info.tx_overhead, TX_OVERHEAD);
 
 	/* Write SPI TXQ header */
 	memcpy(skb_push(skb, spi_len), ax88796c_tx_cmd_buf, spi_len);
diff --git a/drivers/net/ethernet/asix/ax88796c_main.h b/drivers/net/ethernet/asix/ax88796c_main.h
index 4a83c991dcbe..68a09edecab8 100644
--- a/drivers/net/ethernet/asix/ax88796c_main.h
+++ b/drivers/net/ethernet/asix/ax88796c_main.h
@@ -25,7 +25,7 @@
 #define AX88796C_PHY_REGDUMP_LEN	14
 #define AX88796C_PHY_ID			0x10
 
-#define TX_OVERHEAD			8
+#define TX_OVERHEAD     sizeof_field(struct tx_pkt_info, tx_overhead)
 #define TX_EOP_SIZE			4
 
 #define AX_MCAST_FILTER_SIZE		8
@@ -549,8 +549,10 @@ struct tx_eop_header {
 };
 
 struct tx_pkt_info {
-	struct tx_sop_header sop;
-	struct tx_segment_header seg;
+	struct_group(tx_overhead,
+		struct tx_sop_header sop;
+		struct tx_segment_header seg;
+	);
 	struct tx_eop_header eop;
 	u16 pkt_len;
 	u16 seq_num;
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] [v2] net: asix: fix fortify warning
       [not found]     ` <CGME20231212093305eucas1p1efe0774516346de77142dc1ab427122d@eucas1p1.samsung.com>
@ 2023-12-12  9:33       ` Lukasz Stelmach
  0 siblings, 0 replies; 5+ messages in thread
From: Lukasz Stelmach @ 2023-12-12  9:33 UTC (permalink / raw)
  To: Dmitry Antipov; +Cc: Jakub Kicinski, netdev

[-- Attachment #1: Type: text/plain, Size: 3013 bytes --]

It was <2023-12-11 pon 12:05>, when Dmitry Antipov wrote:
> When compiling with gcc version 14.0.0 20231129 (experimental) and
> CONFIG_FORTIFY_SOURCE=y, I've noticed the following warning:
>
> ...
> In function 'fortify_memcpy_chk',
>     inlined from 'ax88796c_tx_fixup' at drivers/net/ethernet/asix/ax88796c_main.c:287:2:
> ./include/linux/fortify-string.h:588:25: warning: call to '__read_overflow2_field'
> declared with attribute warning: detected read beyond size of field (2nd parameter);
> maybe use struct_group()? [-Wattribute-warning]
>   588 |                         __read_overflow2_field(q_size_field, size);
>       |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ...
>
> This call to 'memcpy()' is interpreted as an attempt to copy TX_OVERHEAD
> (which is 8) bytes from 4-byte 'sop' field of 'struct tx_pkt_info' and
> thus overread warning is issued. Since we actually want to copy both
> 'sop' and 'seg' fields at once, use the convenient 'struct_group()' here.
>
> Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
> ---
> v2: prefer 'sizeof_field(struct tx_pkt_info, tx_overhead)' over the
> hardcoded constant (Jakub Kicinski)
> ---
>  drivers/net/ethernet/asix/ax88796c_main.c | 2 +-
>  drivers/net/ethernet/asix/ax88796c_main.h | 8 +++++---
>  2 files changed, 6 insertions(+), 4 deletions(-)
>

Acked-by: Łukasz Stelmach <l.stelmach@samsung.com>

> diff --git a/drivers/net/ethernet/asix/ax88796c_main.c b/drivers/net/ethernet/asix/ax88796c_main.c
> index e551ffaed20d..11e8996b33d7 100644
> --- a/drivers/net/ethernet/asix/ax88796c_main.c
> +++ b/drivers/net/ethernet/asix/ax88796c_main.c
> @@ -284,7 +284,7 @@ ax88796c_tx_fixup(struct net_device *ndev, struct sk_buff_head *q)
>  	ax88796c_proc_tx_hdr(&info, skb->ip_summed);
>  
>  	/* SOP and SEG header */
> -	memcpy(skb_push(skb, TX_OVERHEAD), &info.sop, TX_OVERHEAD);
> +	memcpy(skb_push(skb, TX_OVERHEAD), &info.tx_overhead, TX_OVERHEAD);
>  
>  	/* Write SPI TXQ header */
>  	memcpy(skb_push(skb, spi_len), ax88796c_tx_cmd_buf, spi_len);
> diff --git a/drivers/net/ethernet/asix/ax88796c_main.h b/drivers/net/ethernet/asix/ax88796c_main.h
> index 4a83c991dcbe..68a09edecab8 100644
> --- a/drivers/net/ethernet/asix/ax88796c_main.h
> +++ b/drivers/net/ethernet/asix/ax88796c_main.h
> @@ -25,7 +25,7 @@
>  #define AX88796C_PHY_REGDUMP_LEN	14
>  #define AX88796C_PHY_ID			0x10
>  
> -#define TX_OVERHEAD			8
> +#define TX_OVERHEAD     sizeof_field(struct tx_pkt_info, tx_overhead)
>  #define TX_EOP_SIZE			4
>  
>  #define AX_MCAST_FILTER_SIZE		8
> @@ -549,8 +549,10 @@ struct tx_eop_header {
>  };
>  
>  struct tx_pkt_info {
> -	struct tx_sop_header sop;
> -	struct tx_segment_header seg;
> +	struct_group(tx_overhead,
> +		struct tx_sop_header sop;
> +		struct tx_segment_header seg;
> +	);
>  	struct tx_eop_header eop;
>  	u16 pkt_len;
>  	u16 seq_num;

-- 
Łukasz Stelmach
Samsung R&D Institute Poland
Samsung Electronics

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] [v2] net: asix: fix fortify warning
  2023-12-11  9:05   ` [PATCH] [v2] " Dmitry Antipov
       [not found]     ` <CGME20231212093305eucas1p1efe0774516346de77142dc1ab427122d@eucas1p1.samsung.com>
@ 2023-12-12 22:10     ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-12-12 22:10 UTC (permalink / raw)
  To: Dmitry Antipov; +Cc: kuba, l.stelmach, netdev

Hello:

This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Mon, 11 Dec 2023 12:05:32 +0300 you wrote:
> When compiling with gcc version 14.0.0 20231129 (experimental) and
> CONFIG_FORTIFY_SOURCE=y, I've noticed the following warning:
> 
> ...
> In function 'fortify_memcpy_chk',
>     inlined from 'ax88796c_tx_fixup' at drivers/net/ethernet/asix/ax88796c_main.c:287:2:
> ./include/linux/fortify-string.h:588:25: warning: call to '__read_overflow2_field'
> declared with attribute warning: detected read beyond size of field (2nd parameter);
> maybe use struct_group()? [-Wattribute-warning]
>   588 |                         __read_overflow2_field(q_size_field, size);
>       |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ...
> 
> [...]

Here is the summary with links:
  - [v2] net: asix: fix fortify warning
    https://git.kernel.org/netdev/net-next/c/2a6264480020

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-12-12 22:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-06 13:38 [PATCH] net: asix: fix fortify warning Dmitry Antipov
2023-12-09  0:07 ` Jakub Kicinski
2023-12-11  9:05   ` [PATCH] [v2] " Dmitry Antipov
     [not found]     ` <CGME20231212093305eucas1p1efe0774516346de77142dc1ab427122d@eucas1p1.samsung.com>
2023-12-12  9:33       ` Lukasz Stelmach
2023-12-12 22:10     ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).