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 v6 3/8] can: raw: use a private mutex instead of lock_sock()
Date: Thu, 19 Nov 2026 06:59:21 +0000 [thread overview]
Message-ID: <179507156133.3132.786917973363273055@kernel.org> (raw)
In-Reply-To: <20261117-can-bcmlock-memcg-v6-3-6826a6227d36@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 comment this patch adds to struct raw_sock, `struct mutex
conf_lock; /* protects bind, filters and setsockopt */`, says more…
Pre-existing issues:
- [High] This patch did not introduce this problem, and it is outside
what the patch claims to fix, but the same RTNL stall is still…
- [Low] This patch did not introduce this problem.
--
can: raw: use a private mutex instead of lock_sock()
This patch replaces lock_sock() in CAN_RAW with a new conf_lock mutex in
struct raw_sock. Generic SOL_SOCKET options that touch user space while
holding the socket lock can then no longer stall raw_notify() while it
holds RTNL. The mutex serializes bind, release, the notifier, the filters
and the CAN_RAW socket options.
> diff --git a/net/can/raw.c b/net/can/raw.c
> index f14270b56f521..b69eaadc5e93a 100644
> --- a/net/can/raw.c
> +++ b/net/can/raw.c
> @@ -103,6 +103,7 @@ struct raw_sock {
> struct can_filter dfilter; /* default/single filter */
> struct can_filter *filter; /* pointer to filter(s) */
> struct uniqframe __percpu *uniq;
> + struct mutex conf_lock; /* protects bind, filters and setsockopt */
[Severity: Low]
Does this comment promise more than the code provides?
Only the CAN_RAW_FILTER branch of raw_getsockopt() takes conf_lock. Other
read-backs of state owned by setsockopt still run without it:
net/can/raw.c:raw_getsockopt() {
...
case CAN_RAW_ERR_FILTER:
if (len > sizeof(can_err_mask_t))
len = sizeof(can_err_mask_t);
val = &ro->err_mask;
break;
...
if (copy_to_iter(&ro->raw_vcid_opts, len,
&opt->iter_out) != len)
...
}
The loopback, recv_own_msgs, fd_frames, xl_frames and join_filters bits
are in the same situation. raw_setsockopt_locked() writes all of them
under the mutex, but these readers don't take it.
The error mask is a filter too. Could the comment list the paths that
actually take the lock (bind, release, the notifier, setsockopt and the
CAN_RAW_FILTER read-back)?
The commit message says ro->raw_vcid_opts will be handled in a
follow-up, but no later patch in this series seems to make that change.
> };
>
> static LIST_HEAD(raw_notifier_list);
[ ... ]
> @@ -328,9 +329,9 @@ static void raw_notify(struct raw_sock *ro, unsigned long msg,
>
> switch (msg) {
> case NETDEV_UNREGISTER:
> - lock_sock(sk);
> + mutex_lock(&ro->conf_lock);
> if (ro->dev != dev) {
> - release_sock(sk);
> + mutex_unlock(&ro->conf_lock);
> break;
> }
[Severity: High]
This isn't a bug introduced by this patch, but can CAN_J1939 sockets
still trigger the same RTNL stall?
The series converts raw, isotp ("can: isotp: use a private mutex instead
of lock_sock()") and bcm ("can: bcm: use a private mutex instead of
lock_sock()"). j1939 still calls lock_sock() from its netdevice notifier
while RTNL is held:
j1939_netdev_notify() /* NETDEV_UNREGISTER, RTNL held */
j1939_sk_netdev_event_unregister()
lock_sock(sk)
net/can/j1939/socket.c:j1939_sk_netdev_event_unregister() {
...
sock_hold(sk);
read_unlock_bh(&priv->j1939_socks_lock);
...
lock_sock(sk);
if (jsk->state & J1939_SOCK_BOUND) {
...
}
sk_setsockopt() still reads user memory while it holds
sockopt_lock_sock(sk). Examples are copy_from_sockptr(&ling, ...) for
SO_LINGER and copy_bpf_fprog_from_user() for SO_ATTACH_FILTER.
can_create() has no capability check for CAN_J1939. With user namespaces
and unprivileged FUSE enabled, an unprivileged user could:
1. create a CAN_J1939 socket and bind it to a vcan device in their own
network namespace
2. call setsockopt(SOL_SOCKET, SO_LINGER) with optval in a FUSE backed
mapping whose daemon never answers, so sk_setsockopt() sleeps in
copy_from_sockptr() while holding the socket lock
3. delete the vcan device
j1939_sk_netdev_event_unregister() would then block in lock_sock() with
RTNL held for as long as the copy stays stalled.
Does j1939 need the same conversion as raw, isotp and bcm?
[ ... ]
> @@ -831,7 +834,7 @@ static int raw_getsockopt(struct socket *sock, int level, int optname,
> struct can_filter *filter = NULL;
> int err = 0;
>
> - lock_sock(sk);
> + mutex_lock(&ro->conf_lock);
> if (ro->count > 0) {
> int fsize = ro->count * sizeof(struct can_filter);
>
[ ... ]
> @@ -851,7 +854,7 @@ static int raw_getsockopt(struct socket *sock, int level, int optname,
> } else {
> len = 0;
> }
> - release_sock(sk);
> + mutex_unlock(&ro->conf_lock);
>
> if (filter) {
> if (copy_to_iter(filter, len, &opt->iter_out) != len)
[Severity: Low]
This is a pre-existing issue, but can lockless readers of the VCID state
see a concurrent setsockopt(CAN_RAW_XL_VCID_OPTS) only partly applied?
The writer updates several fields under conf_lock:
net/can/raw.c:raw_setsockopt_locked() {
...
case CAN_RAW_XL_VCID_OPTS:
memcpy(&ro->raw_vcid_opts, val, sizeof(ro->raw_vcid_opts));
/* prepare 32 bit values for handling in hot path */
ro->tx_vcid_shifted = ro->raw_vcid_opts.tx_vcid << CANXL_VCID_OFFSET;
ro->rx_vcid_shifted = ro->raw_vcid_opts.rx_vcid << CANXL_VCID_OFFSET;
ro->rx_vcid_mask_shifted = ro->raw_vcid_opts.rx_vcid_mask << CANXL_VCID_OFFSET;
...
}
raw_getsockopt(CAN_RAW_XL_VCID_OPTS) copies ro->raw_vcid_opts to user
space without the lock.
raw_rcv() reads ro->raw_vcid_opts.flags, rx_vcid_shifted and
rx_vcid_mask_shifted in softirq context. raw_put_canxl_vcid() reads the
flags and tx_vcid_shifted. Neither takes the lock.
Could a frame then be filtered or tagged with the new flags but the old
VCID values, or could getsockopt return a torn copy?
The commit message defers this to a follow-up, and no later patch in the
series appears to change it.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261117-can-bcmlock-memcg-v6-0-6826a6227d36%40hartkopp.net
next prev parent reply other threads:[~2026-11-19 6:59 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 16:35 [PATCH v6 0/8] can: avoid RTNL stalls and fix CAN_ISOTP and netlink issues Oliver Hartkopp
2026-11-17 16:35 ` [PATCH v6 1/8] can: bcm: copy the CAN frames outside of lock_sock() Oliver Hartkopp
2026-11-17 16:35 ` [PATCH v6 2/8] can: bcm: do not remove the procfs entry in bcm_notify() Oliver Hartkopp
2026-11-19 6:59 ` netdev-bot+sashiko
2026-11-17 16:35 ` [PATCH v6 3/8] can: raw: use a private mutex instead of lock_sock() Oliver Hartkopp
2026-11-19 6:59 ` netdev-bot+sashiko [this message]
2026-11-17 16:35 ` [PATCH v6 4/8] can: isotp: " Oliver Hartkopp
2026-11-17 16:35 ` [PATCH v6 5/8] can: bcm: " Oliver Hartkopp
2026-11-17 16:35 ` [PATCH v6 6/8] can: isotp: always start the rx timeout in ISOTP_WAIT_DATA state Oliver Hartkopp
2026-11-19 6:59 ` netdev-bot+sashiko
2026-11-17 16:35 ` [PATCH v6 7/8] can: isotp: reject socket options while a transfer is active Oliver Hartkopp
2026-11-17 17:17 ` sashiko-bot
2026-11-17 18:58 ` Oliver Hartkopp
2026-11-19 6:59 ` netdev-bot+sashiko
2026-11-17 16:35 ` [PATCH v6 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=179507156133.3132.786917973363273055@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