From: Marc Kleine-Budde <mkl@pengutronix.de>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, kuba@kernel.org, linux-can@vger.kernel.org,
kernel@pengutronix.de, Zhu Ling <zhuling0805@qq.com>,
stable@vger.kernel.org, Oliver Hartkopp <socketcan@hartkopp.net>,
Marc Kleine-Budde <mkl@pengutronix.de>
Subject: [PATCH net 08/12] can: netlink: fix static FD-NON-ISO mode validation
Date: Tue, 24 Nov 2026 09:51:35 +0100 [thread overview]
Message-ID: <20261124085757.1093632-9-mkl@pengutronix.de> (raw)
In-Reply-To: <20261124085757.1093632-1-mkl@pengutronix.de>
From: Zhu Ling <zhuling0805@qq.com>
Controllers with a static CAN_CTRLMODE_FD_NON_ISO mode (M_CAN v3.0.x and
v3.1.x, PEAK pcan_usb_fd with firmware < 2.x) do not require the
'fd-non-iso' option to be provided when CAN FD is not switched on by the
IFLA_CAN_CTRLMODE request.
Since commit 6742ca18cb41 ("can: netlink: add userland error messages")
ctrlstatic_missing is calculated before this exception is applied to
ctrlstatic, which is not evaluated afterwards. As a result every
IFLA_CAN_CTRLMODE request on such controllers that does not contain
'fd-non-iso on' is rejected with -EOPNOTSUPP and "missing required
FD-NON-ISO static control mode", e.g. 'fd off', 'loopback on' or
'one-shot on', regardless of the current CAN FD state.
Apply the exception to ctrlstatic_missing instead.
The exception must only relax the requirement to *provide* the static
FD-NON-ISO mode. It must not allow to *switch off* a static mode: before
the above mentioned commit a request like 'fd-non-iso off' passed the
check and removed the static CAN_CTRLMODE_FD_NON_ISO bit from
priv->ctrlmode. As can_get_static_ctrlmode() derives the static modes
from priv->ctrlmode, this information was lost permanently. Therefore
reject any request that explicitly switches off a static control mode
with a dedicated error message. With this check in place a static mode
can never be cleared by the 'priv->ctrlmode &= ~cm->mask' operation as
every static bit in cm->mask is also set in maskedflags.
The request is rejected independent of the resulting CAN FD state, as
accepting it while CAN FD is switched off would remove the static mode
from priv->ctrlmode as well.
Older kernels without the above mentioned commit do not need this fix.
They can lose the static FD-NON-ISO mode by an explicit 'fd-non-iso off'
too, but this only changes the reported control mode while the hardware
keeps using non-ISO CAN FD.
[Hartkopp: reject switching off static control modes instead of restoring
them, extend the commit message (Sashiko review)]
Fixes: 6742ca18cb41 ("can: netlink: add userland error messages")
Cc: stable@vger.kernel.org
Signed-off-by: Zhu Ling <zhuling0805@qq.com>
Link: https://lore.kernel.org/all/tencent_3A964832542399A780E646D6A6246335C409@qq.com/
Link: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261115095746.709371-1-mkl%40pengutronix.de
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
Link: https://patch.msgid.link/20261120-can-bcmlock-memcg-v7-8-f6b84f5257b1@hartkopp.net
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/dev/netlink.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/drivers/net/can/dev/netlink.c b/drivers/net/can/dev/netlink.c
index 081dfddda000..521e2496e2cc 100644
--- a/drivers/net/can/dev/netlink.c
+++ b/drivers/net/can/dev/netlink.c
@@ -330,9 +330,17 @@ static int can_ctrlmode_changelink(struct net_device *dev,
return -EOPNOTSUPP;
}
+ /* static control modes can not be switched off */
+ if (deactivated & ctrlstatic) {
+ NL_SET_ERR_MSG_FMT(extack,
+ "static control mode %s can not be switched off",
+ can_get_ctrlmode_str(deactivated & ctrlstatic));
+ return -EOPNOTSUPP;
+ }
+
/* do not check for static fd-non-iso if 'fd' is disabled */
if (!(maskedflags & CAN_CTRLMODE_FD))
- ctrlstatic &= ~CAN_CTRLMODE_FD_NON_ISO;
+ ctrlstatic_missing &= ~CAN_CTRLMODE_FD_NON_ISO;
if (ctrlstatic_missing) {
NL_SET_ERR_MSG_FMT(extack,
--
2.53.0
next prev parent reply other threads:[~2026-11-24 8:58 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 8:51 [PATCH net 0/12] pull-request: can 2026-11-24 Marc Kleine-Budde
2026-11-24 8:51 ` [PATCH net 01/12] can: bcm: copy the CAN frames outside of lock_sock() Marc Kleine-Budde
2026-11-24 9:04 ` netdev-bot+sinfo
2026-11-24 8:51 ` [PATCH net 02/12] can: bcm: do not remove the procfs entry in bcm_notify() Marc Kleine-Budde
2026-11-24 8:51 ` [PATCH net 03/12] can: raw: use a private mutex instead of lock_sock() Marc Kleine-Budde
2026-11-24 8:51 ` [PATCH net 04/12] can: isotp: " Marc Kleine-Budde
2026-11-24 8:51 ` [PATCH net 05/12] can: bcm: " Marc Kleine-Budde
2026-11-24 8:51 ` [PATCH net 06/12] can: isotp: always start the rx timeout in ISOTP_WAIT_DATA state Marc Kleine-Budde
2026-11-24 8:51 ` [PATCH net 07/12] can: isotp: reject socket options while a transfer is active Marc Kleine-Budde
2026-11-24 8:51 ` Marc Kleine-Budde [this message]
2026-11-24 8:51 ` [PATCH net 09/12] can: netlink: fix IFLA_CAN_BITRATE_MAX attribute sizing Marc Kleine-Budde
2026-11-24 8:51 ` [PATCH net 10/12] can: netlink: fix CAN XL PWM " Marc Kleine-Budde
2026-11-24 8:51 ` [PATCH net 11/12] can: gs_usb: gs_can_start_xmit(): don't leak uninitialized memory over USB Marc Kleine-Budde
2026-11-24 8:51 ` [PATCH net 12/12] can: flexcan: Fix probing for m68k/coldfire Marc Kleine-Budde
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=20261124085757.1093632-9-mkl@pengutronix.de \
--to=mkl@pengutronix.de \
--cc=davem@davemloft.net \
--cc=kernel@pengutronix.de \
--cc=kuba@kernel.org \
--cc=linux-can@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=socketcan@hartkopp.net \
--cc=stable@vger.kernel.org \
--cc=zhuling0805@qq.com \
/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