From: sashiko-bot@kernel.org
To: "Yao Yiqi" <yaoyiqi3@huawei.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH] misc: fastrpc: Fix double free in fastrpc_req_mmap() error path
Date: Wed, 30 Sep 2026 03:57:14 +0000 [thread overview]
Message-ID: <20260930035714.922821F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260930032022.2957082-1-yaoyiqi3@huawei.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Critical] misc: fastrpc: unconditional list_del in error path races with concurrent unmap
--
commit 03236356a22d5b8fc33413026fac2ff46d3f8883
Author: Yao Yiqi <yaoyiqi3@huawei.com>
misc: fastrpc: Fix double free in fastrpc_req_mmap() error path
This commit aims to fix a double free and use-after-free in the
fastrpc_req_mmap() error path. It modifies the error handling when
copy_to_user() fails to remove the buffer from the mmaps list before
unmapping, matching patterns introduced in prior patches.
Cc: stable@vger.kernel.org
> diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
> index af18ff1992eed..436e046ed1cc0 100644
> --- a/drivers/misc/fastrpc.c
> +++ b/drivers/misc/fastrpc.c
> @@ -2129,6 +2129,9 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp)
>
> if (copy_to_user((void __user *)argp, &req, sizeof(req))) {
> err = -EFAULT;
> + spin_lock(&fl->lock);
> + list_del(&buf->node);
> + spin_unlock(&fl->lock);
[Severity: Critical]
Does this unconditionally remove the buffer from the list even if a concurrent
thread has already removed it?
If copy_to_user() blocks or is delayed (for example, via userfaultfd), a
concurrent thread could call FASTRPC_IOCTL_MUNMAP, predicting or reading the
partially copied address. This thread can extract the buffer from the list and
free it while the first thread is still suspended:
drivers/misc/fastrpc.c:fastrpc_req_munmap() {
...
list_del(&iter->node);
buf = iter;
break;
...
}
If the suspended copy_to_user() then fails, the first thread will resume
and execute this newly added list_del(&buf->node). Because the concurrent
unmap already unlinked the buffer, its list pointers will have been set to
LIST_POISON1 and LIST_POISON2.
Could this trigger an immediate kernel oops due to a poisoned pointer
dereference?
> goto err_assign;
> }
>
> @@ -2138,7 +2141,11 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp)
> return 0;
>
> err_assign:
> - fastrpc_req_munmap_impl(fl, buf);
> + if (fastrpc_req_munmap_impl(fl, buf)) {
[Severity: Critical]
Following the race sequence described above, if the concurrent unmap thread
has already freed this buffer, does passing it to fastrpc_req_munmap_impl()
here lead to a use-after-free and a subsequent double free?
> + spin_lock(&fl->lock);
> + list_add_tail(&buf->node, &fl->mmaps);
> + spin_unlock(&fl->lock);
> + }
>
> return err;
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260930032022.2957082-1-yaoyiqi3@huawei.com?part=1
parent reply other threads:[~2026-09-30 3:57 UTC|newest]
Thread overview: expand[flat|nested] mbox.gz Atom feed
[parent not found: <20260930032022.2957082-1-yaoyiqi3@huawei.com>]
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=20260930035714.922821F000FF@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=yaoyiqi3@huawei.com \
/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