From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=220.197.31.4 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796546437; b=EgQfFGIunC+j7Jo5qJnP9wcUDk98GaEG0XH/vJ0BzCwY5ht8cPhG/oZ6p1dy2dZ0i8RQ GVFDouy9/ssPp769W9dHAVRjQwt2kF0EtFcQJZxwvubffRpu8VLE4yEcyIncYW+FIcISw P7WMrMKY+LTb4LjdRYUTTlvUAGfhGgKyKCnlHl/+IUvIPBMxN3jpFRMWLiR+c51ZhWrkC r5eRiyUFOLz79w71tPL1R0wxudPe1IsyPDojvpOfm6RGc0oXX63DFJXRz8x+Vk5hIFLfh d2lF/saZuoq9BNmENIV/VMnJJ+m3QGjNOvvHWrEiCu6/XvIIa+6l+9hBiD0a5p2/umw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796546437; h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailer:MIME-Version:Content-Transfer-Encoding: X-CM-TRANSID:X-Coremail-Antispam:X-CM-SenderInfo; bh=eZFC4W+aGc+UYKB1zfU798/IBAINguBThfzqqpzatps=; b=ujvpVt80gy8AgIGhUIM6wwCZb7qb3bwiwwWwVR7owStKF/Or3iBv0ohUdQE4XYqck7S/ ZHp/atH5R2LLrabTP2DHrfFS8ZgwbNkfmZwMh/K1omYjZ3AWHKkh6GwFnRuth0rhyARmO qvLHil70T+1Sa2RRRI4E8vtIvbIdv1VAimachmrHY1BoAnjHw8HDSdfcnFdaK3rhKozDQ hoGneleVncuhIc9m6Wff6xoM9eD01H4sLNG202z2kgJrWyZgXZiFotZLEbksleUNAnMIq OEjzkH2baWIldBwk6NY4i5WUzgmcCDQHZQsUkBsVV1Sa5GDovwM5PzSlS26dnnb3mLQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=DU4Bl21D; arc=none smtp.remote-ip=220.197.31.4 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E6F2B606A31F; Sun, 6 Dec 2026 08:40:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E6F2B606A31F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=DU4Bl21D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=eZ FC4W+aGc+UYKB1zfU798/IBAINguBThfzqqpzatps=; b=DU4Bl21DpCgyyZ1Act RyLzCKjc7MiPGdk5sWfXOcrLCXkObjrJ93nofwjMq/bh1bUanuQLEP/uiMcBKgu9 a4F5kXqu/H/RAA5LiHNIMDWdAMxyPF7TP+f8+QWwXvwxNdmCsewX/U3nzIFB4Mzh //TeR93GYOHfQW377K+rtheok= Received: from localhost.localdomain (unknown []) by gzsmtp5 (Coremail) with SMTP id QCgvCgCXipR0HxVrl+awKA--.30940S2; Sun, 06 Dec 2026 16:40:21 +0800 (CST) From: Ziheng Wei To: Cheng Xu , Kai Shen , Jason Gunthorpe , Leon Romanovsky Cc: linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH] RDMA/erdma: free common IRQ before destroying CMDQ and AEQ Date: Sun, 6 Dec 2026 16:40:19 +0800 Message-ID: <20261206084019.4331-1-zihengw03@163.com> X-Mailer: git-send-email 2.54.0 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:QCgvCgCXipR0HxVrl+awKA--.30940S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxZryUKr18tFW5Kr47Jr45GFg_yoW5XF4fp3 ZxG3WfKryktrs8Wr47Ca109FyUJas3t3y7G3yUGw13XF1Yyws0vF18tryxCa4UJa9xA3Wx tFy5tF1rCwn5XaUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jmlksUUUUU= X-CM-SenderInfo: p2lkv0ljzqjqqrwthudrp/xtbC7RUFVWsVH3XuYAAA3y erdma_remove_dev() and the error unwind path of erdma_probe_dev() call erdma_cmdq_destroy() and erdma_eq_destroy(dev, &dev->aeq) before erdma_comm_irq_uninit(). Because erdma_hw_reset() does not wait for an already in-flight erdma_comm_irq_handler() to finish, freeing the CMDQ and AEQ DMA rings before free_irq() can cause a use-after-free in erdma_cmdq_completion_handler() or erdma_aeq_event_handler(). Similarly, erdma_probe_dev() requests the common IRQ before initializing the AEQ and CMDQ. Request the common IRQ after initializing the AEQ and CMDQ, and call erdma_comm_irq_uninit() before destroying the CMDQ and AEQ in both erdma_probe_dev() error unwind and erdma_remove_dev(). Found by LLM-assisted static analysis. Compile-tested on x86_64. Fixes: d55e6fb4803c ("RDMA/erdma: Add the erdma module") Cc: stable@vger.kernel.org Signed-off-by: Ziheng Wei --- drivers/infiniband/hw/erdma/erdma_main.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/infiniband/hw/erdma/erdma_main.c b/drivers/infiniband/hw/erdma/erdma_main.c index 62dc22388..49dd79e7f 100644 --- a/drivers/infiniband/hw/erdma/erdma_main.c +++ b/drivers/infiniband/hw/erdma/erdma_main.c @@ -295,22 +295,22 @@ static int erdma_probe_dev(struct pci_dev *pdev) if (err) goto err_uninit_device; - err = erdma_comm_irq_init(dev); - if (err) - goto err_free_vectors; - err = erdma_aeq_init(dev); if (err) - goto err_uninit_comm_irq; + goto err_free_vectors; err = erdma_cmdq_init(dev); if (err) goto err_uninit_aeq; - err = erdma_wait_hw_init_done(dev); + err = erdma_comm_irq_init(dev); if (err) goto err_uninit_cmdq; + err = erdma_wait_hw_init_done(dev); + if (err) + goto err_uninit_comm_irq; + err = erdma_ceqs_init(dev); if (err) goto err_reset_hw; @@ -322,15 +322,15 @@ static int erdma_probe_dev(struct pci_dev *pdev) err_reset_hw: erdma_hw_reset(dev); +err_uninit_comm_irq: + erdma_comm_irq_uninit(dev); + err_uninit_cmdq: erdma_cmdq_destroy(dev); err_uninit_aeq: erdma_eq_destroy(dev, &dev->aeq); -err_uninit_comm_irq: - erdma_comm_irq_uninit(dev); - err_free_vectors: pci_free_irq_vectors(dev->pdev); @@ -358,9 +358,9 @@ static void erdma_remove_dev(struct pci_dev *pdev) erdma_ceqs_uninit(dev); erdma_hw_reset(dev); + erdma_comm_irq_uninit(dev); erdma_cmdq_destroy(dev); erdma_eq_destroy(dev, &dev->aeq); - erdma_comm_irq_uninit(dev); pci_free_irq_vectors(dev->pdev); erdma_device_uninit(dev); base-commit: 97d73c8251226cf27cc6656b4c542869bb8c69fa -- 2.43.0