Skip to content

Commit aeba8c4

Browse files
edumazetgregkh
authored andcommitted
bonding/alb: properly access headers in bond_alb_xmit()
[ Upstream commit 38f88c4 ] syzbot managed to send an IPX packet through bond_alb_xmit() and af_packet and triggered a use-after-free. First, bond_alb_xmit() was using ipx_hdr() helper to reach the IPX header, but ipx_hdr() was using the transport offset instead of the network offset. In the particular syzbot report transport offset was 0xFFFF This patch removes ipx_hdr() since it was only (mis)used from bonding. Then we need to make sure IPv4/IPv6/IPX headers are pulled in skb->head before dereferencing anything. BUG: KASAN: use-after-free in bond_alb_xmit+0x153a/0x1590 drivers/net/bonding/bond_alb.c:1452 Read of size 2 at addr ffff8801ce56dfff by task syz-executor.2/18108 (if (ipx_hdr(skb)->ipx_checksum != IPX_NO_CHECKSUM) ...) Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 Call Trace: [<ffffffff8441fc42>] __dump_stack lib/dump_stack.c:17 [inline] [<ffffffff8441fc42>] dump_stack+0x14d/0x20b lib/dump_stack.c:53 [<ffffffff81a7dec4>] print_address_description+0x6f/0x20b mm/kasan/report.c:282 [<ffffffff81a7e0ec>] kasan_report_error mm/kasan/report.c:380 [inline] [<ffffffff81a7e0ec>] kasan_report mm/kasan/report.c:438 [inline] [<ffffffff81a7e0ec>] kasan_report.cold+0x8c/0x2a0 mm/kasan/report.c:422 [<ffffffff81a7dc4f>] __asan_report_load_n_noabort+0xf/0x20 mm/kasan/report.c:469 [<ffffffff82c8c00a>] bond_alb_xmit+0x153a/0x1590 drivers/net/bonding/bond_alb.c:1452 [<ffffffff82c60c74>] __bond_start_xmit drivers/net/bonding/bond_main.c:4199 [inline] [<ffffffff82c60c74>] bond_start_xmit+0x4f4/0x1570 drivers/net/bonding/bond_main.c:4224 [<ffffffff83baa558>] __netdev_start_xmit include/linux/netdevice.h:4525 [inline] [<ffffffff83baa558>] netdev_start_xmit include/linux/netdevice.h:4539 [inline] [<ffffffff83baa558>] xmit_one net/core/dev.c:3611 [inline] [<ffffffff83baa558>] dev_hard_start_xmit+0x168/0x910 net/core/dev.c:3627 [<ffffffff83bacf35>] __dev_queue_xmit+0x1f55/0x33b0 net/core/dev.c:4238 [<ffffffff83bae3a8>] dev_queue_xmit+0x18/0x20 net/core/dev.c:4278 [<ffffffff84339189>] packet_snd net/packet/af_packet.c:3226 [inline] [<ffffffff84339189>] packet_sendmsg+0x4919/0x70b0 net/packet/af_packet.c:3252 [<ffffffff83b1ac0c>] sock_sendmsg_nosec net/socket.c:673 [inline] [<ffffffff83b1ac0c>] sock_sendmsg+0x12c/0x160 net/socket.c:684 [<ffffffff83b1f5a2>] __sys_sendto+0x262/0x380 net/socket.c:1996 [<ffffffff83b1f700>] SYSC_sendto net/socket.c:2008 [inline] [<ffffffff83b1f700>] SyS_sendto+0x40/0x60 net/socket.c:2004 Fixes: 1da177e ("Linux-2.6.12-rc2") Signed-off-by: Eric Dumazet <[email protected]> Reported-by: syzbot <[email protected]> Cc: Jay Vosburgh <[email protected]> Cc: Veaceslav Falico <[email protected]> Cc: Andy Gospodarek <[email protected]> Signed-off-by: David S. Miller <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 34b4e7b commit aeba8c4

File tree

1 file changed

+32
-12
lines changed

1 file changed

+32
-12
lines changed

drivers/net/bonding/bond_alb.c

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,26 +1371,31 @@ int bond_alb_xmit(struct sk_buff *skb, struct net_device *bond_dev)
13711371
bool do_tx_balance = true;
13721372
u32 hash_index = 0;
13731373
const u8 *hash_start = NULL;
1374-
struct ipv6hdr *ip6hdr;
13751374

13761375
skb_reset_mac_header(skb);
13771376
eth_data = eth_hdr(skb);
13781377

13791378
switch (ntohs(skb->protocol)) {
13801379
case ETH_P_IP: {
1381-
const struct iphdr *iph = ip_hdr(skb);
1380+
const struct iphdr *iph;
13821381

13831382
if (ether_addr_equal_64bits(eth_data->h_dest, mac_bcast) ||
1384-
(iph->daddr == ip_bcast) ||
1385-
(iph->protocol == IPPROTO_IGMP)) {
1383+
(!pskb_network_may_pull(skb, sizeof(*iph)))) {
1384+
do_tx_balance = false;
1385+
break;
1386+
}
1387+
iph = ip_hdr(skb);
1388+
if (iph->daddr == ip_bcast || iph->protocol == IPPROTO_IGMP) {
13861389
do_tx_balance = false;
13871390
break;
13881391
}
13891392
hash_start = (char *)&(iph->daddr);
13901393
hash_size = sizeof(iph->daddr);
1391-
}
13921394
break;
1393-
case ETH_P_IPV6:
1395+
}
1396+
case ETH_P_IPV6: {
1397+
const struct ipv6hdr *ip6hdr;
1398+
13941399
/* IPv6 doesn't really use broadcast mac address, but leave
13951400
* that here just in case.
13961401
*/
@@ -1407,7 +1412,11 @@ int bond_alb_xmit(struct sk_buff *skb, struct net_device *bond_dev)
14071412
break;
14081413
}
14091414

1410-
/* Additianally, DAD probes should not be tx-balanced as that
1415+
if (!pskb_network_may_pull(skb, sizeof(*ip6hdr))) {
1416+
do_tx_balance = false;
1417+
break;
1418+
}
1419+
/* Additionally, DAD probes should not be tx-balanced as that
14111420
* will lead to false positives for duplicate addresses and
14121421
* prevent address configuration from working.
14131422
*/
@@ -1417,17 +1426,26 @@ int bond_alb_xmit(struct sk_buff *skb, struct net_device *bond_dev)
14171426
break;
14181427
}
14191428

1420-
hash_start = (char *)&(ipv6_hdr(skb)->daddr);
1421-
hash_size = sizeof(ipv6_hdr(skb)->daddr);
1429+
hash_start = (char *)&ip6hdr->daddr;
1430+
hash_size = sizeof(ip6hdr->daddr);
14221431
break;
1423-
case ETH_P_IPX:
1424-
if (ipx_hdr(skb)->ipx_checksum != IPX_NO_CHECKSUM) {
1432+
}
1433+
case ETH_P_IPX: {
1434+
const struct ipxhdr *ipxhdr;
1435+
1436+
if (pskb_network_may_pull(skb, sizeof(*ipxhdr))) {
1437+
do_tx_balance = false;
1438+
break;
1439+
}
1440+
ipxhdr = (struct ipxhdr *)skb_network_header(skb);
1441+
1442+
if (ipxhdr->ipx_checksum != IPX_NO_CHECKSUM) {
14251443
/* something is wrong with this packet */
14261444
do_tx_balance = false;
14271445
break;
14281446
}
14291447

1430-
if (ipx_hdr(skb)->ipx_type != IPX_TYPE_NCP) {
1448+
if (ipxhdr->ipx_type != IPX_TYPE_NCP) {
14311449
/* The only protocol worth balancing in
14321450
* this family since it has an "ARP" like
14331451
* mechanism
@@ -1436,9 +1454,11 @@ int bond_alb_xmit(struct sk_buff *skb, struct net_device *bond_dev)
14361454
break;
14371455
}
14381456

1457+
eth_data = eth_hdr(skb);
14391458
hash_start = (char *)eth_data->h_dest;
14401459
hash_size = ETH_ALEN;
14411460
break;
1461+
}
14421462
case ETH_P_ARP:
14431463
do_tx_balance = false;
14441464
if (bond_info->rlb_enabled)

0 commit comments

Comments
 (0)