From patchwork Wed Sep 11 15:01:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kaixin Wang X-Patchwork-Id: 13806230 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1F502FA3758 for ; Tue, 17 Sep 2024 14:43:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=stAgH+qseuJgsSMwbudSc4eHZtACKZ89CA10/VvAg8w=; b=QIo3gAhUWVYg50 ZAAQ/klE9AgNCuLOO0gvH+8OZo8CN6t80NL7geTriAXDeBzyh0ciUidpiWRRnx7R8xWRHGtMm3s3S pLQ4PVcCFoc25pisSjA4zFLw67nb5El840RUB3AQ12bfQTUolEXjeXE2j5uLlJFefk4Des2nNOZ3u D1V2U/yyvmXmhn/4VLBwFZXt95DUTO1TFFtXukt+pTj2vsbwMutvHVycwjkSe/vC01PToZvYY3cmQ YBRXXQ9kCet25hCZQPBRMJBR3wKUtKtbjgnjj0Dtxh4+0rGfsd6cG8/qX2z9IMtTbg03BwkGYQGs3 xnf5C7+YlR6lWHbIMDLg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1sqZQc-00000006KlF-26cF; Tue, 17 Sep 2024 14:43:42 +0000 Received: from smtpbguseast1.qq.com ([54.204.34.129]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1soOr2-0000000A3aa-1c5m for linux-i3c@lists.infradead.org; Wed, 11 Sep 2024 15:02:02 +0000 X-QQ-mid: bizesmtpsz11t1726066890tsr0e7 X-QQ-Originating-IP: Y6v+T0f7c12A5OabWBayGIbWcZSTO4NMcfS5l/rjM4I= Received: from fastnlp.. ( [202.120.234.41]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 11 Sep 2024 23:01:15 +0800 (CST) X-QQ-SSF: 0000000000000000000000000000000 X-QQ-GoodBg: 0 X-BIZMAIL-ID: 13582565552656211047 From: Kaixin Wang To: miquel.raynal@bootlin.com Cc: 21210240012@m.fudan.edu.cn, 21302010073@m.fudan.edu.cn, conor.culhane@silvaco.com, alexandre.belloni@bootlin.com, linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org, frank.li@nxp.com, Kaixin Wang Subject: [PATCH] i3c: master: svc: Fix use after free vulnerability in svc_i3c_master Driver Due to Race Condition Date: Wed, 11 Sep 2024 23:01:35 +0800 Message-Id: <20240911150135.839946-1-kxwang23@m.fudan.edu.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtpsz:m.fudan.edu.cn:qybglogicsvrsz:qybglogicsvrsz4a-0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240911_080201_128051_50E86C34 X-CRM114-Status: UNSURE ( 9.70 ) X-CRM114-Notice: Please train this message. X-Mailman-Approved-At: Tue, 17 Sep 2024 07:43:41 -0700 X-BeenThere: linux-i3c@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-i3c" Errors-To: linux-i3c-bounces+linux-i3c=archiver.kernel.org@lists.infradead.org In the svc_i3c_master_probe function, &master->hj_work is bound with svc_i3c_master_hj_work, &master->ibi_work is bound with svc_i3c_master_ibi_work. And svc_i3c_master_ibi_work  can start the hj_work, svc_i3c_master_irq_handler can start the ibi_work. If we remove the module which will call svc_i3c_master_remove to make cleanup, it will free master->base through i3c_master_unregister while the work mentioned above will be used. The sequence of operations that may lead to a UAF bug is as follows: CPU0 CPU1 | svc_i3c_master_hj_work svc_i3c_master_remove | i3c_master_unregister(&master->base)| device_unregister(&master->dev) | device_release | //free master->base | | i3c_master_do_daa(&master->base) | //use master->base Fix it by ensuring that the work is canceled before proceeding with the cleanup in svc_i3c_master_remove. Signed-off-by: Kaixin Wang --- drivers/i3c/master/svc-i3c-master.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/i3c/master/svc-i3c-master.c b/drivers/i3c/master/svc-i3c-master.c index 0a68fd1b81d4..e084ba648b4a 100644 --- a/drivers/i3c/master/svc-i3c-master.c +++ b/drivers/i3c/master/svc-i3c-master.c @@ -1775,6 +1775,7 @@ static void svc_i3c_master_remove(struct platform_device *pdev) { struct svc_i3c_master *master = platform_get_drvdata(pdev); + cancel_work_sync(&master->hj_work); i3c_master_unregister(&master->base); pm_runtime_dont_use_autosuspend(&pdev->dev);