From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796434043; b=v87y3fVsanQZVEJwYLwVp7usCnxkmDgstikXNBTLIPAf3XwFQmBGokfIGI51cVLHKJqt bM54aNVqJ80tjVR/57SiuETcwGYh4PtHHGYsgkGRykgJKjynwLg1yr4cr6VG8LpFhQhMo d+2Y8UNGQjsTPevKptisnJQFp9mTjKGW3aYs+BzFGSp56odsZzshsOTk+Ymtviv9hYZcd Mv5YFJMQDB5pD9IO/tVsLzomGT0dMBQqEKqpwpB60s10ZIoINkc/N+sb/5fy8aQaJYRmC MYmUZXoEDO0zRcX+BjzvDSzINViBPSg9iHPvD1ani9O+opwz9rhacbvlthWDTVb2FBg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796434043; 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=QC3RepMqXD1OcYKG1nOKH4/8AcmMjuE4w9zr5/4T6uU=; b=Iv+h3tegBvUIfUGRdx6ZpHixLfH1N/K6qT2FflorMYwGg1L0m7HkHNq7VyyplbEdR0so rR23pFaxh2KDCMojPQVe+pi4a1nny5bUDz8D3zPfJSJArn+LyXynN0bXN8XzgTqk5B51M ogo5Fu+ojOeL5rtotuA1RL0Hn3JG3IirsamXcrXloWY8RFXauXXwDkJNsGrwawTIILtGb Nfh/sB+mRYKGKULsjAeBJfPv23NLyEsbSW6ZLtCO7hpGJXEhKopBBQtToH7DuqdCf4ZLw LDjR5Pm/PH4kw3Ggk8CFkcFnv+30LCU+DIDyxZLpfkhFtap2gRs9v+h8qGEPOsLIcjA== 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=Kj8SU5YS; arc=none smtp.remote-ip=100.103.45.18 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 3E735606A322 for ; Sat, 5 Dec 2026 01:27:23 +0000 (UTC) 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=Kj8SU5YS Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9BA8C1F0092B; Sat, 5 Dec 2026 01:27:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796434042; bh=QC3RepMqXD1OcYKG1nOKH4/8AcmMjuE4w9zr5/4T6uU=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=Kj8SU5YSXn+8goOlC+EhdKQf+B+P/rNMIpGXMkZCCgvlQZPuvd4A3vnz6ErXDPXwZ 7ahVZA45exXB6SxPgkXoqXTn9y8LEHM47xZu6yN3R4zaRSUrTXiEzonhbTAQORhWY6 B+2/vsI5tpZzFkFxTyekSf4hreoZNVoWIu/YGZDUGMvuiE4meTV/i81jbWAYa5Y7q1 KxZHYOvcO7MRn2wbhKx6tCzhfnRdWpol5dUXC8yT/SpmjTCEzhLTuHVod97I5Y8N9v nCn0owogHoSSiZ0K975zRi2Qq4KcVSPqMgSvdC7JXFrb5UnAHHnCqmh0dF1b94HBE/ LDFmx9EbF5bVQ== Subject: Re: [PATCH can-next v5 10/24] can: isotp: check the CAN FD tx_flags in CAN_ISOTP_LL_OPTS From: netdev-bot+sashiko@kernel.org To: socketcan@hartkopp.net Cc: linux-can@vger.kernel.org, mkl@pengutronix.de, kuba@kernel.org Date: Sat, 05 Dec 2026 01:27:22 +0000 Message-ID: <179643404216.3142.8251952005737867211@kernel.org> In-Reply-To: <20261203-getsockopt-memcg-isotp-v5-10-bbe89b3d3b71@hartkopp.net> References: <20261203-getsockopt-memcg-isotp-v5-10-bbe89b3d3b71@hartkopp.net> X-sashiko-severity: Medium Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: linux-can@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider. Critical: 0 · High: 0 · Medium: 1 · Low: 1 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] can: isotp: forcing CANFD_FDF in tx_flags breaks getsockopt() UAPI - [Low] The comment this patch adds to the uAPI header (include/uapi/linux/can/isotp.h, struct… -- can: isotp: check the CAN FD tx_flags in CAN_ISOTP_LL_OPTS This commit restricts the CAN FD tx_flags in CAN_ISOTP_LL_OPTS to CANFD_BRS and CANFD_FDF and rejects any other flags with -EINVAL. It also always adds CANFD_FDF to the stored tx_flags for CAN FD, so getsockopt() returns the flags of the created frames. The accepted flags are documented in isotp.h and iso15765-2.rst. > diff --git a/Documentation/networking/iso15765-2.rst b/Documentation/networking/iso15765-2.rst > index 139bca8cdaa7e..bac298ebe6bbc 100644 > --- a/Documentation/networking/iso15765-2.rst > +++ b/Documentation/networking/iso15765-2.rst > @@ -288,7 +288,11 @@ where the ``can_isotp_ll_options`` structure has the following contents: > traffic (i.e.: ``mtu = CANFD_MTU``). > > * ``tx_flags``: flags set into ``struct canfd_frame.flags`` at frame creation. > - Only applies to CAN FD traffic (i.e.: ``mtu = CANFD_MTU``). > + Only applies to CAN FD traffic (i.e.: ``mtu = CANFD_MTU``) and has to be > + ``0`` for classical CAN frames. Only the ``CANFD_BRS`` flag (and the > + ``CANFD_FDF`` marker) can be set, other flags are rejected with ``-EINVAL``. [ ... ] > diff --git a/include/uapi/linux/can/isotp.h b/include/uapi/linux/can/isotp.h > index a2e5aa6f9e82d..eb8b5298f7a5b 100644 > --- a/include/uapi/linux/can/isotp.h > +++ b/include/uapi/linux/can/isotp.h > @@ -119,6 +119,8 @@ struct can_isotp_ll_options { > > __u8 tx_flags; /* set into struct canfd_frame.flags */ > /* at frame creation: e.g. CANFD_BRS */ > + /* only CANFD_BRS and CANFD_FDF allowed */ [Severity: Low] This isn't a bug, but should this uAPI comment say that the rule only applies to CAN FD? As written, the comment allows CANFD_BRS and CANFD_FDF for any mtu. The existing check in isotp_setsockopt_locked() still rejects any non-zero tx_flags for classical CAN: net/can/isotp.c:isotp_setsockopt_locked() { ... if (ll->mtu == CAN_MTU && (ll->tx_dl > CAN_MAX_DLEN || ll->tx_flags != 0)) return -EINVAL; ... } With mtu = CAN_MTU and tx_flags = CANFD_BRS, setsockopt() returns -EINVAL even though the header comment suggests the value is valid. The iso15765-2.rst text added by this patch says tx_flags "has to be 0 for classical CAN frames", so the two descriptions of the same field don't match. Could the header comment say something like "CAN FD: only CANFD_BRS and CANFD_FDF allowed, CAN CC (CAN_MTU): must be 0"? > + /* CANFD_FDF is always set for CAN FD */ > /* Obsolete when the BRS flag is fixed */ > /* by the CAN netdriver configuration */ > }; [ ... ] > diff --git a/net/can/isotp.c b/net/can/isotp.c > --- a/net/can/isotp.c > +++ b/net/can/isotp.c > @@ -1820,12 +1820,21 @@ static int isotp_setsockopt_locked(struct socket *sock, int optname, > > if (ll->mtu == CAN_MTU && > (ll->tx_dl > CAN_MAX_DLEN || ll->tx_flags != 0)) > return -EINVAL; > > + /* only CANFD_BRS (and the CANFD_FDF marker) for CAN FD frames */ > + if (ll->mtu == CANFD_MTU && > + (ll->tx_flags & ~(CANFD_BRS | CANFD_FDF))) > + return -EINVAL; > + > memcpy(&so->ll, ll, sizeof(*ll)); > > + /* CAN FD frames are always marked with CANFD_FDF */ > + if (so->ll.mtu == CANFD_MTU) > + so->ll.tx_flags |= CANFD_FDF; > + > /* set ll_dl for tx path to similar place as for rx */ > so->tx.ll_dl = ll->tx_dl; > break; > } > > [Severity: Medium] Does storing CANFD_FDF in so->ll change what existing users see from getsockopt()? Since CAN_ISOTP_LL_OPTS was added, isotp_getsockopt() has returned so->ll exactly as userspace passed it in. With this change, a CAN FD socket configured with tx_flags = 0 reads back CANFD_FDF (0x04). One configured with CANFD_BRS reads back CANFD_BRS | CANFD_FDF (0x05). Userspace that compares the result with what it set, or that tests "if (ll.tx_flags)" to see whether BRS is enabled, now gets a different answer. The commit message calls this a tightening of the uAPI. Rejecting CANFD_ESI and unknown bits fits that description. Changing the value returned to callers that passed valid flags goes further than that. It also affects callers doing a read-modify-write before bind(). Suppose a program sets mtu = CANFD_MTU with tx_flags = 0 and reads the options back. It then changes only mtu to CAN_MTU and tx_dl to 8 and calls setsockopt() again. The existing CAN_MTU check in isotp_setsockopt_locked() now rejects this with -EINVAL, because tx_flags contains the CANFD_FDF that the kernel added. can_send() in net/can/af_can.c already sets CANFD_FDF on every CAN FD frame. The commit message also says the frames on the bus don't change. So the stored flag doesn't seem to be needed on the transmit path. Would it be better to keep storing the value userspace supplied? If getsockopt() really should report the frame flags, could the CAN_MTU check at least ignore CANFD_FDF, so that the read-modify-write case keeps working? -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261203-getsockopt-memcg-isotp-v5-0-bbe89b3d3b71%40hartkopp.net