All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Toke Høiland-Jørgensen" <toke@toke.dk>
To: Fedor Pchelkin <pchelkin@ispras.ru>, Kalle Valo <kvalo@kernel.org>
Cc: Fedor Pchelkin <pchelkin@ispras.ru>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Zekun Shen <bruceshenzk@gmail.com>, Joe Perches <joe@perches.com>,
	"John W. Linville" <linville@tuxdriver.com>,
	linux-wireless@vger.kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Alexey Khoroshilov <khoroshilov@ispras.ru>,
	lvc-project@linuxtesting.org,
	syzbot+e9632e3eb038d93d6bc6@syzkaller.appspotmail.com
Subject: Re: [PATCH v2] wifi: ath9k: hif_usb: clean up skbs if ath9k_hif_usb_rx_stream() fails
Date: Tue, 03 Jan 2023 22:03:05 +0100	[thread overview]
Message-ID: <875ydn49h2.fsf@toke.dk> (raw)
In-Reply-To: <20230103143029.273695-1-pchelkin@ispras.ru>

Fedor Pchelkin <pchelkin@ispras.ru> writes:

> Syzkaller detected a memory leak of skbs in ath9k_hif_usb_rx_stream().
> While processing skbs in ath9k_hif_usb_rx_stream(), the already allocated
> skbs in skb_pool are not freed if ath9k_hif_usb_rx_stream() fails. If we
> have an incorrect pkt_len or pkt_tag, the skb is dropped and all the
> associated skb_pool buffers should be cleaned, too.
>
> Found by Linux Verification Center (linuxtesting.org) with Syzkaller.
>
> Fixes: 6ce708f54cc8 ("ath9k: Fix out-of-bound memcpy in ath9k_hif_usb_rx_stream")
> Fixes: 44b23b488d44 ("ath9k: hif_usb: Reduce indent 1 column")
> Reported-by: syzbot+e9632e3eb038d93d6bc6@syzkaller.appspotmail.com
> Signed-off-by: Fedor Pchelkin <pchelkin@ispras.ru>
> Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
> ---
> v1->v2: added Reported-by tag
>
>  drivers/net/wireless/ath/ath9k/hif_usb.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/wireless/ath/ath9k/hif_usb.c b/drivers/net/wireless/ath/ath9k/hif_usb.c
> index 1a2e0c7eeb02..d02cec114280 100644
> --- a/drivers/net/wireless/ath/ath9k/hif_usb.c
> +++ b/drivers/net/wireless/ath/ath9k/hif_usb.c
> @@ -586,14 +586,14 @@ static void ath9k_hif_usb_rx_stream(struct hif_device_usb *hif_dev,
>  
>  		if (pkt_tag != ATH_USB_RX_STREAM_MODE_TAG) {
>  			RX_STAT_INC(hif_dev, skb_dropped);
> -			return;
> +			goto invalid_pkt;
>  		}
>  
>  		if (pkt_len > 2 * MAX_RX_BUF_SIZE) {
>  			dev_err(&hif_dev->udev->dev,
>  				"ath9k_htc: invalid pkt_len (%x)\n", pkt_len);
>  			RX_STAT_INC(hif_dev, skb_dropped);
> -			return;
> +			goto invalid_pkt;
>  		}
>  
>  		pad_len = 4 - (pkt_len & 0x3);
> @@ -654,6 +654,11 @@ static void ath9k_hif_usb_rx_stream(struct hif_device_usb *hif_dev,
>  				 skb_pool[i]->len, USB_WLAN_RX_PIPE);
>  		RX_STAT_INC(hif_dev, skb_completed);
>  	}
> +	return;
> +invalid_pkt:
> +	for (i = 0; i < pool_index; i++)
> +		kfree_skb(skb_pool[i]);
> +	return;

Hmm, so in the other error cases (if SKB allocation fails), we just
'goto err' and call the receive handler for the packets already in
skb_pool. Why can't we do the same here?

Also, I think there's another bug in that function, which this change
will make worse? Specifically, in the start of that function,
hif_dev->remain_skb is moved to skb_pool[0], but not cleared from
hif_dev itself. So if we then hit the invalid check and free it, the
next time the function is called, we'll get the same remain_skb pointer,
which has now been freed.

So I think we'll need to clear out hif_dev->remain_skb after moving it
to skb_pool. Care to add that as well?

-Toke

  reply	other threads:[~2023-01-03 21:03 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-28 22:40 [PATCH] wifi: ath9k: hif_usb: clean up skbs if ath9k_hif_usb_rx_stream() fails Fedor Pchelkin
2023-01-02 10:52 ` Toke Høiland-Jørgensen
2023-01-03 14:29   ` Fedor Pchelkin
2023-01-03 20:18     ` Toke Høiland-Jørgensen
2023-01-03 14:30   ` [PATCH v2] " Fedor Pchelkin
2023-01-03 21:03     ` Toke Høiland-Jørgensen [this message]
2023-01-03 22:30       ` Fedor Pchelkin
2023-01-03 23:38         ` Toke Høiland-Jørgensen
2023-01-04 12:36           ` [PATCH v3] " Fedor Pchelkin
2023-01-04 14:50             ` Toke Høiland-Jørgensen
2023-01-17 11:53             ` Kalle Valo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=875ydn49h2.fsf@toke.dk \
    --to=toke@toke.dk \
    --cc=bruceshenzk@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=joe@perches.com \
    --cc=khoroshilov@ispras.ru \
    --cc=kuba@kernel.org \
    --cc=kvalo@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=linville@tuxdriver.com \
    --cc=lvc-project@linuxtesting.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=pchelkin@ispras.ru \
    --cc=syzbot+e9632e3eb038d93d6bc6@syzkaller.appspotmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.