From: Mathieu Poirier <mathieu.poirier@linaro.org>
To: Dawei Li <dawei.li@linux.dev>
Cc: andersson@kernel.org, linux-remoteproc@vger.kernel.org,
linux-kernel@vger.kernel.org, set_pte_at@outlook.com,
Dan Carpenter <dan.carpenter@linaro.org>
Subject: Re: [PATCH v3 2/3] rpmsg: char: Fix UAF and memory leak in rpmsg_anonymous_eptdev_create()
Date: Fri, 14 Nov 2025 12:01:44 -0700 [thread overview]
Message-ID: <aRd8mDzQWXtEFnmt@p14s> (raw)
In-Reply-To: <20251113153909.3789-3-dawei.li@linux.dev>
On Thu, Nov 13, 2025 at 11:39:08PM +0800, Dawei Li wrote:
> Potential UAF and memory leak exsit in exception handling paths for
> rpmsg_anonymous_eptdev_create(), fix them.
>
> - If rpmsg_add_eptdev() failes, eptdev is freed in it.
> Subsequent call of dev_err(&eptdev->device) triggers a UAF.
> - If __rpmsg_eptdev_open() fails, eptdev is supposed to be freed by
> put_device().
>
> Fixes: 2410558f5f11 ("rpmsg: char: Implement eptdev based on anonymous inode")
> Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
> Closes: https://lore.kernel.org/all/aPi6gPZE2_ztOjIW@stanley.mountain/
> Signed-off-by: Dawei Li <dawei.li@linux.dev>
> ---
> drivers/rpmsg/rpmsg_char.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/rpmsg/rpmsg_char.c b/drivers/rpmsg/rpmsg_char.c
> index 1b8297b373f0..0919ad0a19df 100644
> --- a/drivers/rpmsg/rpmsg_char.c
> +++ b/drivers/rpmsg/rpmsg_char.c
> @@ -494,6 +494,7 @@ static int rpmsg_eptdev_add(struct rpmsg_eptdev *eptdev,
> if (cdev)
> ida_free(&rpmsg_minor_ida, MINOR(dev->devt));
> free_eptdev:
> + dev_err(&eptdev->dev, "failed to add %s\n", eptdev->chinfo.name);
> kfree(eptdev);
>
> return ret;
> @@ -544,7 +545,6 @@ int rpmsg_anonymous_eptdev_create(struct rpmsg_device *rpdev, struct device *par
>
> ret = rpmsg_eptdev_add(eptdev, chinfo, false);
> if (ret) {
> - dev_err(&eptdev->dev, "failed to add %s\n", eptdev->chinfo.name);
This doesn't neet to be done if kfree(eptdev) is moved out of
rpmsg_eptdev_add().
> return ret;
> }
>
> @@ -560,6 +560,8 @@ int rpmsg_anonymous_eptdev_create(struct rpmsg_device *rpdev, struct device *par
>
> if (!ret)
> *pfd = fd;
> + else
> + put_device(&eptdev->dev);
This goes in the previous patch.
>
> return ret;
> }
> --
> 2.25.1
>
next prev parent reply other threads:[~2025-11-14 19:01 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-13 15:39 [PATCH v3 0/3] Fix and rework of rpmsg_eptdev_add() Dawei Li
2025-11-13 15:39 ` [PATCH v3 1/3] rpmsg: char: Remove put_device() in rpmsg_eptdev_add() Dawei Li
2025-11-14 9:53 ` Zhongqiu Han
2025-11-14 13:40 ` Zhongqiu Han
2025-11-14 14:23 ` Dawei Li
2025-11-13 15:39 ` [PATCH v3 2/3] rpmsg: char: Fix UAF and memory leak in rpmsg_anonymous_eptdev_create() Dawei Li
2025-11-14 19:01 ` Mathieu Poirier [this message]
2025-11-13 15:39 ` [PATCH v3 3/3] rpmsg: char: Rework exception handling of rpmsg_eptdev_add() Dawei Li
2025-11-14 9:53 ` Zhongqiu Han
2025-11-14 19:04 ` Mathieu Poirier
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=aRd8mDzQWXtEFnmt@p14s \
--to=mathieu.poirier@linaro.org \
--cc=andersson@kernel.org \
--cc=dan.carpenter@linaro.org \
--cc=dawei.li@linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-remoteproc@vger.kernel.org \
--cc=set_pte_at@outlook.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