Linux Remote Processor Subsystem development
 help / color / mirror / Atom feed
From: Mathieu Poirier <mathieu.poirier@linaro.org>
To: Yuho Choi <dbgh9129@gmail.com>
Cc: Bjorn Andersson <andersson@kernel.org>,
	linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] rpmsg: char: fix use-after-free on probe error path
Date: Thu, 4 Jun 2026 12:05:21 -0600	[thread overview]
Message-ID: <aiG-YQi2W6iEY3oq@p14s> (raw)
In-Reply-To: <20260601183247.1962010-1-dbgh9129@gmail.com>

On Mon, Jun 01, 2026 at 02:32:47PM -0400, Yuho Choi wrote:
> rpmsg_chrdev_probe() stores the newly allocated eptdev in the default
> endpoint's priv pointer before calling rpmsg_chrdev_eptdev_add(). If
> rpmsg_chrdev_eptdev_add() then fails, its error path frees eptdev while
> the default endpoint may still dispatch callbacks with the stale priv
> pointer.
> 
> Avoid publishing eptdev through the default endpoint until
> rpmsg_chrdev_eptdev_add() succeeds. Messages received before the priv
> pointer is published should be ignored by rpmsg_ept_cb(). Flow-control
> updates can hit rpmsg_ept_flow_cb() in the same window, so make both
> callbacks return success when priv is NULL.
> 
> Fixes: bc69d1066569 ("rpmsg: char: Introduce the "rpmsg-raw" channel")
> Signed-off-by: Yuho Choi <dbgh9129@gmail.com>
> ---
> Changes in v2:
> - Use a 12-character Fixes SHA.
> - Drop the unnecessary asm-generic/rwonce.h include.
> - Handle NULL priv in rpmsg_ept_flow_cb() as well.
>  drivers/rpmsg/rpmsg_char.c | 15 +++++++++++++--
>  1 file changed, 13 insertions(+), 2 deletions(-)
>

Applied.

Thanks,
Mathieu
 
> diff --git a/drivers/rpmsg/rpmsg_char.c b/drivers/rpmsg/rpmsg_char.c
> index ca9cf8858a5e..bff5aefee212 100644
> --- a/drivers/rpmsg/rpmsg_char.c
> +++ b/drivers/rpmsg/rpmsg_char.c
> @@ -104,6 +104,9 @@ static int rpmsg_ept_cb(struct rpmsg_device *rpdev, void *buf, int len,
>  	struct rpmsg_eptdev *eptdev = priv;
>  	struct sk_buff *skb;
>  
> +	if (!eptdev)
> +		return 0;
> +
>  	skb = alloc_skb(len, GFP_ATOMIC);
>  	if (!skb)
>  		return -ENOMEM;
> @@ -124,6 +127,9 @@ static int rpmsg_ept_flow_cb(struct rpmsg_device *rpdev, void *priv, bool enable
>  {
>  	struct rpmsg_eptdev *eptdev = priv;
>  
> +	if (!eptdev)
> +		return 0;
> +
>  	eptdev->remote_flow_restricted = enable;
>  	eptdev->remote_flow_updated = true;
>  
> @@ -490,6 +496,7 @@ static int rpmsg_chrdev_probe(struct rpmsg_device *rpdev)
>  	struct rpmsg_channel_info chinfo;
>  	struct rpmsg_eptdev *eptdev;
>  	struct device *dev = &rpdev->dev;
> +	int ret;
>  
>  	memcpy(chinfo.name, rpdev->id.name, RPMSG_NAME_SIZE);
>  	chinfo.src = rpdev->src;
> @@ -502,13 +509,17 @@ static int rpmsg_chrdev_probe(struct rpmsg_device *rpdev)
>  	/* Set the default_ept to the rpmsg device endpoint */
>  	eptdev->default_ept = rpdev->ept;
>  
> +	ret = rpmsg_chrdev_eptdev_add(eptdev, chinfo);
> +
> +	if (ret)
> +		return ret;
>  	/*
>  	 * The rpmsg_ept_cb uses *priv parameter to get its rpmsg_eptdev context.
> -	 * Storedit in default_ept *priv field.
> +	 * Stored it in default_ept *priv field.
>  	 */
>  	eptdev->default_ept->priv = eptdev;
>  
> -	return rpmsg_chrdev_eptdev_add(eptdev, chinfo);
> +	return 0;
>  }
>  
>  static void rpmsg_chrdev_remove(struct rpmsg_device *rpdev)
> -- 
> 2.43.0
> 

      reply	other threads:[~2026-06-04 18:05 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-01 18:32 [PATCH v2] rpmsg: char: fix use-after-free on probe error path Yuho Choi
2026-06-04 18:05 ` Mathieu Poirier [this message]

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=aiG-YQi2W6iEY3oq@p14s \
    --to=mathieu.poirier@linaro.org \
    --cc=andersson@kernel.org \
    --cc=dbgh9129@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-remoteproc@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