Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Ma Ke <make_ruc2021@163.com>
To: mripard@kernel.org, paul.kocialkowski@bootlin.com,
	mchehab@kernel.org, gregkh@linuxfoundation.org, wens@csie.org,
	jernej.skrabec@gmail.com, samuel@sholland.org
Cc: linux-media@vger.kernel.org, linux-staging@lists.linux.dev,
	linux-arm-kernel@lists.infradead.org,
	linux-sunxi@lists.linux.dev, Ma Ke <make_ruc2021@163.com>
Subject: [PATCH] media: cedrus: fix use after free bug in cedrus_remove due to race condition
Date: Fri, 15 Sep 2023 19:40:38 +0800	[thread overview]
Message-ID: <20230915114038.3407953-1-make_ruc2021@163.com> (raw)

In cedrus_probe, dev->watchdog_work is bound with cedrus_watchdog. Then
cedrus_device_run may be called to start the work.

If we close the file or remove the module which will call cedrus_release and
cedrus_remove to make cleanup, there may be an unfinished work. The possible
sequence is as follows, which will cause a typical UAF bug.

The same thing will happen in cedrus_release, and use ctx after freeing it.

Fix it by canceling the work before cleanup in cedrus_release.

Signed-off-by: Ma Ke <make_ruc2021@163.com>
---
 drivers/staging/media/sunxi/cedrus/cedrus.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/staging/media/sunxi/cedrus/cedrus.c b/drivers/staging/media/sunxi/cedrus/cedrus.c
index 8e248d4a0aec..0a2cb615d717 100644
--- a/drivers/staging/media/sunxi/cedrus/cedrus.c
+++ b/drivers/staging/media/sunxi/cedrus/cedrus.c
@@ -404,6 +404,8 @@ static int cedrus_release(struct file *file)
 	struct cedrus_ctx *ctx = container_of(file->private_data,
 					      struct cedrus_ctx, fh);
 
+	cancel_delayed_work_sync(&ctx->dev->watchdog_work);
+
 	mutex_lock(&dev->dev_mutex);
 
 	v4l2_fh_del(&ctx->fh);
-- 
2.37.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

             reply	other threads:[~2023-09-15 11:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-15 11:40 Ma Ke [this message]
2023-09-15 12:33 ` [PATCH] media: cedrus: fix use after free bug in cedrus_remove due to race condition Dan Carpenter
  -- strict thread matches above, loose matches on Subject: below --
2023-03-08  3:23 Zheng Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230915114038.3407953-1-make_ruc2021@163.com \
    --to=make_ruc2021@163.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jernej.skrabec@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=linux-sunxi@lists.linux.dev \
    --cc=mchehab@kernel.org \
    --cc=mripard@kernel.org \
    --cc=paul.kocialkowski@bootlin.com \
    --cc=samuel@sholland.org \
    --cc=wens@csie.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox