From: netdev-bot+sashiko@kernel.org
To: socketcan@hartkopp.net
Cc: linux-can@vger.kernel.org, mkl@pengutronix.de, kuba@kernel.org
Subject: Re: [PATCH can-next v5 10/24] can: isotp: check the CAN FD tx_flags in CAN_ISOTP_LL_OPTS
Date: Sat, 05 Dec 2026 01:27:22 +0000 [thread overview]
Message-ID: <179643404216.3142.8251952005737867211@kernel.org> (raw)
In-Reply-To: <20261203-getsockopt-memcg-isotp-v5-10-bbe89b3d3b71@hartkopp.net>
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
next prev parent reply other threads:[~2026-12-05 1:27 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 11:55 [PATCH can-next v5 00/24] can: memcg accounting, CAN_ISOTP fixes and cleanups Oliver Hartkopp
2026-12-03 11:55 ` [PATCH can-next v5 01/24] can: raw: read socket options under conf_lock in raw_getsockopt() Oliver Hartkopp
2026-12-03 11:55 ` [PATCH can-next v5 02/24] can: isotp: read socket options under conf_lock in isotp_getsockopt() Oliver Hartkopp
2026-12-03 12:22 ` sashiko-bot
2026-12-05 1:27 ` netdev-bot+sashiko
2026-12-03 11:55 ` [PATCH can-next v5 03/24] can: enable memcg accounting for user triggered allocations Oliver Hartkopp
2026-12-03 12:41 ` sashiko-bot
2026-12-05 1:27 ` netdev-bot+sashiko
2026-12-03 11:55 ` [PATCH can-next v5 04/24] can: isotp: do not send FC.OVFLW in listen mode Oliver Hartkopp
2026-12-05 1:27 ` netdev-bot+sashiko
2026-12-03 11:55 ` [PATCH can-next v5 05/24] can: isotp: check the CAN_ISOTP_OPTS values before applying them Oliver Hartkopp
2026-12-05 1:27 ` netdev-bot+sashiko
2026-12-03 11:55 ` [PATCH can-next v5 06/24] can: isotp: add the frame transmission time to the CF broadcast gap Oliver Hartkopp
2026-12-05 1:27 ` netdev-bot+sashiko
2026-12-03 11:55 ` [PATCH can-next v5 07/24] can: isotp: limit the frame transmission time to the N_As/N_Ar timeout Oliver Hartkopp
2026-12-03 11:55 ` [PATCH can-next v5 08/24] can: isotp: add N_As timeout monitoring for SF/FF/CF Oliver Hartkopp
2026-12-03 14:11 ` sashiko-bot
2026-12-05 1:27 ` netdev-bot+sashiko
2026-12-03 11:55 ` [PATCH can-next v5 09/24] can: isotp: add N_Ar timeout monitoring for FC Oliver Hartkopp
2026-12-03 14:30 ` sashiko-bot
2026-12-05 1:27 ` netdev-bot+sashiko
2026-12-03 11:56 ` [PATCH can-next v5 10/24] can: isotp: check the CAN FD tx_flags in CAN_ISOTP_LL_OPTS Oliver Hartkopp
2026-12-03 14:50 ` sashiko-bot
2026-12-05 1:27 ` netdev-bot+sashiko [this message]
2026-12-03 11:56 ` [PATCH can-next v5 11/24] can: isotp: reject reserved STmin values in CAN_ISOTP_RECV_FC Oliver Hartkopp
2026-12-03 11:56 ` [PATCH can-next v5 12/24] can: isotp: ignore CAN_ISOTP_CHK_PAD_DATA without CAN_ISOTP_RX_PADDING Oliver Hartkopp
2026-12-03 11:56 ` [PATCH can-next v5 13/24] can: isotp: drop frames without N_PCI Oliver Hartkopp
2026-12-03 11:56 ` [PATCH can-next v5 14/24] can: isotp: drop FF frames with invalid length extension Oliver Hartkopp
2026-12-03 11:56 ` [PATCH can-next v5 15/24] can: isotp: check the minimum FF_DL Oliver Hartkopp
2026-12-03 11:56 ` [PATCH can-next v5 16/24] can: isotp: check the data length of the last CF Oliver Hartkopp
2026-12-03 11:56 ` [PATCH can-next v5 17/24] can: isotp: drop inline keyword, let the compiler decide Oliver Hartkopp
2026-12-03 11:56 ` [PATCH can-next v5 18/24] can: isotp: rename rx_lock as it has become state machine lock Oliver Hartkopp
2026-12-05 1:27 ` netdev-bot+sashiko
2026-12-03 11:56 ` [PATCH can-next v5 19/24] can: isotp: introduce isotp_invalid_canid() to verify proper CAN-IDs Oliver Hartkopp
2026-12-03 11:56 ` [PATCH can-next v5 20/24] can: isotp: rename variable for the required content length Oliver Hartkopp
2026-12-03 11:56 ` [PATCH can-next v5 21/24] can: isotp: rename checkpad functions returning bool values Oliver Hartkopp
2026-12-03 11:56 ` [PATCH can-next v5 22/24] can: isotp: change return type of functions to void Oliver Hartkopp
2026-12-03 11:56 ` [PATCH can-next v5 23/24] can: isotp: rename pointer in isotp_rcv() prototype Oliver Hartkopp
2026-12-03 11:56 ` [PATCH can-next v5 24/24] can: isotp: introduce CAN_ISOTP_MIN_TX_DL 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=179643404216.3142.8251952005737867211@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-can@vger.kernel.org \
--cc=mkl@pengutronix.de \
--cc=socketcan@hartkopp.net \
/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