Skip to content

Commit a49441c

Browse files
committed
Merge branch 'net-fix-error-warning-by-fstrict-flex-arrays-3'
Kuniyuki Iwashima says: ==================== net: Fix error/warning by -fstrict-flex-arrays=3. df8fc4e ("kbuild: Enable -fstrict-flex-arrays=3") started applying strict rules for standard string functions (strlen(), memcpy(), etc.) if CONFIG_FORTIFY_SOURCE=y. This series fixes two false positives caught by syzkaller. v2: https://lore.kernel.org/netdev/[email protected]/ v1: https://lore.kernel.org/netdev/[email protected]/ ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 55cef78 + a0ade84 commit a49441c

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

include/uapi/linux/if_packet.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ struct sockaddr_ll {
1818
unsigned short sll_hatype;
1919
unsigned char sll_pkttype;
2020
unsigned char sll_halen;
21-
unsigned char sll_addr[8];
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+
};
2226
};
2327

2428
/* Packet types */

net/packet/af_packet.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3601,7 +3601,7 @@ static int packet_getname(struct socket *sock, struct sockaddr *uaddr,
36013601
if (dev) {
36023602
sll->sll_hatype = dev->type;
36033603
sll->sll_halen = dev->addr_len;
3604-
memcpy(sll->sll_addr, dev->dev_addr, dev->addr_len);
3604+
memcpy(sll->sll_addr_flex, dev->dev_addr, dev->addr_len);
36053605
} else {
36063606
sll->sll_hatype = 0; /* Bad: we have no ARPHRD_UNSPEC */
36073607
sll->sll_halen = 0;

net/unix/af_unix.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,10 +1208,8 @@ static int unix_bind_bsd(struct sock *sk, struct sockaddr_un *sunaddr,
12081208
struct path parent;
12091209
int err;
12101210

1211-
unix_mkname_bsd(sunaddr, addr_len);
1212-
addr_len = strlen(sunaddr->sun_path) +
1213-
offsetof(struct sockaddr_un, sun_path) + 1;
1214-
1211+
addr_len = strnlen(sunaddr->sun_path, sizeof(sunaddr->sun_path))
1212+
+ offsetof(struct sockaddr_un, sun_path) + 1;
12151213
addr = unix_create_addr(sunaddr, addr_len);
12161214
if (!addr)
12171215
return -ENOMEM;

0 commit comments

Comments
 (0)