* [PATCH net 1/2] can: ucan: fix devres lifetime
[not found] <20260409165942.588421-1-mkl@pengutronix.de>
@ 2026-04-09 16:57 ` Marc Kleine-Budde
2026-04-12 16:40 ` patchwork-bot+netdevbpf
2026-04-09 16:57 ` [PATCH net 2/2] can: raw: fix ro->uniq use-after-free in raw_rcv() Marc Kleine-Budde
1 sibling, 1 reply; 3+ messages in thread
From: Marc Kleine-Budde @ 2026-04-09 16:57 UTC (permalink / raw)
To: netdev
Cc: davem, kuba, linux-can, kernel, Johan Hovold, stable,
Jakob Unterwurzacher, Marc Kleine-Budde
From: Johan Hovold <johan@kernel.org>
USB drivers bind to USB interfaces and any device managed resources
should have their lifetime tied to the interface rather than parent USB
device. This avoids issues like memory leaks when drivers are unbound
without their devices being physically disconnected (e.g. on probe
deferral or configuration changes).
Fix the control message buffer lifetime so that it is released on driver
unbind.
Fixes: 9f2d3eae88d2 ("can: ucan: add driver for Theobroma Systems UCAN devices")
Cc: stable@vger.kernel.org # 4.19
Cc: Jakob Unterwurzacher <jakob.unterwurzacher@theobroma-systems.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
Link: https://patch.msgid.link/20260327104520.1310158-1-johan@kernel.org
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/usb/ucan.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/net/can/usb/ucan.c b/drivers/net/can/usb/ucan.c
index 0ea0ac75e42f..ee3c1abbd063 100644
--- a/drivers/net/can/usb/ucan.c
+++ b/drivers/net/can/usb/ucan.c
@@ -1397,7 +1397,7 @@ static int ucan_probe(struct usb_interface *intf,
*/
/* Prepare Memory for control transfers */
- ctl_msg_buffer = devm_kzalloc(&udev->dev,
+ ctl_msg_buffer = devm_kzalloc(&intf->dev,
sizeof(union ucan_ctl_payload),
GFP_KERNEL);
if (!ctl_msg_buffer) {
base-commit: ebe560ea5f54134279356703e73b7f867c89db13
--
2.53.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH net 2/2] can: raw: fix ro->uniq use-after-free in raw_rcv()
[not found] <20260409165942.588421-1-mkl@pengutronix.de>
2026-04-09 16:57 ` [PATCH net 1/2] can: ucan: fix devres lifetime Marc Kleine-Budde
@ 2026-04-09 16:57 ` Marc Kleine-Budde
1 sibling, 0 replies; 3+ messages in thread
From: Marc Kleine-Budde @ 2026-04-09 16:57 UTC (permalink / raw)
To: netdev
Cc: davem, kuba, linux-can, kernel, Samuel Page, stable,
Oliver Hartkopp, Marc Kleine-Budde
From: Samuel Page <sam@bynar.io>
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+
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>
---
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 eee244ffc31e..58a96e933deb 100644
--- a/net/can/raw.c
+++ b/net/can/raw.c
@@ -361,6 +361,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);
@@ -387,6 +395,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);
@@ -436,7 +446,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;
--
2.53.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net 1/2] can: ucan: fix devres lifetime
2026-04-09 16:57 ` [PATCH net 1/2] can: ucan: fix devres lifetime Marc Kleine-Budde
@ 2026-04-12 16:40 ` patchwork-bot+netdevbpf
0 siblings, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-04-12 16:40 UTC (permalink / raw)
To: Marc Kleine-Budde
Cc: netdev, davem, kuba, linux-can, kernel, johan, stable,
jakob.unterwurzacher
Hello:
This series was applied to netdev/net.git (main)
by Marc Kleine-Budde <mkl@pengutronix.de>:
On Thu, 9 Apr 2026 18:57:07 +0200 you wrote:
> From: Johan Hovold <johan@kernel.org>
>
> USB drivers bind to USB interfaces and any device managed resources
> should have their lifetime tied to the interface rather than parent USB
> device. This avoids issues like memory leaks when drivers are unbound
> without their devices being physically disconnected (e.g. on probe
> deferral or configuration changes).
>
> [...]
Here is the summary with links:
- [net,1/2] can: ucan: fix devres lifetime
https://git.kernel.org/netdev/net/c/fed4626501c8
- [net,2/2] can: raw: fix ro->uniq use-after-free in raw_rcv()
https://git.kernel.org/netdev/net/c/a535a9217ca3
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-04-12 16:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20260409165942.588421-1-mkl@pengutronix.de>
2026-04-09 16:57 ` [PATCH net 1/2] can: ucan: fix devres lifetime Marc Kleine-Budde
2026-04-12 16:40 ` patchwork-bot+netdevbpf
2026-04-09 16:57 ` [PATCH net 2/2] can: raw: fix ro->uniq use-after-free in raw_rcv() Marc Kleine-Budde
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox