Skip to content

Commit 355f16f

Browse files
pchelkin91gregkh
authored andcommitted
wifi: ath9k: hif_usb: Fix use-after-free in ath9k_hif_usb_reg_in_cb()
[ Upstream commit dd95f22 ] It is possible that skb is freed in ath9k_htc_rx_msg(), then usb_submit_urb() fails and we try to free skb again. It causes use-after-free bug. Moreover, if alloc_skb() fails, urb->context becomes NULL but rx_buf is not freed and there can be a memory leak. The patch removes unnecessary nskb and makes skb processing more clear: it is supposed that ath9k_htc_rx_msg() either frees old skb or passes its managing to another callback function. Found by Linux Verification Center (linuxtesting.org) with Syzkaller. Fixes: 3deff76 ("ath9k_htc: Increase URB count for REG_IN pipe") Signed-off-by: Fedor Pchelkin <[email protected]> Signed-off-by: Alexey Khoroshilov <[email protected]> Acked-by: Toke Høiland-Jørgensen <[email protected]> Signed-off-by: Kalle Valo <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sasha Levin <[email protected]>
1 parent d856f75 commit 355f16f

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

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

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -709,14 +709,13 @@ static void ath9k_hif_usb_reg_in_cb(struct urb *urb)
709709
struct rx_buf *rx_buf = (struct rx_buf *)urb->context;
710710
struct hif_device_usb *hif_dev = rx_buf->hif_dev;
711711
struct sk_buff *skb = rx_buf->skb;
712-
struct sk_buff *nskb;
713712
int ret;
714713

715714
if (!skb)
716715
return;
717716

718717
if (!hif_dev)
719-
goto free;
718+
goto free_skb;
720719

721720
switch (urb->status) {
722721
case 0:
@@ -725,7 +724,7 @@ static void ath9k_hif_usb_reg_in_cb(struct urb *urb)
725724
case -ECONNRESET:
726725
case -ENODEV:
727726
case -ESHUTDOWN:
728-
goto free;
727+
goto free_skb;
729728
default:
730729
skb_reset_tail_pointer(skb);
731730
skb_trim(skb, 0);
@@ -736,25 +735,27 @@ static void ath9k_hif_usb_reg_in_cb(struct urb *urb)
736735
if (likely(urb->actual_length != 0)) {
737736
skb_put(skb, urb->actual_length);
738737

739-
/* Process the command first */
738+
/*
739+
* Process the command first.
740+
* skb is either freed here or passed to be
741+
* managed to another callback function.
742+
*/
740743
ath9k_htc_rx_msg(hif_dev->htc_handle, skb,
741744
skb->len, USB_REG_IN_PIPE);
742745

743-
744-
nskb = alloc_skb(MAX_REG_IN_BUF_SIZE, GFP_ATOMIC);
745-
if (!nskb) {
746+
skb = alloc_skb(MAX_REG_IN_BUF_SIZE, GFP_ATOMIC);
747+
if (!skb) {
746748
dev_err(&hif_dev->udev->dev,
747749
"ath9k_htc: REG_IN memory allocation failure\n");
748-
urb->context = NULL;
749-
return;
750+
goto free_rx_buf;
750751
}
751752

752-
rx_buf->skb = nskb;
753+
rx_buf->skb = skb;
753754

754755
usb_fill_int_urb(urb, hif_dev->udev,
755756
usb_rcvintpipe(hif_dev->udev,
756757
USB_REG_IN_PIPE),
757-
nskb->data, MAX_REG_IN_BUF_SIZE,
758+
skb->data, MAX_REG_IN_BUF_SIZE,
758759
ath9k_hif_usb_reg_in_cb, rx_buf, 1);
759760
}
760761

@@ -763,12 +764,13 @@ static void ath9k_hif_usb_reg_in_cb(struct urb *urb)
763764
ret = usb_submit_urb(urb, GFP_ATOMIC);
764765
if (ret) {
765766
usb_unanchor_urb(urb);
766-
goto free;
767+
goto free_skb;
767768
}
768769

769770
return;
770-
free:
771+
free_skb:
771772
kfree_skb(skb);
773+
free_rx_buf:
772774
kfree(rx_buf);
773775
urb->context = NULL;
774776
}

0 commit comments

Comments
 (0)