Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp613990pxx; Wed, 28 Oct 2020 12:25:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyGDpEnfHfTtlyhhagjVlpyW1nO3QxS29H77NbpXjkTEO+lZxfPHfH9b5nH9vWfi5MQWb7v X-Received: by 2002:a17:906:aecf:: with SMTP id me15mr611720ejb.423.1603913158062; Wed, 28 Oct 2020 12:25:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603913158; cv=none; d=google.com; s=arc-20160816; b=dE26Thg2jeo87xDDWTiRp5fUAJPCrNSpFPjJoA2pU/XkX1nOBXSjWbGyhzjw326xra cjbAWfKc4HT5aVxEe6a+Ba7tpyNL6/Qn4NeUzOdWUZX0H4tRB9XkW2t3jxGG+RgJhnih v8Ox6m9+Ju/5Ib/nWNJ35Tb8ruBYqL8raF//TKj6bidkgh+YBgqzZXIYZtt+0bCvKVhA YVRQJDtH5lVpFvutnp3qWWSZz/+I4pzFXXQIvN2QVreYDrRMsL6PeK3mXhnSwvpkY9x3 CyWCFbaTw1mLanbrBAYH40Bw781m173D5uLCqmgYToo/7ZKTq3KyGO6XhmEm8kWDQDV/ Lm8Q== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=l2pIvi0cAd6wV1PaDHqBYG5C1RPu3twyHLtPZnKxXLc=; b=kz3iA1Np1fMcdaVGvEpM3L6LDwQdOpIlXIWvJQsoEvY3YAw5YGlzmUzRJo+X3ZHj79 /heZVRmfZLVuW+C9xtkW1fRaZMAjkAAAS1rUQiZMquGxcgB/wHUatHJEh4HDiodBZxl8 MyzS2UhYyaoG6afAovtf9Y8xkytgLf14PDaB4syyDesONAzlbVPgzLpjXqdelv9Rag/y VZJ19KOZgLy8Dct+VT/umjA3ffQiP6l5xwaaWQ7hhGIuijkg9cfJ2dv71h3vM0TWVL+v wQ+zOBTGuU7652RG0hxyT9E35KRm++m+EmpxBXJuZtgkVSXHP7p8W4NGerqNyrWK6ks/ CvQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=CM25aGr5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ay1si32292edb.3.2020.10.28.12.25.35; Wed, 28 Oct 2020 12:25:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=CM25aGr5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1827355AbgJ0SXR (ORCPT + 99 others); Tue, 27 Oct 2020 14:23:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:49312 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753707AbgJ0OBe (ORCPT ); Tue, 27 Oct 2020 10:01:34 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E93F8221F8; Tue, 27 Oct 2020 14:01:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603807294; bh=fVk+ieiizZ0zn7gw9zpqvfdKJN+Ujcu01ZMRSE3wul8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CM25aGr5ZLcOt2l1XGUKIJ6K6V0SePOw71LFGaDYhiqi5kjp89fakWoBW1wxVQbPK Pw+hH8wtHIGFeBGQMdpQ0bpq+rvgy7ukYx+lHKAFTl/xl3qSCbvIdScMbdu5xp8Kzf q/luBh/Y3RQSnP+usUCS1pHA/rd+JvDyhxIs3wqg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+89bd486af9427a9fc605@syzkaller.appspotmail.com, Brooke Basile , Kalle Valo , Sasha Levin Subject: [PATCH 4.4 094/112] ath9k: hif_usb: fix race condition between usb_get_urb() and usb_kill_anchored_urbs() Date: Tue, 27 Oct 2020 14:50:04 +0100 Message-Id: <20201027134904.995141765@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027134900.532249571@linuxfoundation.org> References: <20201027134900.532249571@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Brooke Basile [ Upstream commit 03fb92a432ea5abe5909bca1455b7e44a9380480 ] Calls to usb_kill_anchored_urbs() after usb_kill_urb() on multiprocessor systems create a race condition in which usb_kill_anchored_urbs() deallocates the URB before the completer callback is called in usb_kill_urb(), resulting in a use-after-free. To fix this, add proper lock protection to usb_kill_urb() calls that can possibly run concurrently with usb_kill_anchored_urbs(). Reported-by: syzbot+89bd486af9427a9fc605@syzkaller.appspotmail.com Link: https://syzkaller.appspot.com/bug?id=cabffad18eb74197f84871802fd2c5117b61febf Signed-off-by: Brooke Basile Signed-off-by: Kalle Valo Link: https://lore.kernel.org/r/20200911071427.32354-1-brookebasile@gmail.com Signed-off-by: Sasha Levin --- drivers/net/wireless/ath/ath9k/hif_usb.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/drivers/net/wireless/ath/ath9k/hif_usb.c b/drivers/net/wireless/ath/ath9k/hif_usb.c index 76d91859cfde9..75072a8f8cf42 100644 --- a/drivers/net/wireless/ath/ath9k/hif_usb.c +++ b/drivers/net/wireless/ath/ath9k/hif_usb.c @@ -445,10 +445,19 @@ static void hif_usb_stop(void *hif_handle) spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags); /* The pending URBs have to be canceled. */ + spin_lock_irqsave(&hif_dev->tx.tx_lock, flags); list_for_each_entry_safe(tx_buf, tx_buf_tmp, &hif_dev->tx.tx_pending, 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); usb_kill_anchored_urbs(&hif_dev->mgmt_submitted); } @@ -758,27 +767,37 @@ static void ath9k_hif_usb_dealloc_tx_urbs(struct hif_device_usb *hif_dev) struct tx_buf *tx_buf = NULL, *tx_buf_tmp = NULL; unsigned long flags; + 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); spin_lock_irqsave(&hif_dev->tx.tx_lock, flags); hif_dev->tx.flags |= HIF_USB_TX_FLUSH; spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags); + spin_lock_irqsave(&hif_dev->tx.tx_lock, flags); list_for_each_entry_safe(tx_buf, tx_buf_tmp, &hif_dev->tx.tx_pending, 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); usb_kill_anchored_urbs(&hif_dev->mgmt_submitted); } -- 2.25.1