Skip to content

Commit f1cb347

Browse files
buszkKalle Valo
authored and
Kalle Valo
committed
rsi: Fix out-of-bounds read in rsi_read_pkt()
rsi_get_* functions rely on an offset variable from usb input. The size of usb input is RSI_MAX_RX_USB_PKT_SIZE(3000), while 2-byte offset can be up to 0xFFFF. Thus a large offset can cause out-of-bounds read. The patch adds a bound checking condition when rcv_pkt_len is 0, indicating it's USB. It's unclear whether this is triggerable from other type of bus. The following check might help in that case. offset > rcv_pkt_len - FRAME_DESC_SZ The bug is trigerrable with conpromised/malfunctioning USB devices. I tested the patch with the crashing input and got no more bug report. Attached is the KASAN report from fuzzing. BUG: KASAN: slab-out-of-bounds in rsi_read_pkt+0x42e/0x500 [rsi_91x] Read of size 2 at addr ffff888019439fdb by task RX-Thread/227 CPU: 0 PID: 227 Comm: RX-Thread Not tainted 5.6.0 #66 Call Trace: dump_stack+0x76/0xa0 print_address_description.constprop.0+0x16/0x200 ? rsi_read_pkt+0x42e/0x500 [rsi_91x] ? rsi_read_pkt+0x42e/0x500 [rsi_91x] __kasan_report.cold+0x37/0x7c ? rsi_read_pkt+0x42e/0x500 [rsi_91x] kasan_report+0xe/0x20 rsi_read_pkt+0x42e/0x500 [rsi_91x] rsi_usb_rx_thread+0x1b1/0x2fc [rsi_usb] ? rsi_probe+0x16a0/0x16a0 [rsi_usb] ? _raw_spin_lock_irqsave+0x7b/0xd0 ? _raw_spin_trylock_bh+0x120/0x120 ? __wake_up_common+0x10b/0x520 ? rsi_probe+0x16a0/0x16a0 [rsi_usb] kthread+0x2b5/0x3b0 ? kthread_create_on_node+0xd0/0xd0 ret_from_fork+0x22/0x40 Reported-by: Brendan Dolan-Gavitt <[email protected]> Signed-off-by: Zekun Shen <[email protected]> Signed-off-by: Kalle Valo <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent b07e3c6 commit f1cb347

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

drivers/net/wireless/rsi/rsi_91x_main.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "rsi_common.h"
2424
#include "rsi_coex.h"
2525
#include "rsi_hal.h"
26+
#include "rsi_usb.h"
2627

2728
u32 rsi_zone_enabled = /* INFO_ZONE |
2829
INIT_ZONE |
@@ -168,6 +169,9 @@ int rsi_read_pkt(struct rsi_common *common, u8 *rx_pkt, s32 rcv_pkt_len)
168169
frame_desc = &rx_pkt[index];
169170
actual_length = *(u16 *)&frame_desc[0];
170171
offset = *(u16 *)&frame_desc[2];
172+
if (!rcv_pkt_len && offset >
173+
RSI_MAX_RX_USB_PKT_SIZE - FRAME_DESC_SZ)
174+
goto fail;
171175

172176
queueno = rsi_get_queueno(frame_desc, offset);
173177
length = rsi_get_length(frame_desc, offset);

drivers/net/wireless/rsi/rsi_91x_usb.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,6 @@ static int rsi_rx_urb_submit(struct rsi_hw *adapter, u8 ep_num, gfp_t mem_flags)
330330
struct sk_buff *skb;
331331
u8 dword_align_bytes = 0;
332332

333-
#define RSI_MAX_RX_USB_PKT_SIZE 3000
334333
skb = dev_alloc_skb(RSI_MAX_RX_USB_PKT_SIZE);
335334
if (!skb)
336335
return -ENOMEM;

drivers/net/wireless/rsi/rsi_usb.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
#define RSI_USB_BUF_SIZE 4096
4545
#define RSI_USB_CTRL_BUF_SIZE 0x04
4646

47+
#define RSI_MAX_RX_USB_PKT_SIZE 3000
48+
4749
struct rx_usb_ctrl_block {
4850
u8 *data;
4951
struct urb *rx_urb;

0 commit comments

Comments
 (0)