From: sashiko-bot@kernel.org
To: "Oliver Hartkopp" <socketcan@hartkopp.net>
Cc: linux-can@vger.kernel.org, "Vincent Mailhol" <mailhol@kernel.org>,
"Oliver Hartkopp" <socketcan@hartkopp.net>,
"Marc Kleine-Budde" <mkl@pengutronix.de>,
"Oleksij Rempel" <o.rempel@pengutronix.de>
Subject: Re: [PATCH] can: notifiers: remove CAN filters independent from namespace
Date: Mon, 31 Aug 2026 21:24:32 +0000 [thread overview]
Message-ID: <20260831212432.6C2B51F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260831185654.16701-1-socketcan@hartkopp.net>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Removing the namespace equality check in `bcm_notify` exposes BCM sockets to cross-namespace `ifindex` collisions. Unprivileged users can exploit this to disrupt BCM sockets in the host or other namespaces by spoofing `NETDEV_UNREGISTER` and `NETDEV_DOWN` events.
--
commit e5738773c45b8a30848fd2bb47977b2587f26903
Author: Oliver Hartkopp <socketcan@hartkopp.net>
can: notifiers: remove CAN filters independent from namespace
This commit removes the namespace equality check in the netdev notifiers
for BCM, ISOTP, and RAW CAN sockets. The goal is to ensure CAN filters
are correctly removed when a device is unregistered, even if the socket
and device network namespaces differ due to a namespace change. It also
updates the can_rx_unregister() calling sites to retrieve the namespace
from the device instead of the socket.
Link: https://lore.kernel.org/linux-can/CEA6A38A-2646-4ADA-95B4-CBAE2F301A8E@doyensec.com/
> diff --git a/net/can/bcm.c b/net/can/bcm.c
> index 3d637a1e0ac1a..aaa5163c46cc2 100644
> --- a/net/can/bcm.c
> +++ b/net/can/bcm.c
> @@ -1794,9 +1794,6 @@ static void bcm_notify(struct bcm_sock *bo, unsigned long msg,
> struct bcm_op *op;
> int notify_enodev = 0;
>
> - if (!net_eq(dev_net(dev), sock_net(sk)))
> - return;
> -
[Severity: High]
With this namespace equality check removed, are BCM sockets now exposed to
cross-namespace ifindex collisions?
Because ifindex is only unique per namespace, an unprivileged user could create
a virtual CAN device in a new network namespace with an ifindex matching a
target BCM socket in another namespace.
When this spoofed device is unregistered or brought down, the events proceed
into the rest of bcm_notify() which compares the integer ifindex instead of
a device pointer:
net/can/bcm.c:bcm_notify() {
...
case NETDEV_UNREGISTER:
...
/* ANYDEV ops */
if (!op->ifindex) {
spin_lock_bh(&op->bcm_rx_update_lock);
if (op->if_detected == dev->ifindex)
op->if_detected = 0;
...
/* tx_ops */
list_for_each_entry(op, &bo->tx_ops, list)
if (op->ifindex == dev->ifindex)
hrtimer_cancel(&op->timer);
...
/* bound device */
if (bo->bound && bo->ifindex == dev->ifindex) {
...
WRITE_ONCE(bo->bound, 0);
bo->ifindex = 0;
notify_enodev = 1;
}
...
case NETDEV_DOWN:
if (bo->bound && bo->ifindex == dev->ifindex) {
sk->sk_err = ENETDOWN;
...
}
Could this allow an attacker to falsely clear ANYDEV claims, cancel active
transmission timers, forcibly unbind the socket (ENODEV), or inject ENETDOWN
errors into victim BCM sockets across namespaces?
> switch (msg) {
>
> case NETDEV_UNREGISTER:
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260831185654.16701-1-socketcan@hartkopp.net?part=1
prev parent reply other threads:[~2026-08-31 21:24 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-31 18:56 [PATCH] can: notifiers: remove CAN filters independent from namespace Oliver Hartkopp
2026-08-31 21:24 ` sashiko-bot [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=20260831212432.6C2B51F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-can@vger.kernel.org \
--cc=mailhol@kernel.org \
--cc=mkl@pengutronix.de \
--cc=o.rempel@pengutronix.de \
--cc=sashiko-reviews@lists.linux.dev \
--cc=socketcan@hartkopp.net \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.