Article View: linux.kernel.netdev
Article #11365Re: [PATCH net 09/15] can: raw, isotp: copy socket options outside of lock_sock()
From: netdev-bot+sashiko
Date: Wed, 04 Nov 2026 20:46
Date: Wed, 04 Nov 2026 20:46
187 lines
13555 bytes
13555 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 1 (1) · Medium: 0 · Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] The patch does not remove the RTNL stall it describes.
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but CAN_BCM has
the same RTNL-stall problem through a sibling notifier, and the series…
--
can: raw, isotp: copy socket options outside of lock_sock()
This commit moves the user space copies for the CAN_RAW and CAN_ISOTP
socket options, including the CAN_RAW_FILTER filters, so they happen
before lock_sock(). raw_getsockopt() now duplicates the filters under
the socket lock and copies them to user space after release_sock(). The
goal is to stop a stalled user copy from holding lock_sock() and blocking
raw_notify()/isotp_notify() under RTNL.
Link: https://patch.msgid.link/20261027-can-rx-lock-v12-4-eb5afc2d8b9b@hartkopp.net
> diff --git a/net/can/raw.c b/net/can/raw.c
> index d6517f71cadeb..0926d5686e419 100644
> --- a/net/can/raw.c
> +++ b/net/can/raw.c
[ ... ]
> @@ -795,17 +730,84 @@ static int raw_setsockopt(struct socket *sock, int level, int optname,
> sockptr_t optval, unsigned int optlen)
> {
> struct sock *sk = sock->sk;
> + struct can_filter *filter = NULL; /* dyn. alloc'ed filters */
> + struct can_filter sfilter; /* single filter */
> + union {
> + can_err_mask_t err_mask;
> + int flag;
> + struct can_raw_vcid_options vcid_opts;
> + } val;
> + unsigned int size = 0;
> + int count = 0;
> int err;
>
> if (level != SOL_CAN_RAW)
> return -EINVAL;
>
> + /* Copy the option values from user space before lock_sock(), so a
> + * stalled copy can not block raw_notify() waiting for lock_sock()
> + * under RTNL.
> + */
[Severity: High]
The comment says a stalled copy can not block raw_notify() waiting for
lock_sock() under RTNL. Is that true for the socket as a whole?
The same bound CAN_RAW socket can still hold the socket lock during a
user copy through the SOL_SOCKET path. sk_setsockopt() takes the lock
before it handles SO_ATTACH_FILTER:
net/core/sock.c:sk_setsockopt() {
...
sockopt_lock_sock(sk);
...
ret = sk_attach_filter(&fprog, sk);
...
}
and sk_attach_filter()->__get_filter() then copies the program from
user space:
if (copy_from_user(prog->insns, fprog->filter, fsize)) {
SO_ATTACH_REUSEPORT_CBPF goes down the same path. On the getsockopt
side, sk_get_filter() calls copy_to_sockptr() under sockopt_lock_sock().
That is the SOL_SOCKET equivalent of the CAN_RAW_FILTER copy this patch
moves after release_sock().
Suppose fprog.filter points into a FUSE or userfaultfd backed mapping
that never resolves. On NETDEV_UNREGISTER or a netns change of the
bound device, raw_notify() then waits under RTNL:
net/can/raw.c:raw_notify() {
...
case NETDEV_UNREGISTER:
lock_sock(sk);
...
}
As far as I can tell, net/can/ has no capability checks. That would
make this reachable by any local user who can create and bind a CAN_RAW
socket.
The commit message says "The generic SOL_SOCKET options in
sk_setsockopt() are not affected by this patch". It does not say that
the RTNL stall is still reachable on the same socket. No later patch in
the series changes net/core/sock.c or net/core/filter.c.
Would it be better to stop raw_notify() and isotp_notify() from blocking
on lock_sock() under RTNL? The other option would be to also move the
generic filter copies out of the socket lock.
> + switch (optname) {
> + case CAN_RAW_FILTER:
[ ... ]
> + if (size) {
> + if (optlen != size)
> + return -EINVAL;
> +
> + if (copy_from_sockptr(&val, optval, size))
> + return -EFAULT;
> + }
> +
> lock_sock(sk);
>
> - err = raw_setsockopt_locked(sock, optname, optval, optlen);
> + err = raw_setsockopt_locked(sock, optname, &val, filter, count);
>
> release_sock(sk);
[Severity: High]
This is a pre-existing issue and was not introduced by this patch, but
CAN_BCM seems to have the same RTNL stall through its notifier. This
series does not address or mention it.
bcm_sendmsg() takes the socket lock and then dispatches to
bcm_tx_setup(), bcm_rx_setup() and bcm_tx_send(). These copy the CAN
frames from the user iovec while the lock is held:
net/can/bcm.c:bcm_sendmsg() {
...
lock_sock(sk);
...
}
net/can/bcm.c:bcm_tx_setup() {
...
err = memcpy_from_msg((u8 *)cf, msg, op->cfsiz);
...
}
bcm_notify() takes the lock for every bcm socket in the netns under
RTNL. It does this before checking whether the socket is bound to the
vanishing device:
net/can/bcm.c:bcm_notify() {
...
if (!net_eq(dev_net(dev), sock_net(sk)))
return;
switch (msg) {
case NETDEV_UNREGISTER:
lock_sock(sk);
...
}
Say a BCM socket sends TX_SETUP, RX_SETUP or TX_SEND with the frame
data in a FUSE or userfaultfd backed mapping that stalls. Can any CAN
device unregistration in that netns then block RTNL indefinitely?
No later patch in the series changes these paths. The only bcm.c
changes are proc and can_rx_register naming.
>
> + /* on error free the filters allocated for CAN_RAW_FILTER above */
> + if (err && count > 1)
> + kfree(filter);
> +
> return err;
> }
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261103204305.3211144-2-mkl%40pengutronix.de
Technical Details
Message-ID:
<179382520924.488856.15425235949830518760@kernel.org>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-356909-linux-kernel-netdev=dewy.ruReferences:
<20261103204305.3211144-10-mkl@pengutronix.de>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-356909-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net 09/15] can: raw, isotp: copy socket options outside of lock_sock() Date: Wed, 04 Nov 2026 20:46:49 +0000 Organization: Usenet Network Message-ID: <179382520924.488856.15425235949830518760@kernel.org> References: <20261103204305.3211144-10-mkl@pengutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="3516046"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:kkdl9QraAT64SLT8WByYDWWY06E= sha256:B0jyQ9vrk/yT/Y1woQ09QWcFTOHKRlRV+7XolegCp6o= sha1:DBMOkhbvjf9EIJsXu5duWCfZ9Ik= sha256:11ZcWzS0ACaS4LP65oz5rwSxrWVyyxNANuaaCy+m6Zg= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 8A711112DF2; Thu, 5 Nov 2026 02:33:47 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.4 X-Spam-Status: No, score=-3.4 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id b7X_np8a_idX; Thu, 5 Nov 2026 02:33:43 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-356909-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id 59ADE112D63; Thu, 5 Nov 2026 02:33:33 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id 1386B8575F; Wed, 4 Nov 2026 21:24:51 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1793825216; b=sJeuOMbxcJ8Spl88tKB1q7DmmQ9WcFyDJqKwOFvesesmH7apZYw07SZ/Z/67NVZ+HPfj 5Y/1YuNF76xw50H1Z9Jp4i1oY2Mdxfe17DdRDSqnDnbV2jQeZC0GS3Oso1LSUWbI5h3Fb mfNvlWSj+OHUG4zSwR0RJrIogKRwZod+rVlVZmmrd5pBoI+d/pBZqr/fLWHygfwBwklnP YlvLLnQZqbcqQT5xD4vBJmWGrXT0EiaesRX6B1OZD5Wxh/V7hVGlnF4gkgtDPNzwtzfZx dtA04R3B1CV0tL6GtLhI238n3ziimcpJvhwMLd3Jc4PpiOnU3oclxzvfYj2E4Q3JKyw== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793825216; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=6kDklRHxeJbP19X2gPkeCnRUqEiSyCdqaMmB98XvLnw=; b=k53//Y8Ysbqpmv2bE1R6O5YUlkaie15j+SzWd5mIEitPiuNWw7mSVO57YFTcpkOwV7aL w9z6zgncUWxpVYXB6b3qyPkWQZsxZ+dfq1SeOZUPkE5ag9IUPiyvgpjgubUG0s9Ye1mm1 g3YV+GguveUuaasXdv0PbyR5lGYTT8MgZH1IhxLoRgh3GwLxp3pqxINF0S4hna8cGto0I adijPj/aG/AX/VUGsvgNzGCKz/lwMJFL7F/gr+uF+4c7MFplLqDXyjaaiCRswUqEKfqkp iURA0g+VibEoAMEAIqhF1tPh4WSeFaoagpdjasG1xly0//extj7/V0GoT0TvzQpvrDg== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=C8AGlTNP; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A79306096906; Wed, 4 Nov 2026 20:46:56 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=C8AGlTNP X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793825210; b=aTszMjearo/TqxscM611lCIjkrYGZmLX3+7MB8E1mXscssizem7iIBIC2ZB6SNGKo8Mr DqCSfVJnL80ji1aIn1YQhOBqCDo9I4UbOmbUWt2cnIlq++DEYynY7LrtS+kXNLN+zbrB0 i/gg7NuR9SYGx3ah1VpyotRccyuvB6JYbsttZB0ZhFdJnW6kvfN2DXtnVnZ/UUmKqGTzs Rh8lSqrzS5kU3wy6ulmazOPSo7zs1TbJWa8FmWHUCP6CyAZfgDPMPSLpYEc4KjbGHA6iZ dgEozOFdbUMDgatu1mkw8k8qpp7lpT/qRqiIIj5eVO0kFMrLv53y+hqpNVl1iDBKvvA== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793825210; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=6kDklRHxeJbP19X2gPkeCnRUqEiSyCdqaMmB98XvLnw=; b=LBRWCtpGvVGREAFrrHPIcTOtIuiLICeCO6U0pOigw4ZrhKhyfwJYrWxrJVaaHGFrHKdF 84lh+w1dsWTFooRQ6uWpdPBcs4bclRC1lEd9zsJVYTW47dYoPqUjJaQpX+sIkdSZQz29/ NzeKpPTnChLeUDWRmWgm4tVirg+vLDYuleIrH7bIES4T3Jv19/n3OeJF6QnVDHd+AYibg 4lKkGE4Kv3IexoGORYuJ57qwSg4wey84c6NsSDyH1e/gHbre/IZX/IFxK5r+5DQ4EKzHk YzL8+3LsIqVAVb9lgkG8Zh2OfU8j0vi4QC/bfQpcK3RyecrKOmiLmWGdMnF2w6FW9Sg== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=C8AGlTNP; arc=none smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 839BE6083633; Wed, 4 Nov 2026 20:46:50 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id AD4F91F00A02; Wed, 4 Nov 2026 20:46:49 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1793825210; bh=6kDklRHxeJbP19X2gPkeCnRUqEiSyCdqaMmB98XvLnw=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=C8AGlTNPofwk9WqlC3PZ6Qy5pgZqKZ+yY+QgOm+d9053PINrbfWJ2uQaVQiYmNWIi h7+2tvXujDavHFg8gsI6w0cmaFK8/j1PQmafzx8D9T9ybMqkjapapGrYeb2P8RjRZf hDtcCZZjna03JgxPn7QPQ14ioplEz1fYh0m1OVqboYIYWE8jtz5L6BEbp7c100QK16 /RymX0IErQxOgaw6WpAX6aLoGp8cfRaietv0DwpANxG/PrtJH8kufXDQSYtRFzY9xj PUmGUp4+uDwYBrnUqaKGEK5QBkJfp6LAYWptEHiKFWEwzS8TS/cIthxvbObtfq9C3q db1iJ4DFZObgQ== X-Cc: netdev@vger.kernel.org, davem@davemloft.net, kuba@kernel.org, linux-can@vger.kernel.org, kernel@pengutronix.de, liucj1228@outlook.com, s.grosjean@peak-system.fr, stable@vger.kernel.org X-In-Reply-To: <20261103204305.3211144-10-mkl@pengutronix.de> X-sashiko-severity: High X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list