linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rsi_usb: Fix out-of-bounds read in rsi_read_pkt
@ 2021-10-29 20:19 Zekun Shen
  2021-11-01 14:07 ` Kalle Valo
  2021-11-29 10:44 ` rsi: Fix out-of-bounds read in rsi_read_pkt() Kalle Valo
  0 siblings, 2 replies; 3+ messages in thread
From: Zekun Shen @ 2021-10-29 20:19 UTC (permalink / raw)
  To: bruceshenzk
  Cc: Amitkumar Karwar, Siva Rebbagondla, Kalle Valo, David S. Miller,
	Jakub Kicinski, linux-wireless, netdev, linux-kernel, brendandg

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: Zekun Shen <bruceshenzk@gmail.com>
Reported-by: Brendan Dolan-Gavitt <brendandg@nyu.edu>
Signed-off-by: Zekun Shen <bruceshenzk@gmail.com>
---
 drivers/net/wireless/rsi/rsi_91x_main.c | 4 ++++
 drivers/net/wireless/rsi/rsi_91x_usb.c  | 1 -
 drivers/net/wireless/rsi/rsi_usb.h      | 2 ++
 3 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/net/wireless/rsi/rsi_91x_main.c b/drivers/net/wireless/rsi/rsi_91x_main.c
index d98483298..61fc27714 100644
--- a/drivers/net/wireless/rsi/rsi_91x_main.c
+++ b/drivers/net/wireless/rsi/rsi_91x_main.c
@@ -23,6 +23,7 @@
 #include "rsi_common.h"
 #include "rsi_coex.h"
 #include "rsi_hal.h"
+#include "rsi_usb.h"
 
 u32 rsi_zone_enabled = /* INFO_ZONE |
 			INIT_ZONE |
@@ -168,6 +169,9 @@ int rsi_read_pkt(struct rsi_common *common, u8 *rx_pkt, s32 rcv_pkt_len)
 		frame_desc = &rx_pkt[index];
 		actual_length = *(u16 *)&frame_desc[0];
 		offset = *(u16 *)&frame_desc[2];
+		if (!rcv_pkt_len && offset >
+			RSI_MAX_RX_USB_PKT_SIZE - FRAME_DESC_SZ)
+			goto fail;
 
 		queueno = rsi_get_queueno(frame_desc, offset);
 		length = rsi_get_length(frame_desc, offset);
diff --git a/drivers/net/wireless/rsi/rsi_91x_usb.c b/drivers/net/wireless/rsi/rsi_91x_usb.c
index d9e9bf26e..49ae4ae69 100644
--- a/drivers/net/wireless/rsi/rsi_91x_usb.c
+++ b/drivers/net/wireless/rsi/rsi_91x_usb.c
@@ -333,7 +333,6 @@ static int rsi_rx_urb_submit(struct rsi_hw *adapter, u8 ep_num, gfp_t mem_flags)
 	struct sk_buff *skb;
 	u8 dword_align_bytes = 0;
 
-#define RSI_MAX_RX_USB_PKT_SIZE	3000
 	skb = dev_alloc_skb(RSI_MAX_RX_USB_PKT_SIZE);
 	if (!skb)
 		return -ENOMEM;
diff --git a/drivers/net/wireless/rsi/rsi_usb.h b/drivers/net/wireless/rsi/rsi_usb.h
index 254d19b66..961851748 100644
--- a/drivers/net/wireless/rsi/rsi_usb.h
+++ b/drivers/net/wireless/rsi/rsi_usb.h
@@ -44,6 +44,8 @@
 #define RSI_USB_BUF_SIZE	     4096
 #define RSI_USB_CTRL_BUF_SIZE	     0x04
 
+#define RSI_MAX_RX_USB_PKT_SIZE	3000
+
 struct rx_usb_ctrl_block {
 	u8 *data;
 	struct urb *rx_urb;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] rsi_usb: Fix out-of-bounds read in rsi_read_pkt
  2021-10-29 20:19 [PATCH] rsi_usb: Fix out-of-bounds read in rsi_read_pkt Zekun Shen
@ 2021-11-01 14:07 ` Kalle Valo
  2021-11-29 10:44 ` rsi: Fix out-of-bounds read in rsi_read_pkt() Kalle Valo
  1 sibling, 0 replies; 3+ messages in thread
From: Kalle Valo @ 2021-11-01 14:07 UTC (permalink / raw)
  To: Zekun Shen
  Cc: Amitkumar Karwar, Siva Rebbagondla, David S. Miller,
	Jakub Kicinski, linux-wireless, netdev, linux-kernel, brendandg

Zekun Shen <bruceshenzk@gmail.com> writes:

> 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: Zekun Shen <bruceshenzk@gmail.com>

You are the author, no need to have your name in Reported-by.


-- 
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: rsi: Fix out-of-bounds read in rsi_read_pkt()
  2021-10-29 20:19 [PATCH] rsi_usb: Fix out-of-bounds read in rsi_read_pkt Zekun Shen
  2021-11-01 14:07 ` Kalle Valo
@ 2021-11-29 10:44 ` Kalle Valo
  1 sibling, 0 replies; 3+ messages in thread
From: Kalle Valo @ 2021-11-29 10:44 UTC (permalink / raw)
  To: Zekun Shen
  Cc: bruceshenzk, Amitkumar Karwar, Siva Rebbagondla, David S. Miller,
	Jakub Kicinski, linux-wireless, netdev, linux-kernel, brendandg

Zekun Shen <bruceshenzk@gmail.com> wrote:

> 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 <brendandg@nyu.edu>
> Signed-off-by: Zekun Shen <bruceshenzk@gmail.com>

Patch applied to wireless-drivers-next.git, thanks.

f1cb3476e48b rsi: Fix out-of-bounds read in rsi_read_pkt()

-- 
https://patchwork.kernel.org/project/linux-wireless/patch/YXxXS4wgu2OsmlVv@10-18-43-117.dynapool.wireless.nyu.edu/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-11-29 10:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-29 20:19 [PATCH] rsi_usb: Fix out-of-bounds read in rsi_read_pkt Zekun Shen
2021-11-01 14:07 ` Kalle Valo
2021-11-29 10:44 ` rsi: Fix out-of-bounds read in rsi_read_pkt() Kalle Valo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).