Skip to content

Commit 97efdab

Browse files
Qiujun Huanggregkh
authored andcommitted
ath9k: Fix general protection fault in ath9k_hif_usb_rx_cb
commit 2bbcaaee1fcbd83272e29f31e2bb7e70d8c49e05 upstream. In ath9k_hif_usb_rx_cb interface number is assumed to be 0. usb_ifnum_to_if(urb->dev, 0) But it isn't always true. The case reported by syzbot: https://lore.kernel.org/linux-usb/000000000000666c9c05a1c05d12@google.com usb 2-1: new high-speed USB device number 2 using dummy_hcd usb 2-1: config 1 has an invalid interface number: 2 but max is 0 usb 2-1: config 1 has no interface number 0 usb 2-1: New USB device found, idVendor=0cf3, idProduct=9271, bcdDevice= 1.08 usb 2-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3 general protection fault, probably for non-canonical address 0xdffffc0000000015: 0000 [Demon000#1] SMP KASAN KASAN: null-ptr-deref in range [0x00000000000000a8-0x00000000000000af] CPU: 0 PID: 0 Comm: swapper/0 Not tainted 5.6.0-rc5-syzkaller #0 Call Trace __usb_hcd_giveback_urb+0x29a/0x550 drivers/usb/core/hcd.c:1650 usb_hcd_giveback_urb+0x368/0x420 drivers/usb/core/hcd.c:1716 dummy_timer+0x1258/0x32ae drivers/usb/gadget/udc/dummy_hcd.c:1966 call_timer_fn+0x195/0x6f0 kernel/time/timer.c:1404 expire_timers kernel/time/timer.c:1449 [inline] __run_timers kernel/time/timer.c:1773 [inline] __run_timers kernel/time/timer.c:1740 [inline] run_timer_softirq+0x5f9/0x1500 kernel/time/timer.c:1786 __do_softirq+0x21e/0x950 kernel/softirq.c:292 invoke_softirq kernel/softirq.c:373 [inline] irq_exit+0x178/0x1a0 kernel/softirq.c:413 exiting_irq arch/x86/include/asm/apic.h:546 [inline] smp_apic_timer_interrupt+0x141/0x540 arch/x86/kernel/apic/apic.c:1146 apic_timer_interrupt+0xf/0x20 arch/x86/entry/entry_64.S:829 Reported-and-tested-by: syzbot+40d5d2e8a4680952f042@syzkaller.appspotmail.com Signed-off-by: Qiujun Huang <hqjagain@gmail.com> Signed-off-by: Kalle Valo <kvalo@codeaurora.org> Link: https://lore.kernel.org/r/20200404041838.10426-6-hqjagain@gmail.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 1442865 commit 97efdab

2 files changed

Lines changed: 42 additions & 11 deletions

File tree

drivers/net/wireless/ath/ath9k/hif_usb.c

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -641,9 +641,9 @@ static void ath9k_hif_usb_rx_stream(struct hif_device_usb *hif_dev,
641641

642642
static void ath9k_hif_usb_rx_cb(struct urb *urb)
643643
{
644-
struct sk_buff *skb = (struct sk_buff *) urb->context;
645-
struct hif_device_usb *hif_dev =
646-
usb_get_intfdata(usb_ifnum_to_if(urb->dev, 0));
644+
struct rx_buf *rx_buf = (struct rx_buf *)urb->context;
645+
struct hif_device_usb *hif_dev = rx_buf->hif_dev;
646+
struct sk_buff *skb = rx_buf->skb;
647647
int ret;
648648

649649
if (!skb)
@@ -683,14 +683,15 @@ static void ath9k_hif_usb_rx_cb(struct urb *urb)
683683
return;
684684
free:
685685
kfree_skb(skb);
686+
kfree(rx_buf);
686687
}
687688

688689
static void ath9k_hif_usb_reg_in_cb(struct urb *urb)
689690
{
690-
struct sk_buff *skb = (struct sk_buff *) urb->context;
691+
struct rx_buf *rx_buf = (struct rx_buf *)urb->context;
692+
struct hif_device_usb *hif_dev = rx_buf->hif_dev;
693+
struct sk_buff *skb = rx_buf->skb;
691694
struct sk_buff *nskb;
692-
struct hif_device_usb *hif_dev =
693-
usb_get_intfdata(usb_ifnum_to_if(urb->dev, 0));
694695
int ret;
695696

696697
if (!skb)
@@ -748,6 +749,7 @@ static void ath9k_hif_usb_reg_in_cb(struct urb *urb)
748749
return;
749750
free:
750751
kfree_skb(skb);
752+
kfree(rx_buf);
751753
urb->context = NULL;
752754
}
753755

@@ -793,7 +795,7 @@ static int ath9k_hif_usb_alloc_tx_urbs(struct hif_device_usb *hif_dev)
793795
init_usb_anchor(&hif_dev->mgmt_submitted);
794796

795797
for (i = 0; i < MAX_TX_URB_NUM; i++) {
796-
tx_buf = kzalloc(sizeof(struct tx_buf), GFP_KERNEL);
798+
tx_buf = kzalloc(sizeof(*tx_buf), GFP_KERNEL);
797799
if (!tx_buf)
798800
goto err;
799801

@@ -830,15 +832,22 @@ static void ath9k_hif_usb_dealloc_rx_urbs(struct hif_device_usb *hif_dev)
830832

831833
static int ath9k_hif_usb_alloc_rx_urbs(struct hif_device_usb *hif_dev)
832834
{
833-
struct urb *urb = NULL;
835+
struct rx_buf *rx_buf = NULL;
834836
struct sk_buff *skb = NULL;
837+
struct urb *urb = NULL;
835838
int i, ret;
836839

837840
init_usb_anchor(&hif_dev->rx_submitted);
838841
spin_lock_init(&hif_dev->rx_lock);
839842

840843
for (i = 0; i < MAX_RX_URB_NUM; i++) {
841844

845+
rx_buf = kzalloc(sizeof(*rx_buf), GFP_KERNEL);
846+
if (!rx_buf) {
847+
ret = -ENOMEM;
848+
goto err_rxb;
849+
}
850+
842851
/* Allocate URB */
843852
urb = usb_alloc_urb(0, GFP_KERNEL);
844853
if (urb == NULL) {
@@ -853,11 +862,14 @@ static int ath9k_hif_usb_alloc_rx_urbs(struct hif_device_usb *hif_dev)
853862
goto err_skb;
854863
}
855864

865+
rx_buf->hif_dev = hif_dev;
866+
rx_buf->skb = skb;
867+
856868
usb_fill_bulk_urb(urb, hif_dev->udev,
857869
usb_rcvbulkpipe(hif_dev->udev,
858870
USB_WLAN_RX_PIPE),
859871
skb->data, MAX_RX_BUF_SIZE,
860-
ath9k_hif_usb_rx_cb, skb);
872+
ath9k_hif_usb_rx_cb, rx_buf);
861873

862874
/* Anchor URB */
863875
usb_anchor_urb(urb, &hif_dev->rx_submitted);
@@ -883,6 +895,8 @@ static int ath9k_hif_usb_alloc_rx_urbs(struct hif_device_usb *hif_dev)
883895
err_skb:
884896
usb_free_urb(urb);
885897
err_urb:
898+
kfree(rx_buf);
899+
err_rxb:
886900
ath9k_hif_usb_dealloc_rx_urbs(hif_dev);
887901
return ret;
888902
}
@@ -894,14 +908,21 @@ static void ath9k_hif_usb_dealloc_reg_in_urbs(struct hif_device_usb *hif_dev)
894908

895909
static int ath9k_hif_usb_alloc_reg_in_urbs(struct hif_device_usb *hif_dev)
896910
{
897-
struct urb *urb = NULL;
911+
struct rx_buf *rx_buf = NULL;
898912
struct sk_buff *skb = NULL;
913+
struct urb *urb = NULL;
899914
int i, ret;
900915

901916
init_usb_anchor(&hif_dev->reg_in_submitted);
902917

903918
for (i = 0; i < MAX_REG_IN_URB_NUM; i++) {
904919

920+
rx_buf = kzalloc(sizeof(*rx_buf), GFP_KERNEL);
921+
if (!rx_buf) {
922+
ret = -ENOMEM;
923+
goto err_rxb;
924+
}
925+
905926
/* Allocate URB */
906927
urb = usb_alloc_urb(0, GFP_KERNEL);
907928
if (urb == NULL) {
@@ -916,11 +937,14 @@ static int ath9k_hif_usb_alloc_reg_in_urbs(struct hif_device_usb *hif_dev)
916937
goto err_skb;
917938
}
918939

940+
rx_buf->hif_dev = hif_dev;
941+
rx_buf->skb = skb;
942+
919943
usb_fill_int_urb(urb, hif_dev->udev,
920944
usb_rcvintpipe(hif_dev->udev,
921945
USB_REG_IN_PIPE),
922946
skb->data, MAX_REG_IN_BUF_SIZE,
923-
ath9k_hif_usb_reg_in_cb, skb, 1);
947+
ath9k_hif_usb_reg_in_cb, rx_buf, 1);
924948

925949
/* Anchor URB */
926950
usb_anchor_urb(urb, &hif_dev->reg_in_submitted);
@@ -946,6 +970,8 @@ static int ath9k_hif_usb_alloc_reg_in_urbs(struct hif_device_usb *hif_dev)
946970
err_skb:
947971
usb_free_urb(urb);
948972
err_urb:
973+
kfree(rx_buf);
974+
err_rxb:
949975
ath9k_hif_usb_dealloc_reg_in_urbs(hif_dev);
950976
return ret;
951977
}

drivers/net/wireless/ath/ath9k/hif_usb.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ struct tx_buf {
8686
struct list_head list;
8787
};
8888

89+
struct rx_buf {
90+
struct sk_buff *skb;
91+
struct hif_device_usb *hif_dev;
92+
};
93+
8994
#define HIF_USB_TX_STOP BIT(0)
9095
#define HIF_USB_TX_FLUSH BIT(1)
9196

0 commit comments

Comments
 (0)