Skip to content

Commit 58e0be1

Browse files
liuhangbinPaolo Abeni
authored andcommitted
net: use struct_group to copy ip/ipv6 header addresses
kernel test robot reported warnings when build bonding module with make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash drivers/net/bonding/: from ../drivers/net/bonding/bond_main.c:35: In function ‘fortify_memcpy_chk’, inlined from ‘iph_to_flow_copy_v4addrs’ at ../include/net/ip.h:566:2, inlined from ‘bond_flow_ip’ at ../drivers/net/bonding/bond_main.c:3984:3: ../include/linux/fortify-string.h:413:25: warning: call to ‘__read_overflow2_field’ declared with attribute warning: detected read beyond size of f ield (2nd parameter); maybe use struct_group()? [-Wattribute-warning] 413 | __read_overflow2_field(q_size_field, size); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In function ‘fortify_memcpy_chk’, inlined from ‘iph_to_flow_copy_v6addrs’ at ../include/net/ipv6.h:900:2, inlined from ‘bond_flow_ip’ at ../drivers/net/bonding/bond_main.c:3994:3: ../include/linux/fortify-string.h:413:25: warning: call to ‘__read_overflow2_field’ declared with attribute warning: detected read beyond size of f ield (2nd parameter); maybe use struct_group()? [-Wattribute-warning] 413 | __read_overflow2_field(q_size_field, size); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This is because we try to copy the whole ip/ip6 address to the flow_key, while we only point the to ip/ip6 saddr. Note that since these are UAPI headers, __struct_group() is used to avoid the compiler warnings. Reported-by: kernel test robot <[email protected]> Fixes: c3f8324 ("net: Add full IPv6 addresses to flow_keys") Signed-off-by: Hangbin Liu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent 809ff97 commit 58e0be1

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

include/net/ip.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ static inline void iph_to_flow_copy_v4addrs(struct flow_keys *flow,
563563
BUILD_BUG_ON(offsetof(typeof(flow->addrs), v4addrs.dst) !=
564564
offsetof(typeof(flow->addrs), v4addrs.src) +
565565
sizeof(flow->addrs.v4addrs.src));
566-
memcpy(&flow->addrs.v4addrs, &iph->saddr, sizeof(flow->addrs.v4addrs));
566+
memcpy(&flow->addrs.v4addrs, &iph->addrs, sizeof(flow->addrs.v4addrs));
567567
flow->control.addr_type = FLOW_DISSECTOR_KEY_IPV4_ADDRS;
568568
}
569569

include/net/ipv6.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,7 @@ static inline void iph_to_flow_copy_v6addrs(struct flow_keys *flow,
897897
BUILD_BUG_ON(offsetof(typeof(flow->addrs), v6addrs.dst) !=
898898
offsetof(typeof(flow->addrs), v6addrs.src) +
899899
sizeof(flow->addrs.v6addrs.src));
900-
memcpy(&flow->addrs.v6addrs, &iph->saddr, sizeof(flow->addrs.v6addrs));
900+
memcpy(&flow->addrs.v6addrs, &iph->addrs, sizeof(flow->addrs.v6addrs));
901901
flow->control.addr_type = FLOW_DISSECTOR_KEY_IPV6_ADDRS;
902902
}
903903

include/uapi/linux/ip.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,10 @@ struct iphdr {
100100
__u8 ttl;
101101
__u8 protocol;
102102
__sum16 check;
103-
__be32 saddr;
104-
__be32 daddr;
103+
__struct_group(/* no tag */, addrs, /* no attrs */,
104+
__be32 saddr;
105+
__be32 daddr;
106+
);
105107
/*The options start here. */
106108
};
107109

include/uapi/linux/ipv6.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,10 @@ struct ipv6hdr {
130130
__u8 nexthdr;
131131
__u8 hop_limit;
132132

133-
struct in6_addr saddr;
134-
struct in6_addr daddr;
133+
__struct_group(/* no tag */, addrs, /* no attrs */,
134+
struct in6_addr saddr;
135+
struct in6_addr daddr;
136+
);
135137
};
136138

137139

0 commit comments

Comments
 (0)