Received: by 2002:ac0:f2c4:0:0:0:0:0 with SMTP id f4csp2188539imp; Mon, 25 Jul 2022 08:21:01 -0700 (PDT) X-Google-Smtp-Source: AGRyM1s/AFgIsnLF18p/TcXQ4YIcrGEKQYIWvIxgeKpb01hWMzwLLnfokBbC4gY2kwATcB3/c/rg X-Received: by 2002:a05:6402:358a:b0:43b:ce8f:df00 with SMTP id y10-20020a056402358a00b0043bce8fdf00mr13923049edc.219.1658762461746; Mon, 25 Jul 2022 08:21:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658762461; cv=none; d=google.com; s=arc-20160816; b=vrWE3CTJfOyn8PQ2QMXCjm/X7QReguVQhFGr6osOrSunCCB1JPHAyJ1DSgxekFV0gu bS+se7kWjj4z2aGj+c8VBMiNvZ3h/SCrlEOx4fSBuLuQRUZXq5WNtYN3/dW02DjZTOXP RUNRCZe8IXo9y2upFen9mxmfKDQwh+m7yEtlcL6Y5vR3Bg4zY/c0P2Y/HbTPtOX6YVtj 3eqB0N1cGOIN7YvtT0VYoXBXCk3cUR9fdnA1LrBpSgc+wWR0zxHOePKpfphclmwpXvQM 1feCjvETwtu8gPeercRpKZGm1h2Dld3zgSVDdYjju6F9tp9w8x+7MilySg5ldpk7ZLAn tDsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=suPgtTHs0qqMkxYqwAlBDtVgJ82ShTiDD5sPiQ7zs/M=; b=V2CElen06tUxoXb3pS84kVgA09fjlZrC8mlCRqvsE0G3ChdVkpY+BsaufD7163+E2e FheRU4NRVnryUi2t9nkxtODWqtowZDFnZ0AW0CtblvA1371r+XlTLeuENpuRHx6u0sRv r6ZWTckcL1S3ny7n9Y93o/G7OaAIjoKaHDr6Hp+yZDTUZyZzk1wnAeQPTSxma/xTyXRx /PxaD9Q8kJRd19jt+4GiKLADsfDz674+ki+iaLMA9r+XHr0O2WkdWvcGCru52EvQSciG /HXccsf2L4cCyHjxJaDtYC/FmyHm2M5D2opgk0FucttpVEC9G8prUWcAdKHwPhCzpN7X 37vA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hq20-20020a1709073f1400b0072b9928acfesi7941628ejc.581.2022.07.25.08.20.41; Mon, 25 Jul 2022 08:21:01 -0700 (PDT) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236224AbiGYPRz (ORCPT + 65 others); Mon, 25 Jul 2022 11:17:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235949AbiGYPRj (ORCPT ); Mon, 25 Jul 2022 11:17:39 -0400 Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2E121BEAF; Mon, 25 Jul 2022 08:14:47 -0700 (PDT) Received: from localhost.localdomain (unknown [83.149.199.65]) by mail.ispras.ru (Postfix) with ESMTPSA id A648D40D403D; Mon, 25 Jul 2022 15:14:16 +0000 (UTC) From: Fedor Pchelkin To: =?UTF-8?q?Toke=20H=C3=B8iland-J=C3=B8rgensen?= , Kalle Valo Cc: Fedor Pchelkin , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Brooke Basile , linux-wireless@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Alexey Khoroshilov Subject: [PATCH] ath9k: hif_usb: fix memory leak of urbs in ath9k_hif_usb_dealloc_tx_urbs() Date: Mon, 25 Jul 2022 18:13:59 +0300 Message-Id: <20220725151359.283704-1-pchelkin@ispras.ru> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,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 Syzkaller reports a long-known leak of urbs in ath9k_hif_usb_dealloc_tx_urbs(). The cause of the leak is that usb_get_urb() is called but usb_free_urb() (or usb_put_urb()) is not called inside usb_kill_urb() as urb->dev or urb->ep fields have not been initialized and usb_kill_urb() returns immediately. The patch removes trying to kill urbs located in hif_dev->tx.tx_buf because hif_dev->tx.tx_buf is not supposed to contain urbs which are in pending state (the pending urbs are stored in hif_dev->tx.tx_pending). The tx.tx_lock is acquired so there should not be any changes in the list. Found by Linux Verification Center (linuxtesting.org) with Syzkaller. Fixes: 03fb92a432ea ("ath9k: hif_usb: fix race condition between usb_get_urb() and usb_kill_anchored_urbs()") Signed-off-by: Fedor Pchelkin Signed-off-by: Alexey Khoroshilov --- drivers/net/wireless/ath/ath9k/hif_usb.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/drivers/net/wireless/ath/ath9k/hif_usb.c b/drivers/net/wireless/ath/ath9k/hif_usb.c index 518deb5098a2..2d2cd895a9d4 100644 --- a/drivers/net/wireless/ath/ath9k/hif_usb.c +++ b/drivers/net/wireless/ath/ath9k/hif_usb.c @@ -780,14 +780,10 @@ static void ath9k_hif_usb_dealloc_tx_urbs(struct hif_device_usb *hif_dev) spin_lock_irqsave(&hif_dev->tx.tx_lock, flags); list_for_each_entry_safe(tx_buf, tx_buf_tmp, &hif_dev->tx.tx_buf, list) { - usb_get_urb(tx_buf->urb); - spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags); - usb_kill_urb(tx_buf->urb); list_del(&tx_buf->list); usb_free_urb(tx_buf->urb); kfree(tx_buf->buf); kfree(tx_buf); - spin_lock_irqsave(&hif_dev->tx.tx_lock, flags); } spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags); -- 2.25.1