Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp12370000rwl; Tue, 3 Jan 2023 13:19:13 -0800 (PST) X-Google-Smtp-Source: AMrXdXu0jL0Bgsis/Ed40GlbZ+zmi6aScmb/ddRgIvVh5RMGfMso8HCFl19bPND6nyooq1jsd4Oe X-Received: by 2002:aa7:c6c2:0:b0:46c:6bdc:4116 with SMTP id b2-20020aa7c6c2000000b0046c6bdc4116mr37124464eds.33.1672780752925; Tue, 03 Jan 2023 13:19:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672780752; cv=none; d=google.com; s=arc-20160816; b=zKkjlXpRSSPPRML+agKn5G7uW3gNJNXFSJXJ7+NFhPkLqaj4Juf/pJEIGZ2OfimHMW CLH8mdF/vVoTTd2a2y2fdLMdKQ1xsFjV6ptXcTiZv/6MdPi0khLHcmvcKLGD6EQ2TiV6 rVz1QDr9zpQAw0yPDL3F8MUkS86Zf5Jse9Fk+Iqe4Mt+A5u1eqW8GpGSFt461m9vyeUX XK9VpqvM+Pekd/cxPEGNFL60y6TcRS1+/WBTrB7WLCJ2qT9/ckz1Pu1GeYjKOXo0qYcA qM91zmVkZtPPqPBemURZqu5+UnxOwwef9Ie2i81A2DA3pWZdVS8RAjH/8vX5BX8wzySh ibtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:dkim-signature:from; bh=4ooSZ0ZspYMLbv2GW5Q/XWd6wI5x8nvaKEYwpNeo8Lg=; b=mZ2GR98ptJENUQqZTbVNmCLBBjGcuNMg75RsViW8GTYJHFPAT42Q9TB8QsqXYopvsE 079dHHWlFwPxt/T3z3dtpj7nc89WvrrxANqOlGu5r8krixDCPclGgz05JBAOxJ1gWNxz j3/XYpb6jBu13tJQQItwU0yiB93oLvKqsxZPCG4DE3m6yuDnPm+mU1i5HgpU/De4nMdN 26lWmYKO0yfeHWKMdsZm8e9ACpwp+mPaLB4aXKZxEKlMGTR9yW7ieXWF8708sPqj1pGg i6PPO7U6mPDouAmtqqpVRZ50uWFw2+jU2ON7aCC74rHAhr2Si4YjYdWmZ+3aK0l4/KVB x8dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@toke.dk header.s=20161023 header.b=WQD6xWiF; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=toke.dk Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ds16-20020a0564021cd000b0048eda35a868si1540133edb.222.2023.01.03.13.18.56; Tue, 03 Jan 2023 13:19:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@toke.dk header.s=20161023 header.b=WQD6xWiF; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=toke.dk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233966AbjACVDL (ORCPT + 67 others); Tue, 3 Jan 2023 16:03:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231226AbjACVDJ (ORCPT ); Tue, 3 Jan 2023 16:03:09 -0500 Received: from mail.toke.dk (mail.toke.dk [45.145.95.4]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD5252FD; Tue, 3 Jan 2023 13:03:07 -0800 (PST) From: Toke =?utf-8?Q?H=C3=B8iland-J=C3=B8rgensen?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=toke.dk; s=20161023; t=1672779785; bh=8XlWB7q8ieR1Skm6kedaC7CKs/VrhNaK24zO4/mpaWc=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=WQD6xWiFOItdmSw8E4C6MmPRZGzaa27UqsPNuxYzUfDtmk5Zv8Wpzfau4VHJptE4q tiLlYS3QEIezMbi4fRG4BcUe4j2SKMDkhF4Mc+rrS9APvCVHKPhTMt5wbFNjbXkixw CbQvAy6iXJdoIQAJXziSwBQEE5BuMnifNzlERhw0MMkRvvI2xD1E//2yhaI4cUdV1B VxfiDEYI1nIeV51lVrPcWaV8qiEoazJysGfA537AEKf3SahNDDmT9usDm/HQTWK+dd TU+OOOyMmeq+iJYPsDLo+RC52OuzHDoKKDtMgd9pltZFStTlgwrfbiU3HgO7djIOAt AqdyHNu9GPSPA== To: Fedor Pchelkin , Kalle Valo Cc: Fedor Pchelkin , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Zekun Shen , Joe Perches , "John W. Linville" , linux-wireless@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Alexey Khoroshilov , 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 In-Reply-To: <20230103143029.273695-1-pchelkin@ispras.ru> References: <20230103143029.273695-1-pchelkin@ispras.ru> Date: Tue, 03 Jan 2023 22:03:05 +0100 X-Clacks-Overhead: GNU Terry Pratchett Message-ID: <875ydn49h2.fsf@toke.dk> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Fedor Pchelkin 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 > Signed-off-by: Alexey Khoroshilov > --- > 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