Netdev List
 help / color / mirror / Atom feed
From: Oliver Hartkopp <socketcan@hartkopp.net>
To: Jianqiang kang <jianqkang@sina.cn>,
	gregkh@linuxfoundation.org, stable@vger.kernel.org, sam@bynar.io
Cc: patches@lists.linux.dev, linux-kernel@vger.kernel.org,
	mkl@pengutronix.de, davem@davemloft.net, edumazet@google.com,
	kuba@kernel.org, pabeni@redhat.com, linux-can@vger.kernel.org,
	netdev@vger.kernel.org
Subject: Re: [PATCH 6.1.y] can: raw: fix ro->uniq use-after-free in raw_rcv()
Date: Wed, 13 May 2026 08:35:09 +0200	[thread overview]
Message-ID: <cddb23c3-8c07-461b-b6c2-3d9a62d5179b@hartkopp.net> (raw)
In-Reply-To: <20260513061828.3671533-1-jianqkang@sina.cn>



On 13.05.26 08:18, Jianqiang kang wrote:
> From: Samuel Page <sam@bynar.io>
> 
> [ Upstream commit a535a9217ca3f2fccedaafb2fddb4c48f27d36dc ]
> 
> raw_release() unregisters raw CAN receive filters via can_rx_unregister(),
> but receiver deletion is deferred with call_rcu(). This leaves a window
> where raw_rcv() may still be running in an RCU read-side critical section
> after raw_release() frees ro->uniq, leading to a use-after-free of the
> percpu uniq storage.
> 
> Move free_percpu(ro->uniq) out of raw_release() and into a raw-specific
> socket destructor. can_rx_unregister() takes an extra reference to the
> socket and only drops it from the RCU callback, so freeing uniq from
> sk_destruct ensures the percpu area is not released until the relevant
> callbacks have drained.
> 
> Fixes: 514ac99c64b2 ("can: fix multiple delivery of a single CAN frame for overlapping CAN filters")
> Cc: stable@vger.kernel.org # v4.1+

This fix is not only missing in 6.1.y but also for older stable kernels. 
It has only be applied to 6.18.y so far.

Best regards,
Oliver

> Assisted-by: Bynario AI
> Signed-off-by: Samuel Page <sam@bynar.io>
> Link: https://patch.msgid.link/26ec626d-cae7-4418-9782-7198864d070c@bynar.io
> Acked-by: Oliver Hartkopp <socketcan@hartkopp.net>
> [mkl: applied manually]
> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
> Signed-off-by: Jianqiang kang <jianqkang@sina.cn>
> ---
>   net/can/raw.c | 11 ++++++++++-
>   1 file changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/net/can/raw.c b/net/can/raw.c
> index 488320738e31..bcd6061f43d8 100644
> --- a/net/can/raw.c
> +++ b/net/can/raw.c
> @@ -336,6 +336,14 @@ static int raw_notifier(struct notifier_block *nb, unsigned long msg,
>   	return NOTIFY_DONE;
>   }
>   
> +static void raw_sock_destruct(struct sock *sk)
> +{
> +	struct raw_sock *ro = raw_sk(sk);
> +
> +	free_percpu(ro->uniq);
> +	can_sock_destruct(sk);
> +}
> +
>   static int raw_init(struct sock *sk)
>   {
>   	struct raw_sock *ro = raw_sk(sk);
> @@ -362,6 +370,8 @@ static int raw_init(struct sock *sk)
>   	if (unlikely(!ro->uniq))
>   		return -ENOMEM;
>   
> +	sk->sk_destruct = raw_sock_destruct;
> +
>   	/* set notifier */
>   	spin_lock(&raw_notifier_lock);
>   	list_add_tail(&ro->notifier, &raw_notifier_list);
> @@ -409,7 +419,6 @@ static int raw_release(struct socket *sock)
>   	ro->bound = 0;
>   	ro->dev = NULL;
>   	ro->count = 0;
> -	free_percpu(ro->uniq);
>   
>   	sock_orphan(sk);
>   	sock->sk = NULL;


      reply	other threads:[~2026-05-13  6:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-13  6:18 [PATCH 6.1.y] can: raw: fix ro->uniq use-after-free in raw_rcv() Jianqiang kang
2026-05-13  6:35 ` Oliver Hartkopp [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=cddb23c3-8c07-461b-b6c2-3d9a62d5179b@hartkopp.net \
    --to=socketcan@hartkopp.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jianqkang@sina.cn \
    --cc=kuba@kernel.org \
    --cc=linux-can@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mkl@pengutronix.de \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=patches@lists.linux.dev \
    --cc=sam@bynar.io \
    --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