History

af_packet: Fix fortified memcpy() without flex array.

Sergei Trofimovich reported a regression [0] caused by commit a0ade8404c3b ("af_packet: Fix warning of fortified memcpy() in packet_getname()."). It introduced a flex array sll_addr_flex in struct sockaddr_ll as a union-ed member with sll_addr to work around the fortified memcpy() check. However, a userspace program uses a struct that has struct sockaddr_ll in the middle, where a flex array is illegal to exist. include/linux/if_packet.h:24:17: error: flexible array member 'sockaddr_ll::<unnamed union>::<unnamed struct>::sll_addr_flex' not at end of 'struct packet_info_t' 24 | __DECLARE_FLEX_ARRAY(unsigned char, sll_addr_flex); | ^~~~~~~~~~~~~~~~~~~~ To fix the regression, let's go back to the first attempt [1] telling memcpy() the actual size of the array.

Kuniyuki Iwashima committed 3 years ago

Commit e2bca481 parent 71c299c2 files · +7 −6Browse files

Showing the changes to include/uapi/linux (1 of 2 files). Show all

Unified · Split

include/uapi/linux/if_packet.h+1−5
@@ -18,11 +18,7 @@ struct sockaddr_ll { · 17 unmodified lines
1818 unsigned short sll_hatype;
1919 unsigned char sll_pkttype;
2020 unsigned char sll_halen;
21− union {
22− unsigned char sll_addr[8];
23− /* Actual length is in sll_halen. */
24− __DECLARE_FLEX_ARRAY(unsigned char, sll_addr_flex);
25− };
21+ unsigned char sll_addr[8];
2622 };
2723
2824 /* Packet types */