Linux CAN drivers development
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: socketcan@hartkopp.net
Cc: linux-can@vger.kernel.org, mkl@pengutronix.de,
	o.rempel@pengutronix.de, mailhol@kernel.org, zhuling0805@qq.com,
	kuba@kernel.org
Subject: Re: [PATCH v7 5/8] can: bcm: use a private mutex instead of lock_sock()
Date: Sun, 22 Nov 2026 02:04:08 +0000	[thread overview]
Message-ID: <179531304802.3131.12745921065969332467@kernel.org> (raw)
In-Reply-To: <20261120-can-bcmlock-memcg-v7-5-f6b84f5257b1@hartkopp.net>

Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The stable dependency note "Cc: stable@vger.kernel.org # depends
  on \"can: bcm: copy the CAN frames outside of lock_sock()\"" is…

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but CAN_J1939 has
  the same RTNL-stall pattern that this series removes from CAN_RAW,…

--

can: bcm: use a private mutex instead of lock_sock()

This patch replaces lock_sock() in CAN_BCM with a private conf_lock mutex
in struct bcm_sock. The generic SOL_SOCKET options access user space under
the socket lock, and with this change they can no longer stall bcm_notify()
while it holds RTNL. bcm_release() now removes the procfs entry before it
takes the new mutex.

> Cc: stable@vger.kernel.org # depends on "can: bcm: copy the CAN frames outside of lock_sock()"

[Severity: Low]
Is this dependency note complete? The patch also seems to depend on "can:
bcm: do not remove the procfs entry in bcm_notify()", which comes earlier
in the same series.

That commit turned the plain bo->ifindex = 0 assignments into WRITE_ONCE().
This patch uses the new lines as context, for example in bcm_release():

		WRITE_ONCE(bo->ifindex, 0);
	}

+	mutex_unlock(&bo->conf_lock);

If only the listed prerequisite is applied, this patch will not apply
cleanly.

The dependency is also functional. The commit message says bcm_release()
removes the procfs entry before taking the mutex. That assumes the entry
is only ever removed in release.

Without the prerequisite, bcm_notify() still calls remove_proc_entry()
inside the NETDEV_UNREGISTER section. With this patch, that call would run
under conf_lock with RTNL held. If a backport is resolved by hand, the
RTNL stall would remain through a procfs reader stuck in copy_to_user().

The prerequisite has its own Cc: stable tag and comes first in the series,
so applying the series in order works. Could the "# depends on" note list
it too?

> diff --git a/net/can/bcm.c b/net/can/bcm.c
> index 1595b7720c981..dc9e2890490ac 100644
> --- a/net/can/bcm.c
> +++ b/net/can/bcm.c

[ ... ]

> @@ -1843,7 +1844,7 @@ static void bcm_notify(struct bcm_sock *bo, unsigned long msg,
>  	switch (msg) {
>  
>  	case NETDEV_UNREGISTER:
> -		lock_sock(sk);
> +		mutex_lock(&bo->conf_lock);
>  
>  		/* rx_ops: remove device specific receive entries */
>  		list_for_each_entry(op, &bo->rx_ops, list) {

[Severity: High]
This isn't a bug introduced by this patch, but CAN_J1939 seems to have the
same RTNL stall that this series removes from CAN_RAW, CAN_ISOTP and
CAN_BCM.

On NETDEV_UNREGISTER, the j1939 notifier runs with RTNL held and takes the
socket lock of every bound socket:

j1939_netdev_notify()
  j1939_sk_netdev_event_unregister()

net/can/j1939/socket.c:j1939_sk_netdev_event_unregister() {
    ...
		lock_sock(sk);
		if (jsk->state & J1939_SOCK_BOUND) {
    ...
}

So if a task holds the socket lock of a bound j1939 socket while it
accesses user memory, it can block RTNL. There appear to be two such
paths.

The first is the generic SOL_SOCKET options. For example, SO_ATTACH_FILTER
in sk_setsockopt() copies the filter from user space under
sockopt_lock_sock():

net/core/sock.c:sk_setsockopt() {
    ...
		ret = copy_bpf_fprog_from_user(&fprog, optval, optlen);
		if (!ret)
			ret = sk_attach_filter(&fprog, sk);
    ...
}

The second is j1939_sk_sendmsg(). It holds lock_sock() across
j1939_sk_send_loop(), which copies the payload from user space:

net/can/j1939/socket.c:j1939_sk_sendmsg() {
	lock_sock(sock->sk);
    ...
	ret = j1939_sk_send_loop(priv, sk, msg, size);

sendmsg_done:
	release_sock(sock->sk);
}

If the user buffer is on a FUSE backed mapping, either copy can stall for
as long as the user wants.

can_create() has no capability check. A user can create a vcan device in
their own user and network namespace, bind a j1939 socket to it, stall one
of these copies, and then delete the vcan device. RTNL would then be held
until the copy finishes.

None of the commit messages in the series mention j1939. Should CAN_J1939
get the same conversion, or should the series say that it is still
affected?

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261120-can-bcmlock-memcg-v7-0-f6b84f5257b1%40hartkopp.net

  reply	other threads:[~2026-11-22  2:04 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 11:28 [PATCH v7 0/8] can: avoid RTNL stalls and fix CAN_ISOTP and netlink issues Oliver Hartkopp
2026-11-20 11:28 ` [PATCH v7 1/8] can: bcm: copy the CAN frames outside of lock_sock() Oliver Hartkopp
2026-11-20 11:28 ` [PATCH v7 2/8] can: bcm: do not remove the procfs entry in bcm_notify() Oliver Hartkopp
2026-11-20 11:28 ` [PATCH v7 3/8] can: raw: use a private mutex instead of lock_sock() Oliver Hartkopp
2026-11-20 11:28 ` [PATCH v7 4/8] can: isotp: " Oliver Hartkopp
2026-11-20 11:28 ` [PATCH v7 5/8] can: bcm: " Oliver Hartkopp
2026-11-22  2:04   ` netdev-bot+sashiko [this message]
2026-11-22 17:55     ` Oliver Hartkopp
2026-11-20 11:29 ` [PATCH v7 6/8] can: isotp: always start the rx timeout in ISOTP_WAIT_DATA state Oliver Hartkopp
2026-11-22  2:04   ` netdev-bot+sashiko
2026-11-22 15:57     ` Oliver Hartkopp
2026-11-20 11:29 ` [PATCH v7 7/8] can: isotp: reject socket options while a transfer is active Oliver Hartkopp
2026-11-22  2:04   ` netdev-bot+sashiko
2026-11-22 18:26     ` Oliver Hartkopp
2026-11-20 11:29 ` [PATCH v7 8/8] can: netlink: fix static FD-NON-ISO mode validation Oliver Hartkopp

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=179531304802.3131.12745921065969332467@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-can@vger.kernel.org \
    --cc=mailhol@kernel.org \
    --cc=mkl@pengutronix.de \
    --cc=o.rempel@pengutronix.de \
    --cc=socketcan@hartkopp.net \
    --cc=zhuling0805@qq.com \
    /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