Skip to content

Commit a066562

Browse files
liuyonglong86davem330
authored andcommitted
net: hns3: fix use-after-free when doing self test
Enable promisc mode of PF, set VF link state to enable, and run iperf of the VF, then do self test of the PF. The self test will fail with a low frequency, and may cause a use-after-free problem. [ 87.142126] selftest:000004a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ [ 87.159722] ================================================================== [ 87.174187] BUG: KASAN: use-after-free in hex_dump_to_buffer+0x140/0x608 [ 87.187600] Read of size 1 at addr ffff003b22828000 by task ethtool/1186 [ 87.201012] [ 87.203978] CPU: 7 PID: 1186 Comm: ethtool Not tainted 5.5.0-rc4-gfd51c473-dirty #4 [ 87.219306] Hardware name: Huawei TaiShan 2280 V2/BC82AMDA, BIOS TA BIOS 2280-A CS V2.B160.01 01/15/2020 [ 87.238292] Call trace: [ 87.243173] dump_backtrace+0x0/0x280 [ 87.250491] show_stack+0x24/0x30 [ 87.257114] dump_stack+0xe8/0x140 [ 87.263911] print_address_description.isra.8+0x70/0x380 [ 87.274538] __kasan_report+0x12c/0x230 [ 87.282203] kasan_report+0xc/0x18 [ 87.288999] __asan_load1+0x60/0x68 [ 87.295969] hex_dump_to_buffer+0x140/0x608 [ 87.304332] print_hex_dump+0x140/0x1e0 [ 87.312000] hns3_lb_check_skb_data+0x168/0x170 [ 87.321060] hns3_clean_rx_ring+0xa94/0xfe0 [ 87.329422] hns3_self_test+0x708/0x8c0 The length of packet sent by the selftest process is only 128 + 14 bytes, and the min buffer size of a BD is 256 bytes, and the receive process will make sure the packet sent by the selftest process is in the linear part, so only check the linear part in hns3_lb_check_skb_data(). So fix this use-after-free by using skb_headlen() to dump skb->data instead of skb->len. Fixes: c39c4d9 ("net: hns3: Add mac loopback selftest support in hns3 driver") Signed-off-by: Yonglong Liu <[email protected]> Signed-off-by: Huazhong Tan <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent e22b5e7 commit a066562

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,18 +180,21 @@ static void hns3_lb_check_skb_data(struct hns3_enet_ring *ring,
180180
{
181181
struct hns3_enet_tqp_vector *tqp_vector = ring->tqp_vector;
182182
unsigned char *packet = skb->data;
183+
u32 len = skb_headlen(skb);
183184
u32 i;
184185

185-
for (i = 0; i < skb->len; i++)
186+
len = min_t(u32, len, HNS3_NIC_LB_TEST_PACKET_SIZE);
187+
188+
for (i = 0; i < len; i++)
186189
if (packet[i] != (unsigned char)(i & 0xff))
187190
break;
188191

189192
/* The packet is correctly received */
190-
if (i == skb->len)
193+
if (i == HNS3_NIC_LB_TEST_PACKET_SIZE)
191194
tqp_vector->rx_group.total_packets++;
192195
else
193196
print_hex_dump(KERN_ERR, "selftest:", DUMP_PREFIX_OFFSET, 16, 1,
194-
skb->data, skb->len, true);
197+
skb->data, len, true);
195198

196199
dev_kfree_skb_any(skb);
197200
}

0 commit comments

Comments
 (0)