Message ID | 20230313163120.3741811-1-zyytlz.wz@163.com (mailing list archive) |
---|---|
State | Accepted |
Delegated to: | Hans Verkuil |
Headers |
Received: from vger.kernel.org ([23.128.96.18]) by www.linuxtv.org with esmtp (Exim 4.92) (envelope-from <linux-media-owner@vger.kernel.org>) id 1pbl7h-00G0rN-Bz; Mon, 13 Mar 2023 16:34:10 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231408AbjCMQeH (ORCPT <rfc822;mkrufky@linuxtv.org> + 1 other); Mon, 13 Mar 2023 12:34:07 -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 <rfc822;linux-media@vger.kernel.org>); 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 <zyytlz.wz@163.com> 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 <zyytlz.wz@163.com> 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 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-media.vger.kernel.org> X-Mailing-List: linux-media@vger.kernel.org X-LSpam-Score: -2.5 (--) X-LSpam-Report: No, score=-2.5 required=5.0 tests=BAYES_00=-1.9,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,FREEMAIL_FORGED_FROMDOMAIN=0.001,FREEMAIL_FROM=0.001,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1 autolearn=ham autolearn_force=no |
Series |
[v2] media: cedrus: fix use after free bug in cedrus_remove due to race condition
|
|
Commit Message
Zheng Wang
March 13, 2023, 4:31 p.m. UTC
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 <zyytlz.wz@163.com>
---
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(+)
Comments
Dne ponedeljek, 13. marec 2023 ob 17:31:20 CET je Zheng Wang napisal(a): > 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 <zyytlz.wz@163.com> > --- > 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(+) > Acked-by: Jernej Skrabec <jernej.skrabec@gmail.com> Best regards, Jernej > 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);
Jernej Škrabec <jernej.skrabec@gmail.com> 于2023年3月15日周三 03:53写道: > > Dne ponedeljek, 13. marec 2023 ob 17:31:20 CET je Zheng Wang napisal(a): > > 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 <zyytlz.wz@163.com> > > --- > > 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(+) > > > > Acked-by: Jernej Skrabec <jernej.skrabec@gmail.com> > Thanks for your review. Best regards, Zheng > Best regards, > Jernej > > > 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); > > > >
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);