Received: by 2002:a05:7412:8d11:b0:fa:4934:9f with SMTP id bj17csp291566rdb; Sun, 14 Jan 2024 18:05:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IFnJlIY9nfYFwo8AvjMP/F6Xus5cBhSRmf/i/54QjpkQmQ4/M6QA/jxuDYFkUiBzniZe2ie X-Received: by 2002:a17:907:9302:b0:a29:51e8:ef2c with SMTP id bu2-20020a170907930200b00a2951e8ef2cmr2794604ejc.84.1705284309713; Sun, 14 Jan 2024 18:05:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705284309; cv=none; d=google.com; s=arc-20160816; b=YNR/jj4mtkQ9o7CeMSR1S/qMYKrEcPtDuU9IazXkVCFZK13PsQQVg8yFF8Qd3Hbw1y ve6L2IlxakyQjW4IB81YviDOGtx1j7R1XbB55y1VYq+VEcjeHbmL9155rJNBNxBnHrD/ hObgpxByU2zWkIE9n62xaGmiAvqdQTPJETCgU8Sq43V1AZEuRNGZA3p72WXNsAjjTrQZ rz5onOjc/zNqqyHQERihoaJgccuXlFV0J99Cr6PS/kKWA4DDfpNMQsP02JXCFALYMX+F WfEhCUtJzbeeuWgzP4SdxLUXNPW+MAwdcmxQQTVTCpYLakV+TRIKl6yT/9vQlgAUqHJq 0SXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :content-transfer-encoding:content-language:accept-language :in-reply-to:references:message-id:date:thread-index:thread-topic :subject:cc:to:from; bh=LUCD7Dn8Kl0P68+wPRBEis5w3FdksNdB0p1AgRrQs0k=; fh=yPDYK5+/ADxsiQO0jM8yra2YGuwx05G9bbO1iRqZWiE=; b=vFrSszLMIi9bLvQnrr/YszrEop/0/1BVgnAGcndz7X0U1tzSzB7FMUTL348CSOi87E neseGwUj6MiqF2uM8TrKEOFu0oF6kyZbWa2VGprOUY+slZeNz2r/CBmnVR0QSPY7z2C1 S+tVvOPb4m0lZzmt4ovCeXi3qWJ152VW4jF5Zvr9RNmS+G2xDqaTDs4W36E//5hFUm29 L8TGVAXOuUBao16U4OhuiNkyo9NtcUjq+pK+MJhMMOwtiZhWyleJCx13Tv4XqegpIF3E 7oUWsFnGcMuK3Zvn8o7iXh8W2useatbgTWYSSgbDPlLbnTs4w3rv5hd/FObOqnP7yE3O fsfQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-wireless+bounces-1898-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-wireless+bounces-1898-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id d23-20020a1709067f1700b00a28ac1176c1si3231861ejr.465.2024.01.14.18.05.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Jan 2024 18:05:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-wireless+bounces-1898-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-wireless+bounces-1898-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-wireless+bounces-1898-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 1B5AD1F2128B for ; Mon, 15 Jan 2024 02:05:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5549E15BE; Mon, 15 Jan 2024 02:05:02 +0000 (UTC) X-Original-To: linux-wireless@vger.kernel.org Received: from rtits2.realtek.com.tw (rtits2.realtek.com [211.75.126.72]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 485F715BB for ; Mon, 15 Jan 2024 02:04:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=realtek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=realtek.com X-SpamFilter-By: ArmorX SpamTrap 5.78 with qID 40F23tY023479368, This message is accepted by code: ctloc85258 Received: from mail.realtek.com (rtexh36506.realtek.com.tw[172.21.6.27]) by rtits2.realtek.com.tw (8.15.2/2.95/5.92) with ESMTPS id 40F23tY023479368 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 15 Jan 2024 10:03:55 +0800 Received: from RTEXMBS03.realtek.com.tw (172.21.6.96) by RTEXH36506.realtek.com.tw (172.21.6.27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.17; Mon, 15 Jan 2024 10:03:55 +0800 Received: from RTEXMBS04.realtek.com.tw (172.21.6.97) by RTEXMBS03.realtek.com.tw (172.21.6.96) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Mon, 15 Jan 2024 10:03:55 +0800 Received: from RTEXMBS04.realtek.com.tw ([fe80::e4c4:c4f:4e4c:d23c]) by RTEXMBS04.realtek.com.tw ([fe80::e4c4:c4f:4e4c:d23c%5]) with mapi id 15.01.2507.035; Mon, 15 Jan 2024 10:03:55 +0800 From: Ping-Ke Shih To: Deren Wu , Felix Fietkau , "Lorenzo Bianconi" CC: Sean Wang , Soul Huang , Ming Yen Hsieh , Leon Yen , Eric-SY Chang , KM Lin , Robin Chiu , CH Yeh , Posh Sun , Quan Zhou , Ryder Lee , Shayne Chen , linux-wireless , linux-mediatek Subject: RE: [PATCH 1/2] wifi: mt76: mt7921e: fix use-after-free in free_irq() Thread-Topic: [PATCH 1/2] wifi: mt76: mt7921e: fix use-after-free in free_irq() Thread-Index: AQHaRf8Mfdr/M2DJQ0qJZHApLacQLbDaIV+w Date: Mon, 15 Jan 2024 02:03:54 +0000 Message-ID: <3a3fc58206ec436e8cdfd97d71350795@realtek.com> References: <572d6af305a09fc8bdd96a8ee57399039803a2bb.1705135817.git.deren.wu@mediatek.com> In-Reply-To: <572d6af305a09fc8bdd96a8ee57399039803a2bb.1705135817.git.deren.wu@mediatek.com> Accept-Language: en-US, zh-TW Content-Language: zh-TW x-kse-serverinfo: RTEXMBS03.realtek.com.tw, 9 x-kse-antispam-interceptor-info: fallback x-kse-antivirus-interceptor-info: fallback Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Precedence: bulk X-Mailing-List: linux-wireless@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-KSE-AntiSpam-Interceptor-Info: fallback > -----Original Message----- > From: Deren Wu > Sent: Saturday, January 13, 2024 5:00 PM > To: Felix Fietkau ; Lorenzo Bianconi > Cc: Sean Wang ; Soul Huang ; Ming Yen Hsieh > ; Leon Yen ; Eric-SY C= hang > ; KM Lin ; Robin Chiu ; CH Yeh > ; Posh Sun ; Quan Zhou ; Ryder Lee > ; Shayne Chen ; linux-w= ireless > ; linux-mediatek ; Deren Wu > > Subject: [PATCH 1/2] wifi: mt76: mt7921e: fix use-after-free in free_irq(= ) >=20 > From commit a304e1b82808 ("[PATCH] Debug shared irqs"), there is a test > to make sure the shared irq handler should be able to handle the unexpect= ed > event after deregistration. For this case, let's apply MT76_REMOVED flag = to > indicate the device was removed and do not run into the resource access > anymore. >=20 > BUG: KASAN: use-after-free in mt7921_irq_handler+0xd8/0x100 [mt7921e] > Read of size 8 at addr ffff88824a7d3b78 by task rmmod/11115 > CPU: 28 PID: 11115 Comm: rmmod Tainted: G W L 5.17.0 #10 > Hardware name: Micro-Star International Co., Ltd. MS-7D73/MPG B650I > EDGE WIFI (MS-7D73), BIOS 1.81 01/05/2024 > Call Trace: > > dump_stack_lvl+0x6f/0xa0 > print_address_description.constprop.0+0x1f/0x190 > ? mt7921_irq_handler+0xd8/0x100 [mt7921e] > ? mt7921_irq_handler+0xd8/0x100 [mt7921e] > kasan_report.cold+0x7f/0x11b > ? mt7921_irq_handler+0xd8/0x100 [mt7921e] > mt7921_irq_handler+0xd8/0x100 [mt7921e] > free_irq+0x627/0xaa0 > devm_free_irq+0x94/0xd0 > ? devm_request_any_context_irq+0x160/0x160 > ? kobject_put+0x18d/0x4a0 > mt7921_pci_remove+0x153/0x190 [mt7921e] > pci_device_remove+0xa2/0x1d0 > __device_release_driver+0x346/0x6e0 > driver_detach+0x1ef/0x2c0 > bus_remove_driver+0xe7/0x2d0 > ? __check_object_size+0x57/0x310 > pci_unregister_driver+0x26/0x250 > __do_sys_delete_module+0x307/0x510 > ? free_module+0x6a0/0x6a0 > ? fpregs_assert_state_consistent+0x4b/0xb0 > ? rcu_read_lock_sched_held+0x10/0x70 > ? syscall_enter_from_user_mode+0x20/0x70 > ? trace_hardirqs_on+0x1c/0x130 > do_syscall_64+0x5c/0x80 > ? trace_hardirqs_on_prepare+0x72/0x160 > ? do_syscall_64+0x68/0x80 > ? trace_hardirqs_on_prepare+0x72/0x160 > entry_SYSCALL_64_after_hwframe+0x44/0xae >=20 > Reported-by: Mikhail Gavrilov > Closes: > https://lore.kernel.org/linux-wireless/CABXGCsOdvVwdLmSsC8TZ1jF0UOg_F_W3w= qLECWX620PUkvNk=3DA@mail.gmail. > com/ > Fixes: 9270270d6219 ("wifi: mt76: mt7921: fix PCI DMA hang after reboot") > Tested-by: Mikhail Gavrilov > Signed-off-by: Deren Wu > --- > drivers/net/wireless/mediatek/mt76/mt7921/pci.c | 1 + > drivers/net/wireless/mediatek/mt76/mt792x_dma.c | 2 ++ > 2 files changed, 3 insertions(+) >=20 > diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/pci.c > b/drivers/net/wireless/mediatek/mt76/mt7921/pci.c > index 57903c6e4f11..2f04d6658b6b 100644 > --- a/drivers/net/wireless/mediatek/mt76/mt7921/pci.c > +++ b/drivers/net/wireless/mediatek/mt76/mt7921/pci.c > @@ -387,6 +387,7 @@ static void mt7921_pci_remove(struct pci_dev *pdev) > struct mt792x_dev *dev =3D container_of(mdev, struct mt792x_dev, = mt76); >=20 > mt7921e_unregister_device(dev); > + set_bit(MT76_REMOVED, &mdev->phy.state); Can it do below like mt7921_pci_suspend() to safely stop interrupt handler? Instead of setting a flag.=20 synchronize_irq(pdev->irq); tasklet_kill(&mdev->irq_tasklet); > devm_free_irq(&pdev->dev, pdev->irq, dev); > mt76_free_device(&dev->mt76); > pci_free_irq_vectors(pdev); > diff --git a/drivers/net/wireless/mediatek/mt76/mt792x_dma.c > b/drivers/net/wireless/mediatek/mt76/mt792x_dma.c > index 488326ce5ed4..3893dbe866fe 100644 > --- a/drivers/net/wireless/mediatek/mt76/mt792x_dma.c > +++ b/drivers/net/wireless/mediatek/mt76/mt792x_dma.c > @@ -12,6 +12,8 @@ irqreturn_t mt792x_irq_handler(int irq, void *dev_insta= nce) > { > struct mt792x_dev *dev =3D dev_instance; >=20 If PCI is removed, is it still safe to access 'dev_instance'? > + if (test_bit(MT76_REMOVED, &dev->mt76.phy.state)) > + return IRQ_NONE; > mt76_wr(dev, dev->irq_map->host_irq_enable, 0); >=20 > if (!test_bit(MT76_STATE_INITIALIZED, &dev->mphy.state)) > -- > 2.18.0 >=20