Skip to content

Commit

Permalink
net: asix: fix fortify warning
Browse files Browse the repository at this point in the history
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>
Acked-by: Łukasz Stelmach <l.stelmach@samsung.com>
Link: https://lore.kernel.org/r/20231211090535.9730-1-dmantipov@yandex.ru
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Dmitry Antipov authored and Jakub Kicinski committed Dec 12, 2023
1 parent 609c767 commit 2a62644
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion drivers/net/ethernet/asix/ax88796c_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 5 additions & 3 deletions drivers/net/ethernet/asix/ax88796c_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 2a62644

Please sign in to comment.