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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 166EFC61DA4 for ; Mon, 13 Mar 2023 16:34:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231422AbjCMQeJ (ORCPT ); Mon, 13 Mar 2023 12:34:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231279AbjCMQdu (ORCPT ); Mon, 13 Mar 2023 12:33:50 -0400 Received: from m12.mail.163.com (m12.mail.163.com [220.181.12.197]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7AB01C169; Mon, 13 Mar 2023 09:33:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=IacwA yjPTNhi/tmrdS6hhYpxHKnIxK7jZ03eSL+e44E=; b=SQGyceuW32BcU07IBhF1R ygBdWL1vj+hmYGv//ILgyM++7Z0b9ih5TQhVUr5vQaEPGa8MlPY1tInrA+dHfSNk WahBZnCPUa0/q4XczHmZq3p7xGMTzt9jkILpnQB1Gc56sQ5dqtORP1nLaYGmaxvF skU35mp3ealNe5Rw4OLDHo= Received: from leanderwang-LC2.localdomain (unknown [111.206.145.21]) by zwqz-smtp-mta-g5-3 (Coremail) with SMTP id _____wDnTI3aTw9kcosTAA--.14497S2; Tue, 14 Mar 2023 00:31:23 +0800 (CST) From: Zheng Wang To: mchehab@kernel.org Cc: hverkuil@xs4all.nl, wens@csie.org, jernej.skrabec@gmail.com, samuel@sholland.org, linux-media@vger.kernel.org, linux-staging@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, hackerzheng666@gmail.com, 1395428693sheep@gmail.com, alex000young@gmail.com, Zheng Wang Subject: [PATCH v2] media: cedrus: fix use after free bug in cedrus_remove due to race condition Date: Tue, 14 Mar 2023 00:31:20 +0800 Message-Id: <20230313163120.3741811-1-zyytlz.wz@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: _____wDnTI3aTw9kcosTAA--.14497S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7uw15uFyUCF1fAryDGrW3KFg_yoW8GF4rpa yYka45CayUtF4Yg3y7Ar18ZFy5W34I9w1Fg34xJw1xtas5Jr1Sqr1Fy3W7Gwn8Z39Yka1a vF15X34Iqan7AF7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zi-eOJUUUUU= X-Originating-IP: [111.206.145.21] X-CM-SenderInfo: h2113zf2oz6qqrwthudrp/1tbiQgMxU1aEEpIz3AAAse Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In cedrus_probe, dev->watchdog_work is bound with cedrus_watchdog function. In cedrus_device_run, it will started by schedule_delayed_work. If there is an unfinished work in cedrus_remove, there may be a race condition and trigger UAF bug. CPU0 CPU1 |cedrus_watchdog cedrus_remove | v4l2_m2m_release | kfree(m2m_dev) | | | v4l2_m2m_get_curr_priv | m2m_dev //use Fix it by canceling the worker in cedrus_remove. Fixes: 7c38a551bda1 ("media: cedrus: Add watchdog for job completion") Signed-off-by: Zheng Wang --- v2: - use cancel_delayed_work_sync instead and add Fixes label suggested by Hans Verkuil --- drivers/staging/media/sunxi/cedrus/cedrus.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/staging/media/sunxi/cedrus/cedrus.c b/drivers/staging/media/sunxi/cedrus/cedrus.c index a43d5ff66716..a50a4d0a8f71 100644 --- a/drivers/staging/media/sunxi/cedrus/cedrus.c +++ b/drivers/staging/media/sunxi/cedrus/cedrus.c @@ -547,6 +547,7 @@ static int cedrus_remove(struct platform_device *pdev) { struct cedrus_dev *dev = platform_get_drvdata(pdev); + cancel_delayed_work_sync(&dev->watchdog_work); if (media_devnode_is_registered(dev->mdev.devnode)) { media_device_unregister(&dev->mdev); v4l2_m2m_unregister_media_controller(dev->m2m_dev); -- 2.25.1