From: Andrew Morton <akpm@linux-foundation.org>
To: James Kim <james010kim@gmail.com>
Cc: linux-kernel@vger.kernel.org, mporter@kernel.crashing.org,
alex.bou9@gmail.com, dan.carpenter@linaro.org,
stable@vger.kernel.org, gregkh@linuxfoundation.org
Subject: Re: [PATCH v2] rapidio: mport_cdev: fix use-after-free in dma_req_free()
Date: Wed, 22 Jul 2026 17:18:14 -0700 [thread overview]
Message-ID: <20260722171814.8faf85a64f3bb5e91968fb17@linux-foundation.org> (raw)
In-Reply-To: <20260615070530.371640-1-james010kim@gmail.com>
On Mon, 15 Jun 2026 16:05:30 +0900 James Kim <james010kim@gmail.com> wrote:
> dma_req_free() drops the mapping reference under buf_mutex and then
> dereferences req->map again to unlock the mutex.
>
> If kref_put() drops the last reference, mport_release_mapping() frees
> the mapping, and the subsequent mutex_unlock() dereferences a freed
> object. This is a use-after-free.
>
> Fix this by caching map and md before kref_put() and using the cached
> md for mutex unlocking.
>
> Fixes: 4b0986a36 ("rapidio: add mport character device support")
12 characters of hash, please.
> Cc: stable@vger.kernel.org
Is this observable from userspace in any way?
> --- a/drivers/rapidio/devices/rio_mport_cdev.c
> +++ b/drivers/rapidio/devices/rio_mport_cdev.c
> @@ -564,9 +564,14 @@ static void dma_req_free(struct kref *ref)
> }
>
> if (req->map) {
> - mutex_lock(&req->map->md->buf_mutex);
> - kref_put(&req->map->ref, mport_release_mapping);
> - mutex_unlock(&req->map->md->buf_mutex);
> + struct rio_mport_mapping *map = req->map;
> + struct mport_dev *md = map->md;
> +
> + mutex_lock(&md->buf_mutex);
> + kref_put(&map->ref, mport_release_mapping);
> + mutex_unlock(&md->buf_mutex);
> +
> + req->map = NULL;
> }
lgtm, although rio object lifetimes aren't exactly my strength ;)
It might be safer/saner to do the `req->map = NULL' inside the mutex?
And....
You made Sashiko AI review look at this code. The results aren't pretty:
https://sashiko.dev/#/patchset/20260615070530.371640-1-james010kim@gmail.com
It claims to have found fourteen pre-existing flaws in there :(
next prev parent reply other threads:[~2026-07-23 0:18 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-15 7:05 James Kim
2026-07-22 0:36 ` James Kim
2026-07-23 8:17 ` Dan Carpenter
2026-07-23 0:18 ` Andrew Morton [this message]
2026-07-23 0:21 ` Andrew Morton
2026-07-23 0:48 ` James Kim
2026-07-27 8:09 ` Dan Carpenter
2026-07-23 23:52 ` [PATCH v3] " James Kim
2026-07-27 7:55 ` James Kim
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=20260722171814.8faf85a64f3bb5e91968fb17@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=alex.bou9@gmail.com \
--cc=dan.carpenter@linaro.org \
--cc=gregkh@linuxfoundation.org \
--cc=james010kim@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mporter@kernel.crashing.org \
--cc=stable@vger.kernel.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
all inboxes | Powered by JetHome®