From: Oliver Hartkopp <socketcan@hartkopp.net>
To: linux-can@vger.kernel.org
Cc: Oliver Hartkopp <socketcan@hartkopp.net>,
Norbert Szetei <norbert@doyensec.com>,
stable@vger.kernel.org
Subject: [PATCH] can: notifiers: remove CAN filters independent from namespace
Date: Mon, 31 Aug 2026 20:56:53 +0200 [thread overview]
Message-ID: <20260831185654.16701-1-socketcan@hartkopp.net> (raw)
Remove the namespace equality check in the netdev notifiers for BCM,
ISOTP, and RAW sockets.
When the devices namespace is changed the socket namespace and the device
namespace might differ. The net_eq(dev_net(dev), sock_net(sk)) check
therefore skipped the removal of the CAN filters from the (ns changed)
CAN device.
Since the `struct net_device` pointer is globally unique, the notifier
should always process the unregister event and remove the CAN filters if
it matches the socket's bound device, regardless of the device's current
network namespace.
Change all can_rx_unregister() calling sites to use dev_net(dev) instead
of sock_net(sk) to retrieve the namespace (only missing in isotp.c).
Fixes: e057dd3fc20f ("can: add ISO 15765-2:2016 transport protocol")
Reported-by: Norbert Szetei <norbert@doyensec.com>
Link: https://lore.kernel.org/linux-can/CEA6A38A-2646-4ADA-95B4-CBAE2F301A8E@doyensec.com/
Cc: stable@vger.kernel.org
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
---
net/can/bcm.c | 3 ---
net/can/isotp.c | 7 ++-----
net/can/raw.c | 3 ---
3 files changed, 2 insertions(+), 11 deletions(-)
diff --git a/net/can/bcm.c b/net/can/bcm.c
index 3d637a1e0ac1..aaa5163c46cc 100644
--- a/net/can/bcm.c
+++ b/net/can/bcm.c
@@ -1792,13 +1792,10 @@ static void bcm_notify(struct bcm_sock *bo, unsigned long msg,
{
struct sock *sk = &bo->sk;
struct bcm_op *op;
int notify_enodev = 0;
- if (!net_eq(dev_net(dev), sock_net(sk)))
- return;
-
switch (msg) {
case NETDEV_UNREGISTER:
lock_sock(sk);
diff --git a/net/can/isotp.c b/net/can/isotp.c
index 155530aedce2..0835a4758a72 100644
--- a/net/can/isotp.c
+++ b/net/can/isotp.c
@@ -1490,15 +1490,15 @@ static int isotp_release(struct socket *sock)
/* remove current filters & unregister
* tracked reference so->dev is taken at bind() time with rtnl_lock
*/
if (so->bound && so->dev) {
if (isotp_register_rxid(so))
- can_rx_unregister(net, so->dev, so->rxid,
+ can_rx_unregister(dev_net(so->dev), so->dev, so->rxid,
SINGLE_MASK(so->rxid),
isotp_rcv, sk);
- can_rx_unregister(net, so->dev, so->txid,
+ can_rx_unregister(dev_net(so->dev), so->dev, so->txid,
SINGLE_MASK(so->txid),
isotp_rcv_echo, sk);
netdev_put(so->dev, &so->dev_tracker);
}
@@ -1846,13 +1846,10 @@ static int isotp_getsockopt(struct socket *sock, int level, int optname,
static void isotp_notify(struct isotp_sock *so, unsigned long msg,
struct net_device *dev)
{
struct sock *sk = &so->sk;
- if (!net_eq(dev_net(dev), sock_net(sk)))
- return;
-
if (so->dev != dev)
return;
switch (msg) {
case NETDEV_UNREGISTER:
diff --git a/net/can/raw.c b/net/can/raw.c
index 82d9c0499c95..c5596fc9aac5 100644
--- a/net/can/raw.c
+++ b/net/can/raw.c
@@ -300,13 +300,10 @@ static int raw_enable_allfilters(struct net *net, struct net_device *dev,
static void raw_notify(struct raw_sock *ro, unsigned long msg,
struct net_device *dev)
{
struct sock *sk = &ro->sk;
- if (!net_eq(dev_net(dev), sock_net(sk)))
- return;
-
if (ro->dev != dev)
return;
switch (msg) {
case NETDEV_UNREGISTER:
--
2.53.0
next reply other threads:[~2026-08-31 18:57 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-31 18:56 Oliver Hartkopp [this message]
2026-08-31 21:24 ` [PATCH] can: notifiers: remove CAN filters independent from namespace sashiko-bot
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=20260831185654.16701-1-socketcan@hartkopp.net \
--to=socketcan@hartkopp.net \
--cc=linux-can@vger.kernel.org \
--cc=norbert@doyensec.com \
--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