From patchwork Tue Mar 7 17:39:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zheng Wang X-Patchwork-Id: 660302 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 AB79FC678DB for ; Tue, 7 Mar 2023 17:45:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232043AbjCGRpl (ORCPT ); Tue, 7 Mar 2023 12:45:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232271AbjCGRpF (ORCPT ); Tue, 7 Mar 2023 12:45:05 -0500 Received: from m12.mail.163.com (m12.mail.163.com [220.181.12.214]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id AC265974AB; Tue, 7 Mar 2023 09:40:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=4L/vO yAA0sQq/vaIuPvACeaXWgWX0UFxKoUhXSbG0m0=; b=UzIwnVEV5JDj95YxrljJP px9MzX/E86TxlvUDOBNHJoO4maH5IvOrEBbtrywVYxF/b3vpNhesxv2YSyImi0lm P6QndSMRkTzSHwD/8k9WkqVhMQIjVfLgeIA2vUc05imGf4zoe2KW1f5413exLwNQ IkUoC41VPZ5Dp1aBTkwtWw= Received: from leanderwang-LC2.localdomain (unknown [111.206.145.21]) by zwqz-smtp-mta-g2-1 (Coremail) with SMTP id _____wCHjdG2dgdkm7_iCQ--.13674S2; Wed, 08 Mar 2023 01:39:02 +0800 (CST) From: Zheng Wang To: ezequiel@vanguardiasur.com.ar Cc: mchehab@kernel.org, gregkh@linuxfoundation.org, linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org, hackerzheng666@gmail.com, 1395428693sheep@gmail.com, alex000young@gmail.com, Zheng Wang Subject: [PATCH] media: rkvdec: fix use after free bug in rkvdec_remove Date: Wed, 8 Mar 2023 01:39:00 +0800 Message-Id: <20230307173900.1299387-1-zyytlz.wz@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CM-TRANSID: _____wCHjdG2dgdkm7_iCQ--.13674S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7GF4xAFy8uw17XryxtryxXwb_yoW8JF1fpr W7ta4UCa15GF4jgF47tw4xZ3WrG345KF95Kr9rXa43ZryfJrnrJ3sYyF1UAFZ7trZ3Z3y3 CFyYgw1rXw4DtrDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zi-eOJUUUUU= X-Originating-IP: [111.206.145.21] X-CM-SenderInfo: h2113zf2oz6qqrwthudrp/1tbiXQArU1WBo1XSVAAAsB Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org In rkvdec_probe, rkvdec->watchdog_work is bound with rkvdec_watchdog_func. Then rkvdec_vp9_run may be called to start the work. If we remove the module which will call rkvdec_remove to make cleanup, there may be a unfinished work. The possible sequence is as follows, which will cause a typical UAF bug. Fix it by canceling the work before cleanup in rkvdec_remove. CPU0 CPU1 |rkvdec_watchdog_func rkvdec_remove | rkvdec_v4l2_cleanup| v4l2_m2m_release | kfree(m2m_dev); | | | v4l2_m2m_get_curr_priv | m2m_dev->curr_ctx //use Signed-off-by: Zheng Wang --- drivers/staging/media/rkvdec/rkvdec.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/staging/media/rkvdec/rkvdec.c b/drivers/staging/media/rkvdec/rkvdec.c index 7bab7586918c..6b14655a8e2c 100644 --- a/drivers/staging/media/rkvdec/rkvdec.c +++ b/drivers/staging/media/rkvdec/rkvdec.c @@ -1066,6 +1066,7 @@ static int rkvdec_remove(struct platform_device *pdev) { struct rkvdec_dev *rkvdec = platform_get_drvdata(pdev); + cancel_delayed_work(&rkvdec->watchdog_work); rkvdec_v4l2_cleanup(rkvdec); pm_runtime_disable(&pdev->dev); pm_runtime_dont_use_autosuspend(&pdev->dev);