🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #22400

Re: [PATCH net 07/12] can: isotp: reject socket options while a transfer is active

#22400
From: netdev-bot+sashiko
Date: Wed, 25 Nov 2026 08:58
169 lines
13903 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 2 · 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).

- [Medium] The commit message says that moving the `ae`/`wait_tx_done`
  reads after the claim means "all socket options used by…
- [Medium] The new check in isotp_setsockopt_locked() (net/can/isotp.c,
  lines 1737-1739) reads so->tx.state and so->rx.state with READ_ONCE()…

--

can: isotp: reject socket options while a transfer is active

This patch makes isotp_setsockopt_locked() return -EAGAIN while
so->tx.state or so->rx.state is not ISOTP_IDLE, mirroring the check in
isotp_bind(). It also moves the CAN_ISOTP_EXTEND_ADDR and
CAN_ISOTP_WAIT_TX_DONE reads in isotp_sendmsg() to after the transfer claim
and the so->bound recheck.

Link: https://patch.msgid.link/20261120-can-bcmlock-memcg-v7-7-f6b84f5257b1@hartkopp.net

> diff --git a/net/can/isotp.c b/net/can/isotp.c
> index 0b7db1ead7a90..642fec500af9d 100644
> --- a/net/can/isotp.c
> +++ b/net/can/isotp.c

[ ... ]

> @@ -1188,6 +1188,10 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
>  		goto err_out_drop;
>  	}
>  
> +	/* read the options after the claim of the transfer */
> +	ae = (so->opt.flags & CAN_ISOTP_EXTEND_ADDR) ? 1 : 0;
> +	wait_tx_done = (so->opt.flags & CAN_ISOTP_WAIT_TX_DONE) ? 1 : 0;
> +

[Severity: Medium]

The commit message says this change means "all socket options used by
isotp_sendmsg() are covered by this check". Is that accurate?

Later in isotp_sendmsg(), so->ll.tx_flags is still read after the final
tx.state is published, the timeout is armed and so->rx_lock is dropped:

net/can/isotp.c:isotp_sendmsg() {
    ...
	WRITE_ONCE(so->tx.state, new_state);
	hrtimer_start(tx_hrt, ktime_set(hrtimer_sec, 0),
		      HRTIMER_MODE_REL_SOFT);
	spin_unlock_bh(&so->rx_lock);

	/* send the first or only CAN frame */
	cf->flags = so->ll.tx_flags;
    ...
}

After that point the transfer can return to ISOTP_IDLE without sendmsg()
doing anything. isotp_tx_timeout() can cmpxchg tx.state to IDLE after the
FC or echo timeout. In WAIT_FIRST_FC, an FC frame that isotp_rcv_fc()
handles (overflow, unknown status, bad padding) can also set IDLE.

Suppose NETDEV_UNREGISTER then clears so->bound in isotp_notify(). Then
isotp_setsockopt_locked() passes both the so->bound check and the new
tx.state/rx.state check. CAN_ISOTP_LL_OPTS can then memcpy() a new so->ll
before the cf->flags assignment runs.

Would the first frame then take its flags byte from the new options, while
its skb size (old ll.mtu), length and payload come from the old ones?

can_send() usually fails with -ENETDOWN here. The frame could still go out
if the device was moved to another netns and brought up again.

Could cf->flags be set while the frame is built, before tx.state is
published and the timer is armed?

[ ... ]

> @@ -1726,6 +1730,14 @@ static int isotp_setsockopt_locked(struct socket *sock, int optname,
>  	if (so->bound)
>  		return -EISCONN;
>  
> +	/* A transmission or reception that outlived a previous binding
> +	 * (unbound by NETDEV_UNREGISTER) may still be draining and uses the
> +	 * socket options, see isotp_bind().
> +	 */
> +	if (READ_ONCE(so->tx.state) != ISOTP_IDLE ||
> +	    READ_ONCE(so->rx.state) != ISOTP_IDLE)
> +		return -EAGAIN;
> +

[Severity: Medium]

This check runs under conf_lock only, without so->rx_lock. Can it race with
RX paths that have already set rx.state to ISOTP_IDLE but are still reading
the socket options?

For example, isotp_rcv_ff() sets IDLE on entry. On the overflow path it
then calls isotp_send_fc():

net/can/isotp.c:isotp_rcv_ff() {
    ...
	hrtimer_cancel(&so->rxtimer);
	WRITE_ONCE(so->rx.state, ISOTP_IDLE);
    ...
	if (so->rx.len > so->rx.buflen) {
		/* send FC frame with overflow status */
		isotp_send_fc(sk, ae, ISOTP_FC_OVFLW);
		return 1;
	}
    ...
}

isotp_send_fc() reads so->ll.mtu twice:

net/can/isotp.c:isotp_send_fc() {
    ...
	nskb = alloc_skb(so->ll.mtu, gfp_any());
    ...
	skb_put_zero(nskb, so->ll.mtu);
    ...
}

It also reads so->opt, so->rxfc and so->ll.tx_flags.

There are similar cases:

- isotp_rcv_cf() sets IDLE before check_pad() uses so->opt.
- isotp_rcv_sf() sets IDLE and then reads so->opt.
- isotp_rcv() reads so->opt.flags, so->ll.mtu and so->opt.rx_ext_address
  before it takes spin_lock(&so->rx_lock) at all.

isotp_notify(NETDEV_UNREGISTER) calls can_rx_unregister() and clears
so->bound without waiting for a grace period. The comment in
isotp_release() already says this happens "without waiting for in-flight
isotp_rcv() callers to finish".

Frames can still arrive in that window. For example, vxcan_xmit() delivers
to the peer via netif_rx() without checking IFF_UP, and can_rcv() does not
check it either.

So setsockopt() could see bound == 0 with both states IDLE, and overwrite
so->opt, so->ll, so->rxfc or so->tx.ll_dl while isotp_rcv() on another CPU
is still using them. Couldn't that produce an FC frame built from mixed
option sets (alloc_skb() with the old ll.mtu, skb_put_zero() with the new
one), or run padding checks against the wrong options?

Would either of these close the window?

- Do the state check and the option update under
  spin_lock_bh(&so->rx_lock), and move isotp_rcv()'s pre-lock option reads
  under that lock.
- Wait for a grace period after the unregister.

If so, the commit message claim that "the socket options can only be
changed when no transfer is active" would also hold on the RX side.

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261124085757.1093632-2-mkl%40pengutronix.de
Technical Details
Message-ID: <179559711531.3135.15295307789383806315@kernel.org>
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-371150-linux-kernel-netdev=dewy.ru
References: <20261124085757.1093632-8-mkl@pengutronix.de>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-371150-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net 07/12] can: isotp: reject socket options while a
 transfer is active
Date: Wed, 25 Nov 2026 08:58:35 +0000
Organization: Usenet Network
Message-ID: <179559711531.3135.15295307789383806315@kernel.org>
References: <20261124085757.1093632-8-mkl@pengutronix.de>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="160876"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:VQaHCKd+QipcICHhFGe6O5p93GA= sha256:wQTiuJJGOp6xJXHgbZShgMaFM9URNkJF7mA8GBqgdIQ=
	sha1:D0lyWHBBeTBEMwzQU3cUhiiaR94= sha256:OFBZfbqxLsrBbvs5ubMVAo1QDN27iOBe8DEuyLf1GzY=
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 63EE5125E3D; Wed, 25 Nov 2026 11:59:11 +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 dp3beoZaQoCX;
	Wed, 25 Nov 2026 11:59:07 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-371150-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 sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 4E823125E3F; Wed, 25 Nov 2026 11:58:59 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 975F43B356; Wed, 25 Nov 2026 08:58:42 +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=1795597122;
	b=0iUhGjQEXi0U0YND6gfCWySWzWzUhDx8lOMmf+WINUwU1fhxVDlI63jBo07jIcPdtwxX
	 5sOcgGHRXg57BmG1Y6TXUQfRVX8gnnSQqWMoiWaZcpyZSxH1skq+iJlyLC8Kd5vOMMgKG
	 Tt6J9TPvRHsC77YX/j79axdvzOXXMEGZPJFDnziLJzs2LKqcAhZjQCl2fB9OaF8ziTUtf
	 sBjmmKkkUYT6TiO1wFgE6RYmzqt+3I5PvkDwjQGO5CoHVeasmWkhOxqQ7IVo3KV9Sr8RQ
	 N5VYsz5XD+I/QMJzpl7KfNgK+8r0vThr4Gyt28nqAtHwBKei36tIQL60EZchN4P0fEA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795597122;
	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=SmlnObTyvLLWex2fHr/9/apQ6tGYW8v7LEnW15NaoWc=;
	b=xlhHeflk2+CPG/vOFib2CKlEW2vj3rHqDgrew/WzqIE/HztDwg5MxZz9lrZUUZRWfDc0
	 /ZiZqXFe/RwbjqakT8YtTXdUtSqy7NlR2IhcPT0Qmnd5kfDVlMBwKGU1/owILcSrKK236
	 yy5UsMjyZCbs9kk4o5vg9/8wj+WkTh0Xg9TbJfZsstQle935EYWat4dd7o5QLc4MQnpkk
	 ABFUsUi+neg0idh7gjX/g01wwpqx9DqVJonMnME053rPF1AcokVQuch9ZDdRV1TvhxgeR
	 RhNTQeAv+DWqS1Jrci+L63p7wPmOeScMaT5B/yWqg0bQP5bm0HYIHW2j7Ftb0tI3m8g==
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=GF2jJNlW;
	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 6FE53606A31E;
	Wed, 25 Nov 2026 08:58:42 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=GF2jJNlW
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=1795597116;
	b=RuhRhxlDy8unRDGdD+aoG9OQcjt+SaTIsoeTYCFnWAdARyl+G+kJnCQ6gVg/bx1XHoVI
	 EmREIusSAfEHrOkc51EGKzQLcnvbr68tMglDg2pqZEi8979peJognfKA/sDDy3y2XAMTX
	 nAQTbdyB5RUjUQ8br4igG/6HD7a1ql+erTqF8hPHcfj/BLSTa+j6cO9oRAPjAo+oow2yZ
	 hq50C1etQEEQGSO8JajIctwpbJJoKZgKUdsKOY4chB4qz3Ormr+Yt7Cs10OryijHW1d9K
	 Ze23duyKUBtiIgMMH3vDGVpubUOCfvmsLBANsOf/FlW30WWhd77LehhN3qITZBi+xwg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795597116;
	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=SmlnObTyvLLWex2fHr/9/apQ6tGYW8v7LEnW15NaoWc=;
	b=n/TcIZzBdjkM4ZUwkgAh0Nc6nS25YDbCXIc4Er6+ZHb0MbaTw4qNZIqCJ+J5E9/EsHJT
	 2vrdyQRhMA+GhGkUmyl4m0d83sTGFbI7zs/48sZnHCbQwqzVNv0cRne8k68N+rf2tgxWG
	 OHB5mxXatkh6MPCD0i9ll8sUeY/GlmjON3B3OekIDHBv7ZcDK9iCIitz4VLVWE1VRl9vj
	 j2efDXdhIfe4MEcSQVl2OLnhsbmKRb5dJQjSlCHBgiExCbrRe2zBQs2CnDmQT9FeBr84y
	 NSAZ7ZADMhrOLJ8JTDJ+1sGWooeQ8/mBMOrHsBbHkayZ/bp+bvDTU3hu9VpeaIuLzXg==
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=GF2jJNlW;
	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 8FB24606A68D;
	Wed, 25 Nov 2026 08:58:36 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id BACAF1F000EC;
	Wed, 25 Nov 2026 08:58:35 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795597116;
	bh=SmlnObTyvLLWex2fHr/9/apQ6tGYW8v7LEnW15NaoWc=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=GF2jJNlWPjiai7ydXLSS09EXB3h/ov1GxwtX0gIt+Uo2+bI/zN4iYVDqU6VaKVW9S
	 LPbQT7LSzoP8YhwPc6ezH8qFY6rZf8DtMzZFwvm+peI8Qf3G1e2PnCo/hfZUS+zI+z
	 AOkZc1LBzrh6L0S/S5ml7nLcmEC2vImn9A73uHEiRmqVazeXSoUyJ9oXgvHvTSoHi5
	 uF3uWr6h7aPpHfgbTYsY2K3iYow8fo0pDHyLfjQSkqZFPmH6NXUHCYkWHo88NPDqC6
	 2ZGuATJNtnM2Gt+ZFV7RkTOgi28+p/lBWqcdJ1VR1FfJXnZ5r8uuIFXHVNN6f/6nPz
	 TfDrzTX0PUSzg==
X-Cc: netdev@vger.kernel.org, davem@davemloft.net, kuba@kernel.org,
 linux-can@vger.kernel.org, kernel@pengutronix.de,
 u.kleine-koenig@baylibre.com, stable@vger.kernel.org, mailhol@kernel.org,
 robh@kernel.org, linux-kernel@vger.kernel.org, jeanmichel.hautbois@yoseli.org
X-In-Reply-To: <20261124085757.1093632-8-mkl@pengutronix.de>
X-sashiko-severity: Medium
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