Linux CAN drivers development
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: socketcan@hartkopp.net
Cc: linux-can@vger.kernel.org, mkl@pengutronix.de,
	sashiko-bot@kernel.org, zihanx@nebusec.ai,
	o.rempel@pengutronix.de, yewentian395@gmail.com, kuba@kernel.org
Subject: Re: [PATCH can-next v4 09/23] can: isotp: check the CAN FD tx_flags in CAN_ISOTP_LL_OPTS
Date: Thu, 03 Dec 2026 06:15:30 +0000	[thread overview]
Message-ID: <179627853066.3142.11128687057743464854@kernel.org> (raw)
In-Reply-To: <20261201-getsockopt-memcg-isotp-v4-9-97261be8e38e@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] In isotp_setsockopt_locked() (net/can/isotp.c), CANFD_FDF is
  now ORed into the stored so->ll.tx_flags whenever ll.mtu == CANFD_MTU.
- [Low] The comment this patch adds to the tx_flags field of struct
  can_isotp_ll_options in include/uapi/linux/can/isotp.h reads 'only…

--

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 every other bit with -EINVAL. It
also ORs CANFD_FDF into the stored tx_flags for CAN FD, so getsockopt()
returns the flags of the created CAN FD frames. The isotp.h and
iso15765-2.rst documentation is updated to match.

[ ... ]

> 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 */
> +				/* CANFD_FDF is always set for CAN FD	*/

[Severity: Low]
This isn't a bug, but should this uAPI comment also mention the mtu
dependency?

isotp_setsockopt_locked() only accepts these bits when mtu == CANFD_MTU.
With mtu == CAN_MTU any non-zero tx_flags still fails:

	if (ll->mtu == CAN_MTU &&
	    (ll->tx_dl > CAN_MAX_DLEN || ll->tx_flags != 0))
		return -EINVAL;

So a call like setsockopt(CAN_ISOTP_LL_OPTS, {mtu=CAN_MTU, tx_dl=8,
tx_flags=CANFD_BRS}) returns -EINVAL, although the header says CANFD_BRS
is allowed.

The iso15765-2.rst text added by this patch gets it right ("has to be 0
for classical CAN frames"). Only the exported header leaves that out.

>  				/* Obsolete when the BRS flag is fixed	*/
>  				/* by the CAN netdriver configuration	*/
>  };
> diff --git a/net/can/isotp.c b/net/can/isotp.c
> index aa7bfed15500e..992e8d016e9d4 100644
> --- a/net/can/isotp.c
> +++ b/net/can/isotp.c
> @@ -1796,8 +1796,17 @@ static int isotp_setsockopt_locked(struct socket *sock, int optname,
>  		    (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;

[Severity: Medium]
Can this break a get/modify/set of the LL options when switching back
to classical CAN?

isotp_getsockopt() returns the stored options unchanged:

	case CAN_ISOTP_LL_OPTS:
		len = min_t(int, len, sizeof(struct can_isotp_ll_options));
		val.ll = so->ll;

Userspace now sees CANFD_FDF in tx_flags even when it never set that
bit. Take this sequence on an unbound socket:

  setsockopt(CAN_ISOTP_LL_OPTS, {mtu=CANFD_MTU, tx_dl=8, tx_flags=0})
  getsockopt(CAN_ISOTP_LL_OPTS)    -> tx_flags == CANFD_FDF
  set mtu = CAN_MTU in the returned struct
  setsockopt(CAN_ISOTP_LL_OPTS)    -> -EINVAL

The last call hits the unchanged CAN_MTU check above:

	if (ll->mtu == CAN_MTU &&
	    (ll->tx_dl > CAN_MAX_DLEN || ll->tx_flags != 0))
		return -EINVAL;

Before this patch, getsockopt() returned exactly what was written
(tx_flags=0), so the same sequence worked. Every step happens before
bind, and ISO-TP sockets need no capability.

The commit message says getsockopt() now returns "the flags of the
created CAN FD frames" and that "The CAN frames on the bus are not
changed by this". It doesn't say that this round trip can now be
rejected.

The CAN core already sets the marker at send time in af_can.c:

	cfd->flags |= CANFD_FDF;

So keeping CANFD_FDF out of the stored so->ll.tx_flags would not change
any frame on the bus.

The same code is still there at the end of the series, after "can:
isotp: introduce CAN_ISOTP_MIN_TX_DL".

> +
>  		/* set ll_dl for tx path to similar place as for rx */
>  		so->tx.ll_dl = ll->tx_dl;
>  		break;

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261201-getsockopt-memcg-isotp-v4-0-97261be8e38e%40hartkopp.net

  reply	other threads:[~2026-12-03  6:15 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 16:51 [PATCH can-next v4 00/23] can: memcg accounting, CAN_ISOTP fixes and cleanups Oliver Hartkopp
2026-12-01 16:51 ` [PATCH can-next v4 01/23] can: raw: read socket options under conf_lock in raw_getsockopt() Oliver Hartkopp
2026-12-01 16:51 ` [PATCH can-next v4 02/23] can: isotp: read socket options under conf_lock in isotp_getsockopt() Oliver Hartkopp
2026-12-01 16:51 ` [PATCH can-next v4 03/23] can: enable memcg accounting for user triggered allocations Oliver Hartkopp
2026-12-03  6:15   ` netdev-bot+sashiko
2026-12-01 16:51 ` [PATCH can-next v4 04/23] can: isotp: do not send FC.OVFLW in listen mode Oliver Hartkopp
2026-12-01 16:51 ` [PATCH can-next v4 05/23] can: isotp: check the CAN_ISOTP_OPTS values before applying them Oliver Hartkopp
2026-12-01 16:51 ` [PATCH can-next v4 06/23] can: isotp: add the frame transmission time to the CF broadcast gap Oliver Hartkopp
2026-12-03  6:15   ` netdev-bot+sashiko
2026-12-01 16:51 ` [PATCH can-next v4 07/23] can: isotp: add the frame transmission time to the protocol timeouts Oliver Hartkopp
2026-12-03  6:15   ` netdev-bot+sashiko
2026-12-01 16:51 ` [PATCH can-next v4 08/23] can: isotp: use the N_As timeout for the local echo Oliver Hartkopp
2026-12-03  6:15   ` netdev-bot+sashiko
2026-12-01 16:51 ` [PATCH can-next v4 09/23] can: isotp: check the CAN FD tx_flags in CAN_ISOTP_LL_OPTS Oliver Hartkopp
2026-12-03  6:15   ` netdev-bot+sashiko [this message]
2026-12-01 16:51 ` [PATCH can-next v4 10/23] can: isotp: reject reserved STmin values in CAN_ISOTP_RECV_FC Oliver Hartkopp
2026-12-01 16:51 ` [PATCH can-next v4 11/23] can: isotp: ignore CAN_ISOTP_CHK_PAD_DATA without CAN_ISOTP_RX_PADDING Oliver Hartkopp
2026-12-01 16:51 ` [PATCH can-next v4 12/23] can: isotp: drop frames without N_PCI Oliver Hartkopp
2026-12-01 16:51 ` [PATCH can-next v4 13/23] can: isotp: drop FF frames with invalid length extension Oliver Hartkopp
2026-12-01 16:51 ` [PATCH can-next v4 14/23] can: isotp: check the minimum FF_DL Oliver Hartkopp
2026-12-01 16:51 ` [PATCH can-next v4 15/23] can: isotp: check the data length of the last CF Oliver Hartkopp
2026-12-01 16:51 ` [PATCH can-next v4 16/23] can: isotp: drop inline keyword, let the compiler decide Oliver Hartkopp
2026-12-01 16:51 ` [PATCH can-next v4 17/23] can: isotp: rename rx_lock as it has become state machine lock Oliver Hartkopp
2026-12-03  6:15   ` netdev-bot+sashiko
2026-12-01 16:51 ` [PATCH can-next v4 18/23] can: isotp: introduce isotp_invalid_canid() to verify proper CAN-IDs Oliver Hartkopp
2026-12-01 16:51 ` [PATCH can-next v4 19/23] can: isotp: rename variable for the required content length Oliver Hartkopp
2026-12-01 16:51 ` [PATCH can-next v4 20/23] can: isotp: rename checkpad functions returning bool values Oliver Hartkopp
2026-12-01 16:51 ` [PATCH can-next v4 21/23] can: isotp: change return type of functions to void Oliver Hartkopp
2026-12-01 16:51 ` [PATCH can-next v4 22/23] can: isotp: rename pointer in isotp_rcv() prototype Oliver Hartkopp
2026-12-01 16:51 ` [PATCH can-next v4 23/23] 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=179627853066.3142.11128687057743464854@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-can@vger.kernel.org \
    --cc=mkl@pengutronix.de \
    --cc=o.rempel@pengutronix.de \
    --cc=sashiko-bot@kernel.org \
    --cc=socketcan@hartkopp.net \
    --cc=yewentian395@gmail.com \
    --cc=zihanx@nebusec.ai \
    /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