* [PATCH can-next 01/22] can: raw: read socket options under conf_lock in raw_getsockopt()
2026-11-26 21:05 [PATCH can-next 00/22] can: memcg accounting, CAN_ISOTP fixes and cleanups Oliver Hartkopp
@ 2026-11-26 21:05 ` Oliver Hartkopp
2026-11-26 21:05 ` [PATCH can-next 02/22] can: isotp: read socket options under conf_lock in isotp_getsockopt() Oliver Hartkopp
` (21 subsequent siblings)
22 siblings, 0 replies; 38+ messages in thread
From: Oliver Hartkopp @ 2026-11-26 21:05 UTC (permalink / raw)
To: linux-can; +Cc: Marc Kleine-Budde, Oliver Hartkopp
raw_getsockopt() only takes conf_lock for CAN_RAW_FILTER. All other
CAN_RAW socket options are read without the mutex, while
raw_setsockopt() updates them under conf_lock. CAN_RAW_XL_VCID_OPTS is
even copied to user space directly from the socket, so a concurrent
setsockopt() can lead to a mix of old and new values.
Read the option values under conf_lock into a local variable and copy
them to user space after mutex_unlock(), like raw_setsockopt() does it
in the other direction. So no user space access happens while the
mutex is held and a stalled copy can not block raw_notify() under RTNL.
CAN_RAW_FILTER is handled in front of the switch statement, as it takes
the mutex on its own for the duplication of the filters. Its code is
not changed.
The socket options have been read without a lock before commit
"can: raw: use a private mutex instead of lock_sock()" as well, so this
is no fix. As the only visible change, a failing copy to user space for
CAN_RAW_XL_VCID_OPTS now returns the clamped option length together
with -EFAULT, like the other socket options.
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
---
net/can/raw.c | 64 ++++++++++++++++++++++++++++++-----------------------------
1 file changed, 33 insertions(+), 31 deletions(-)
diff --git a/net/can/raw.c b/net/can/raw.c
index b69eaadc5e93..cf1770432dad 100644
--- a/net/can/raw.c
+++ b/net/can/raw.c
@@ -101,11 +101,11 @@ struct raw_sock {
can_err_mask_t err_mask;
int count; /* number of active filters */
struct can_filter dfilter; /* default/single filter */
struct can_filter *filter; /* pointer to filter(s) */
struct uniqframe __percpu *uniq;
- struct mutex conf_lock; /* protects bind, filters and setsockopt */
+ struct mutex conf_lock; /* protects bind, filters and sockopts */
};
static LIST_HEAD(raw_notifier_list);
static DEFINE_SPINLOCK(raw_notifier_lock);
static struct raw_sock *raw_busy_notifier;
@@ -817,24 +817,26 @@ static int raw_setsockopt(struct socket *sock, int level, int optname,
static int raw_getsockopt(struct socket *sock, int level, int optname,
sockopt_t *opt)
{
struct sock *sk = sock->sk;
struct raw_sock *ro = raw_sk(sk);
- int flag;
+ union {
+ can_err_mask_t err_mask;
+ int flag;
+ struct can_raw_vcid_options vcid_opts;
+ } val;
int len;
- void *val;
+ int err = 0;
if (level != SOL_CAN_RAW)
return -EINVAL;
len = opt->optlen;
if (len < 0)
return -EINVAL;
- switch (optname) {
- case CAN_RAW_FILTER: {
+ if (optname == CAN_RAW_FILTER) {
struct can_filter *filter = NULL;
- int err = 0;
mutex_lock(&ro->conf_lock);
if (ro->count > 0) {
int fsize = ro->count * sizeof(struct can_filter);
@@ -864,76 +866,76 @@ static int raw_getsockopt(struct socket *sock, int level, int optname,
if (!err)
opt->optlen = len;
return err;
}
+
+ /* Read the option value under ro->conf_lock and copy it to user
+ * space after mutex_unlock(), see raw_setsockopt().
+ */
+ mutex_lock(&ro->conf_lock);
+
+ switch (optname) {
case CAN_RAW_ERR_FILTER:
if (len > sizeof(can_err_mask_t))
len = sizeof(can_err_mask_t);
- val = &ro->err_mask;
+ val.err_mask = ro->err_mask;
break;
case CAN_RAW_LOOPBACK:
if (len > sizeof(int))
len = sizeof(int);
- flag = ro->loopback;
- val = &flag;
+ val.flag = ro->loopback;
break;
case CAN_RAW_RECV_OWN_MSGS:
if (len > sizeof(int))
len = sizeof(int);
- flag = ro->recv_own_msgs;
- val = &flag;
+ val.flag = ro->recv_own_msgs;
break;
case CAN_RAW_FD_FRAMES:
if (len > sizeof(int))
len = sizeof(int);
- flag = ro->fd_frames;
- val = &flag;
+ val.flag = ro->fd_frames;
break;
case CAN_RAW_XL_FRAMES:
if (len > sizeof(int))
len = sizeof(int);
- flag = ro->xl_frames;
- val = &flag;
+ val.flag = ro->xl_frames;
break;
- case CAN_RAW_XL_VCID_OPTS: {
- int err = 0;
-
+ case CAN_RAW_XL_VCID_OPTS:
/* user space buffer to small for VCID opts? */
if (len < sizeof(ro->raw_vcid_opts)) {
/* return -ERANGE and needed space in optlen */
err = -ERANGE;
opt->optlen = sizeof(ro->raw_vcid_opts);
} else {
- if (len > sizeof(ro->raw_vcid_opts))
- len = sizeof(ro->raw_vcid_opts);
- if (copy_to_iter(&ro->raw_vcid_opts, len,
- &opt->iter_out) != len)
- err = -EFAULT;
+ len = sizeof(ro->raw_vcid_opts);
+ val.vcid_opts = ro->raw_vcid_opts;
}
- if (!err)
- opt->optlen = len;
- return err;
- }
+ break;
+
case CAN_RAW_JOIN_FILTERS:
if (len > sizeof(int))
len = sizeof(int);
- flag = ro->join_filters;
- val = &flag;
+ val.flag = ro->join_filters;
break;
default:
- return -ENOPROTOOPT;
+ err = -ENOPROTOOPT;
}
+ mutex_unlock(&ro->conf_lock);
+
+ if (err)
+ return err;
+
opt->optlen = len;
- if (copy_to_iter(val, len, &opt->iter_out) != len)
+ if (copy_to_iter(&val, len, &opt->iter_out) != len)
return -EFAULT;
return 0;
}
static void raw_put_canxl_vcid(struct raw_sock *ro, struct sk_buff *skb)
--
2.53.0
^ permalink raw reply related [flat|nested] 38+ messages in thread* [PATCH can-next 02/22] can: isotp: read socket options under conf_lock in isotp_getsockopt()
2026-11-26 21:05 [PATCH can-next 00/22] can: memcg accounting, CAN_ISOTP fixes and cleanups Oliver Hartkopp
2026-11-26 21:05 ` [PATCH can-next 01/22] can: raw: read socket options under conf_lock in raw_getsockopt() Oliver Hartkopp
@ 2026-11-26 21:05 ` Oliver Hartkopp
2026-11-26 21:05 ` [PATCH can-next 03/22] can: enable memcg accounting for user triggered allocations Oliver Hartkopp
` (20 subsequent siblings)
22 siblings, 0 replies; 38+ messages in thread
From: Oliver Hartkopp @ 2026-11-26 21:05 UTC (permalink / raw)
To: linux-can; +Cc: Marc Kleine-Budde, Oliver Hartkopp
isotp_getsockopt() copies the CAN_ISOTP socket options to user space
directly from the socket without taking conf_lock, while
isotp_setsockopt() updates them under conf_lock. For the options that
consist of several values, i.e. CAN_ISOTP_OPTS, CAN_ISOTP_RECV_FC and
CAN_ISOTP_LL_OPTS, a concurrent setsockopt() can lead to a mix of old
and new values.
Read the option values under conf_lock into a local variable and copy
them to user space after mutex_unlock(), like isotp_setsockopt() does
it in the other direction. So no user space access happens while the
mutex is held and a stalled copy can not block isotp_notify() under
RTNL.
The socket options have been read without a lock before commit
"can: isotp: use a private mutex instead of lock_sock()" as well, so
this is no fix.
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
---
net/can/isotp.c | 34 +++++++++++++++++++++++++---------
1 file changed, 25 insertions(+), 9 deletions(-)
diff --git a/net/can/isotp.c b/net/can/isotp.c
index 642fec500af9..98a7e489ca3e 100644
--- a/net/can/isotp.c
+++ b/net/can/isotp.c
@@ -180,11 +180,11 @@ struct isotp_sock {
u32 tx_result[ISOTP_TX_RESULT_SLOTS]; /* per-generation result slots */
struct tpcon rx, tx;
struct list_head notifier;
wait_queue_head_t wait;
spinlock_t rx_lock; /* protect single thread state machine */
- struct mutex conf_lock; /* protects bind and setsockopt */
+ struct mutex conf_lock; /* protects bind and sockopts */
};
static LIST_HEAD(isotp_notifier_list);
static DEFINE_SPINLOCK(isotp_notifier_lock);
static struct isotp_sock *isotp_busy_notifier;
@@ -1860,53 +1860,69 @@ static int isotp_setsockopt(struct socket *sock, int level, int optname,
static int isotp_getsockopt(struct socket *sock, int level, int optname,
char __user *optval, int __user *optlen)
{
struct sock *sk = sock->sk;
struct isotp_sock *so = isotp_sk(sk);
+ union {
+ struct can_isotp_options opt;
+ struct can_isotp_fc_options rxfc;
+ struct can_isotp_ll_options ll;
+ u32 stmin;
+ } val;
int len;
- void *val;
+ int err = 0;
if (level != SOL_CAN_ISOTP)
return -EINVAL;
if (get_user(len, optlen))
return -EFAULT;
if (len < 0)
return -EINVAL;
+ /* Read the option value under so->conf_lock and copy it to user
+ * space after mutex_unlock(), see isotp_setsockopt().
+ */
+ mutex_lock(&so->conf_lock);
+
switch (optname) {
case CAN_ISOTP_OPTS:
len = min_t(int, len, sizeof(struct can_isotp_options));
- val = &so->opt;
+ val.opt = so->opt;
break;
case CAN_ISOTP_RECV_FC:
len = min_t(int, len, sizeof(struct can_isotp_fc_options));
- val = &so->rxfc;
+ val.rxfc = so->rxfc;
break;
case CAN_ISOTP_TX_STMIN:
len = min_t(int, len, sizeof(u32));
- val = &so->force_tx_stmin;
+ val.stmin = so->force_tx_stmin;
break;
case CAN_ISOTP_RX_STMIN:
len = min_t(int, len, sizeof(u32));
- val = &so->force_rx_stmin;
+ val.stmin = so->force_rx_stmin;
break;
case CAN_ISOTP_LL_OPTS:
len = min_t(int, len, sizeof(struct can_isotp_ll_options));
- val = &so->ll;
+ val.ll = so->ll;
break;
default:
- return -ENOPROTOOPT;
+ err = -ENOPROTOOPT;
}
+ mutex_unlock(&so->conf_lock);
+
+ if (err)
+ return err;
+
if (put_user(len, optlen))
return -EFAULT;
- if (copy_to_user(optval, val, len))
+ if (copy_to_user(optval, &val, len))
return -EFAULT;
return 0;
}
static void isotp_notify(struct isotp_sock *so, unsigned long msg,
--
2.53.0
^ permalink raw reply related [flat|nested] 38+ messages in thread* [PATCH can-next 03/22] can: enable memcg accounting for user triggered allocations
2026-11-26 21:05 [PATCH can-next 00/22] can: memcg accounting, CAN_ISOTP fixes and cleanups Oliver Hartkopp
2026-11-26 21:05 ` [PATCH can-next 01/22] can: raw: read socket options under conf_lock in raw_getsockopt() Oliver Hartkopp
2026-11-26 21:05 ` [PATCH can-next 02/22] can: isotp: read socket options under conf_lock in isotp_getsockopt() Oliver Hartkopp
@ 2026-11-26 21:05 ` Oliver Hartkopp
2026-11-27 10:08 ` Oliver Hartkopp
2026-11-26 21:05 ` [PATCH can-next 04/22] can: isotp: check the CAN_ISOTP_OPTS values before applying them Oliver Hartkopp
` (19 subsequent siblings)
22 siblings, 1 reply; 38+ messages in thread
From: Oliver Hartkopp @ 2026-11-26 21:05 UTC (permalink / raw)
To: linux-can
Cc: Marc Kleine-Budde, Sashiko, Zihan Xi, Oleksij Rempel,
Oliver Hartkopp
Unprivileged users can create CAN sockets and trigger allocations that
stay in the kernel for the lifetime of the socket or of the related
objects. E.g. each CAN_BCM RX_SETUP for a new CAN ID creates a bcm_op
with optional frame arrays of up to 257 CAN FD frames and a CAN
receiver, without requiring a CAN device (ifindex 0) and without a
limit for the number of ops per socket.
None of these allocations are accounted to the memory cgroup of the
process that triggers them. So a process can bypass the memory limit
of its cgroup, e.g. of a container or a systemd service, and exhaust
the memory of the whole system. The OOM killer can not attribute this
kernel memory to the responsible process either, which has nearly no
RSS, and terminates unrelated processes instead.
Enable memcg accounting for these allocations, as it has been done for
other objects that can be created by unprivileged users. This does not
introduce any new CAN specific limit and does not make assumptions
about the number of sockets, filters or BCM operations an application
needs. The CAN related kernel memory is just charged to the cgroup of
the allocating process, so that the memory limits which are already
configured for this cgroup apply to it as well. Without a configured
limit the behaviour is unchanged.
A per socket limit for the number or the memory of the BCM operations,
as suggested in the reports, does not bound the memory consumption, as
a process can open many sockets and fork. Hard-coded limits can also
break existing applications, e.g. one that monitors all 2048 SFF CAN
IDs with individual RX operations, without a possibility to adjust
them.
The following allocations are accounted:
- af_can: the CAN socket structures (e.g. struct isotp_sock contains
two DEFAULT_MAX_PDU_SIZE buffers), the CAN receivers of all CAN
protocols and the per-netns receive lists and statistics
- bcm: the bcm_op structures and their frames/last_frames arrays
- raw: the per-cpu uniq data and the CAN_RAW_FILTER filters
- isotp: the TX buffer for PDUs > DEFAULT_MAX_PDU_SIZE
- j1939: the SO_J1939_FILTER filters and the per device j1939_priv,
which is created by the first bind() to a CAN device
The CAN socket structures are allocated with GFP_KERNEL_ACCOUNT in
sk_alloc() instead of creating dedicated slab caches with
proto_register(), as the CAN protocols copy socket options directly
from their socket structures to user space, which would require
usercopy whitelists for these caches.
memdup_sockptr() does not support memcg accounting, so the filters are
allocated with the GFP_USER | __GFP_NOWARN flags of memdup_sockptr()
plus __GFP_ACCOUNT and copied explicitly.
The isotp RX buffer for PDUs > DEFAULT_MAX_PDU_SIZE is allocated in
softirq context and is not accounted. It could be charged to the memory
cgroup of the socket with set_active_memcg(), but a charge in atomic
context can not reclaim memory. With GFP_ATOMIC the charge is forced,
which allows a cgroup to exceed its limit by up to max_pdu_size per
socket. Without __GFP_HIGH the allocation fails at the limit, so the
reception of the PDU fails, and it loses the access to the atomic
reserves on systems without a memory limit as well. This buffer is only
used when the administrator has increased the max_pdu_size module
parameter. The j1939 RX sessions are allocated in softirq context
before a socket is involved and can not be attributed to a process.
The j1939 TX sessions only exist for the duration of a transfer and the
can-gw jobs require CAP_NET_ADMIN in the initial user namespace, so
they are not changed. The local j1939 ECUs created by bind() are
allocated with BH disabled and their number is limited by the number of
bound j1939 sockets, which are accounted. Temporary buffers that are
freed before the syscall returns are not accounted either.
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://sashiko.dev/#/patchset/20260707-bcm_fixes-v5-0-c3c74f8d8ff7@hartkopp.net
Reported-by: Zihan Xi <zihanx@nebusec.ai>
Closes: https://lore.kernel.org/linux-can/cover.1793089479.git.zihanx@nebusec.ai/
Link: https://lore.kernel.org/linux-can/350df96b-5f69-490e-b39e-ed6e9bca4754@hartkopp.net/
Cc: Oleksij Rempel <o.rempel@pengutronix.de>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
---
net/can/af_can.c | 12 +++++++-----
net/can/bcm.c | 10 +++++-----
net/can/isotp.c | 9 +++++++--
net/can/j1939/main.c | 2 +-
net/can/j1939/socket.c | 12 +++++++++---
net/can/raw.c | 14 ++++++++++----
6 files changed, 39 insertions(+), 20 deletions(-)
diff --git a/net/can/af_can.c b/net/can/af_can.c
index 0f3051a61aab..6f958c2bb49d 100644
--- a/net/can/af_can.c
+++ b/net/can/af_can.c
@@ -153,11 +153,11 @@ static int can_create(struct net *net, struct socket *sock, int protocol,
goto errout;
}
sock->ops = cp->ops;
- sk = sk_alloc(net, PF_CAN, GFP_KERNEL, cp->prot, kern);
+ sk = sk_alloc(net, PF_CAN, GFP_KERNEL_ACCOUNT, cp->prot, kern);
if (!sk) {
err = -ENOMEM;
goto errout;
}
@@ -828,18 +828,20 @@ void can_proto_unregister(const struct can_proto *cp)
EXPORT_SYMBOL(can_proto_unregister);
static int can_pernet_init(struct net *net)
{
spin_lock_init(&net->can.rcvlists_lock);
- net->can.rx_alldev_list = kzalloc_obj(*net->can.rx_alldev_list);
+ net->can.rx_alldev_list = kzalloc_obj(*net->can.rx_alldev_list,
+ GFP_KERNEL_ACCOUNT);
if (!net->can.rx_alldev_list)
goto out;
spin_lock_init(&net->can.rx_alldev_list->lock);
- net->can.pkg_stats = kzalloc_obj(*net->can.pkg_stats);
+ net->can.pkg_stats = kzalloc_obj(*net->can.pkg_stats, GFP_KERNEL_ACCOUNT);
if (!net->can.pkg_stats)
goto out_free_rx_alldev_list;
- net->can.rcv_lists_stats = kzalloc_obj(*net->can.rcv_lists_stats);
+ net->can.rcv_lists_stats = kzalloc_obj(*net->can.rcv_lists_stats,
+ GFP_KERNEL_ACCOUNT);
if (!net->can.rcv_lists_stats)
goto out_free_pkg_stats;
if (IS_ENABLED(CONFIG_PROC_FS)) {
/* the statistics are updated every second (timer triggered) */
@@ -917,11 +919,11 @@ static __init int can_init(void)
offsetof(struct canfd_frame, data));
pr_info("can: controller area network core\n");
rcv_cache = kmem_cache_create("can_receiver", sizeof(struct receiver),
- 0, 0, NULL);
+ 0, SLAB_ACCOUNT, NULL);
if (!rcv_cache)
return -ENOMEM;
err = register_pernet_subsys(&can_pernet_ops);
if (err)
diff --git a/net/can/bcm.c b/net/can/bcm.c
index dc9e2890490a..f3d93a203071 100644
--- a/net/can/bcm.c
+++ b/net/can/bcm.c
@@ -1159,11 +1159,11 @@ static int bcm_tx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,
kfree(new_frames);
} else {
/* insert new BCM operation for the given can_id */
- op = kzalloc(OPSIZ, GFP_KERNEL);
+ op = kzalloc(OPSIZ, GFP_KERNEL_ACCOUNT);
if (!op)
return -ENOMEM;
spin_lock_init(&op->bcm_tx_lock);
op->can_id = msg_head->can_id;
@@ -1176,11 +1176,11 @@ static int bcm_tx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,
/* create array for CAN frames and copy the data */
if (msg_head->nframes > 1) {
op->frames = kmalloc_array(msg_head->nframes,
op->cfsiz,
- GFP_KERNEL);
+ GFP_KERNEL_ACCOUNT);
if (!op->frames) {
kfree(op);
return -ENOMEM;
}
} else
@@ -1407,11 +1407,11 @@ static int bcm_rx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,
*/
do_rx_register = (ifindex && !op->rx_reg_dev) ? 1 : 0;
} else {
/* insert new BCM operation for the given can_id */
- op = kzalloc(OPSIZ, GFP_KERNEL);
+ op = kzalloc(OPSIZ, GFP_KERNEL_ACCOUNT);
if (!op)
return -ENOMEM;
spin_lock_init(&op->bcm_tx_lock);
spin_lock_init(&op->bcm_rx_update_lock);
@@ -1422,20 +1422,20 @@ static int bcm_rx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,
if (msg_head->nframes > 1) {
/* create array for CAN frames and copy the data */
op->frames = kmalloc_array(msg_head->nframes,
op->cfsiz,
- GFP_KERNEL);
+ GFP_KERNEL_ACCOUNT);
if (!op->frames) {
kfree(op);
return -ENOMEM;
}
/* create and init array for received CAN frames */
op->last_frames = kcalloc(msg_head->nframes,
op->cfsiz,
- GFP_KERNEL);
+ GFP_KERNEL_ACCOUNT);
if (!op->last_frames) {
kfree(op->frames);
kfree(op);
return -ENOMEM;
}
diff --git a/net/can/isotp.c b/net/can/isotp.c
index 98a7e489ca3e..3b83507a8c21 100644
--- a/net/can/isotp.c
+++ b/net/can/isotp.c
@@ -607,11 +607,16 @@ static int isotp_rcv_ff(struct sock *sk, struct canfd_frame *cf, int ae)
off = (so->rx.ll_dl > CAN_MAX_DLEN) ? 1 : 0;
if (so->rx.len + ae + off + ff_pci_sz < so->rx.ll_dl)
return 1;
- /* PDU size > default => try max_pdu_size */
+ /* PDU size > default => try max_pdu_size
+ *
+ * This buffer is not accounted to a memory cgroup: In softirq
+ * context the charge would either have to be forced beyond the
+ * limit of the cgroup or the reception would fail at the limit.
+ */
if (so->rx.len > so->rx.buflen && so->rx.buflen < max_pdu_size) {
u8 *newbuf = kmalloc(max_pdu_size, GFP_ATOMIC);
if (newbuf) {
so->rx.buf = newbuf;
@@ -1192,11 +1197,11 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
ae = (so->opt.flags & CAN_ISOTP_EXTEND_ADDR) ? 1 : 0;
wait_tx_done = (so->opt.flags & CAN_ISOTP_WAIT_TX_DONE) ? 1 : 0;
/* PDU size > default => try max_pdu_size */
if (size > so->tx.buflen && so->tx.buflen < max_pdu_size) {
- u8 *newbuf = kmalloc(max_pdu_size, GFP_KERNEL);
+ u8 *newbuf = kmalloc(max_pdu_size, GFP_KERNEL_ACCOUNT);
if (newbuf) {
so->tx.buf = newbuf;
so->tx.buflen = max_pdu_size;
}
diff --git a/net/can/j1939/main.c b/net/can/j1939/main.c
index d9384cf0e356..77adb817b36c 100644
--- a/net/can/j1939/main.c
+++ b/net/can/j1939/main.c
@@ -126,11 +126,11 @@ static DEFINE_MUTEX(j1939_netdev_lock);
static struct j1939_priv *j1939_priv_create(struct net_device *ndev)
{
struct j1939_priv *priv;
- priv = kzalloc_obj(*priv);
+ priv = kzalloc_obj(*priv, GFP_KERNEL_ACCOUNT);
if (!priv)
return NULL;
rwlock_init(&priv->lock);
INIT_LIST_HEAD(&priv->ecus);
diff --git a/net/can/j1939/socket.c b/net/can/j1939/socket.c
index 50a598ef5fd4..85b7e8847c06 100644
--- a/net/can/j1939/socket.c
+++ b/net/can/j1939/socket.c
@@ -714,13 +714,19 @@ static int j1939_sk_setsockopt(struct socket *sock, int level, int optname,
if (optlen > J1939_FILTER_MAX *
sizeof(struct j1939_filter))
return -EINVAL;
count = optlen / sizeof(*filters);
- filters = memdup_sockptr(optval, optlen);
- if (IS_ERR(filters))
- return PTR_ERR(filters);
+ filters = kmalloc(optlen, GFP_USER | __GFP_NOWARN |
+ __GFP_ACCOUNT);
+ if (!filters)
+ return -ENOMEM;
+
+ if (copy_from_sockptr(filters, optval, optlen)) {
+ kfree(filters);
+ return -EFAULT;
+ }
for (f = filters, c = count; c; f++, c--) {
f->name &= f->name_mask;
f->pgn &= f->pgn_mask;
f->addr &= f->addr_mask;
diff --git a/net/can/raw.c b/net/can/raw.c
index cf1770432dad..da462e9874f1 100644
--- a/net/can/raw.c
+++ b/net/can/raw.c
@@ -416,11 +416,11 @@ static int raw_init(struct sock *sk)
ro->fd_frames = 0;
ro->xl_frames = 0;
ro->join_filters = 0;
/* alloc_percpu provides zero'ed memory */
- ro->uniq = alloc_percpu(struct uniqframe);
+ ro->uniq = alloc_percpu_gfp(struct uniqframe, GFP_KERNEL_ACCOUNT);
if (unlikely(!ro->uniq))
return -ENOMEM;
sk->sk_destruct = raw_sock_destruct;
@@ -761,13 +761,19 @@ static int raw_setsockopt(struct socket *sock, int level, int optname,
count = optlen / sizeof(struct can_filter);
if (count > 1) {
/* filter does not fit into dfilter => alloc space */
- filter = memdup_sockptr(optval, optlen);
- if (IS_ERR(filter))
- return PTR_ERR(filter);
+ filter = kmalloc(optlen, GFP_USER | __GFP_NOWARN |
+ __GFP_ACCOUNT);
+ if (!filter)
+ return -ENOMEM;
+
+ if (copy_from_sockptr(filter, optval, optlen)) {
+ kfree(filter);
+ return -EFAULT;
+ }
} else if (count == 1) {
if (copy_from_sockptr(&sfilter, optval, sizeof(sfilter)))
return -EFAULT;
filter = &sfilter;
}
--
2.53.0
^ permalink raw reply related [flat|nested] 38+ messages in thread* Re: [PATCH can-next 03/22] can: enable memcg accounting for user triggered allocations
2026-11-26 21:05 ` [PATCH can-next 03/22] can: enable memcg accounting for user triggered allocations Oliver Hartkopp
@ 2026-11-27 10:08 ` Oliver Hartkopp
2026-11-27 11:50 ` Oleksij Rempel
0 siblings, 1 reply; 38+ messages in thread
From: Oliver Hartkopp @ 2026-11-27 10:08 UTC (permalink / raw)
To: Marc Kleine-Budde, Oleksij Rempel; +Cc: linux-can
Hello Marc, hello Oleksij,
On 26.11.26 22:05, Oliver Hartkopp wrote:
>
> The following allocations are accounted:
(..)
> - j1939: the SO_J1939_FILTER filters and the per device j1939_priv,
> which is created by the first bind() to a CAN device
(..)
> net/can/j1939/main.c | 2 +-
> net/can/j1939/socket.c | 12 +++++++++---
This can-next series contains the leftovers of the former fix series
which were not suitable for stable. The memcg accounting is one of them.
The J1939 code is currently changing almost daily due to several fixes,
and some of them will likely go to stable too. Having the memcg changes
in net/can/j1939/ in between might cause additional effort when
backporting these fixes.
Would it make sense to split this patch into a J1939 and a non-J1939
part and to post the J1939 memcg accounting when all J1939 fixes have
hit the mainline tree?
Or would you prefer me to drop the memcg patch entirely from this
series, so that we can address the entire CAN subsystem once the
J1939 fixes are done?
Best regards,
Oliver
^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: [PATCH can-next 03/22] can: enable memcg accounting for user triggered allocations
2026-11-27 10:08 ` Oliver Hartkopp
@ 2026-11-27 11:50 ` Oleksij Rempel
2026-11-27 11:58 ` Oliver Hartkopp
0 siblings, 1 reply; 38+ messages in thread
From: Oleksij Rempel @ 2026-11-27 11:50 UTC (permalink / raw)
To: Oliver Hartkopp; +Cc: Marc Kleine-Budde, linux-can
Hi Oliver,
On Fri, Nov 27, 2026 at 11:08:17AM +0100, Oliver Hartkopp wrote:
> Would it make sense to split this patch into a J1939 and a non-J1939
> part and to post the J1939 memcg accounting when all J1939 fixes have
> hit the mainline tree?
Thank you for thinking about it. As far as I can see, there is no need
to split it. The J1939 part only touches the j1939_priv allocation and
the SO_J1939_FILTER copy, and the pending J1939 fixes I know of do not
touch these lines. If a conflict shows up later, it should be easy to
resolve.
Acked-by: Oleksij Rempel <o.rempel@pengutronix.de>
Regards,
Oleksij
^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: [PATCH can-next 03/22] can: enable memcg accounting for user triggered allocations
2026-11-27 11:50 ` Oleksij Rempel
@ 2026-11-27 11:58 ` Oliver Hartkopp
0 siblings, 0 replies; 38+ messages in thread
From: Oliver Hartkopp @ 2026-11-27 11:58 UTC (permalink / raw)
To: Oleksij Rempel; +Cc: Marc Kleine-Budde, linux-can
On 27.11.26 12:50, Oleksij Rempel wrote:
> On Fri, Nov 27, 2026 at 11:08:17AM +0100, Oliver Hartkopp wrote:
>> Would it make sense to split this patch into a J1939 and a non-J1939
>> part and to post the J1939 memcg accounting when all J1939 fixes have
>> hit the mainline tree?
>
> Thank you for thinking about it. As far as I can see, there is no need
> to split it. The J1939 part only touches the j1939_priv allocation and
> the SO_J1939_FILTER copy, and the pending J1939 fixes I know of do not
> touch these lines. If a conflict shows up later, it should be easy to
> resolve.
>
> Acked-by: Oleksij Rempel <o.rempel@pengutronix.de>
>
Great! Thanks!
So let's see what Sashiko has to grumble whether I need to re-spin ;-)
Best regards,
Oliver
^ permalink raw reply [flat|nested] 38+ messages in thread
* [PATCH can-next 04/22] can: isotp: check the CAN_ISOTP_OPTS values before applying them
2026-11-26 21:05 [PATCH can-next 00/22] can: memcg accounting, CAN_ISOTP fixes and cleanups Oliver Hartkopp
` (2 preceding siblings ...)
2026-11-26 21:05 ` [PATCH can-next 03/22] can: enable memcg accounting for user triggered allocations Oliver Hartkopp
@ 2026-11-26 21:05 ` Oliver Hartkopp
2026-11-26 21:05 ` [PATCH can-next 05/22] can: isotp: add the frame transmission time to the protocol timeouts Oliver Hartkopp
` (18 subsequent siblings)
22 siblings, 0 replies; 38+ messages in thread
From: Oliver Hartkopp @ 2026-11-26 21:05 UTC (permalink / raw)
To: linux-can; +Cc: Marc Kleine-Budde, Oliver Hartkopp
isotp_setsockopt_locked() copies the CAN_ISOTP_OPTS values into so->opt
before it checks them. When CAN_ISOTP_SF_BROADCAST and
CAN_ISOTP_CF_BROADCAST are set together, CAN_ISOTP_CF_BROADCAST is
removed and the remaining options are applied, although -EINVAL is
returned to give user feedback on the wrong configuration.
Since commit "can: isotp: use a private mutex instead of lock_sock()"
the option values are copied from user space into a local buffer before
conf_lock is taken. Check the broadcast flags in this copy and reject an
invalid combination before so->opt is changed. A rejected setsockopt()
now leaves all socket options untouched instead of applying a modified
set of options.
Use hweight32() to check that only one of the broadcast flags is set, so
that further broadcast flags can be added to ISOTP_ALL_BC_FLAGS without
changing the check.
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
---
net/can/isotp.c | 20 +++++++++-----------
1 file changed, 9 insertions(+), 11 deletions(-)
diff --git a/net/can/isotp.c b/net/can/isotp.c
index 3b83507a8c21..7be3d9322ad1 100644
--- a/net/can/isotp.c
+++ b/net/can/isotp.c
@@ -1742,34 +1742,32 @@ static int isotp_setsockopt_locked(struct socket *sock, int optname,
if (READ_ONCE(so->tx.state) != ISOTP_IDLE ||
READ_ONCE(so->rx.state) != ISOTP_IDLE)
return -EAGAIN;
switch (optname) {
- case CAN_ISOTP_OPTS:
- memcpy(&so->opt, val, sizeof(so->opt));
+ case CAN_ISOTP_OPTS: {
+ const struct can_isotp_options *opt = val;
+
+ /* only one broadcast flag at a time */
+ if (hweight32(opt->flags & ISOTP_ALL_BC_FLAGS) > 1)
+ return -EINVAL;
+
+ memcpy(&so->opt, opt, sizeof(*opt));
/* no separate rx_ext_address is given => use ext_address */
if (!(so->opt.flags & CAN_ISOTP_RX_EXT_ADDR))
so->opt.rx_ext_address = so->opt.ext_address;
- /* these broadcast flags are not allowed together */
- if (isotp_bc_flags(so) == ISOTP_ALL_BC_FLAGS) {
- /* CAN_ISOTP_SF_BROADCAST is prioritized */
- so->opt.flags &= ~CAN_ISOTP_CF_BROADCAST;
-
- /* give user feedback on wrong config attempt */
- ret = -EINVAL;
- }
-
/* check for frame_txtime changes (0 => no changes) */
if (so->opt.frame_txtime) {
if (so->opt.frame_txtime == CAN_ISOTP_FRAME_TXTIME_ZERO)
so->frame_txtime = 0;
else
so->frame_txtime = so->opt.frame_txtime;
}
break;
+ }
case CAN_ISOTP_RECV_FC:
memcpy(&so->rxfc, val, sizeof(so->rxfc));
break;
--
2.53.0
^ permalink raw reply related [flat|nested] 38+ messages in thread* [PATCH can-next 05/22] can: isotp: add the frame transmission time to the protocol timeouts
2026-11-26 21:05 [PATCH can-next 00/22] can: memcg accounting, CAN_ISOTP fixes and cleanups Oliver Hartkopp
` (3 preceding siblings ...)
2026-11-26 21:05 ` [PATCH can-next 04/22] can: isotp: check the CAN_ISOTP_OPTS values before applying them Oliver Hartkopp
@ 2026-11-26 21:05 ` Oliver Hartkopp
2026-11-28 10:20 ` netdev-bot+sashiko
2026-11-26 21:05 ` [PATCH can-next 06/22] can: isotp: check the CAN FD tx_flags in CAN_ISOTP_LL_OPTS Oliver Hartkopp
` (17 subsequent siblings)
22 siblings, 1 reply; 38+ messages in thread
From: Oliver Hartkopp @ 2026-11-26 21:05 UTC (permalink / raw)
To: linux-can; +Cc: Marc Kleine-Budde, Wentian Ye, Oliver Hartkopp
The frame_txtime element of struct can_isotp_options is documented as
the frame transmission time (N_As/N_Ar). It is added to the gap between
the consecutive frames in the tx path, but it is missing when the
timeouts are started after the transmission of a CAN frame:
- isotp_send_fc() starts the rx timeout for the next consecutive frame
without the transmission time of the flow control frame (N_Ar)
- isotp_sendmsg() starts the timeout for the first flow control frame
without the transmission time of the first frame (N_As)
Add so->frame_txtime to both timeouts to comply with the documentation
in isotp.h. The local echo timeout for single frames and first frames
without flow control uses the same timer start in isotp_sendmsg() and
gets the frame transmission time as well, which has no effect. As the
value now extends the protocol timeouts, reject frame_txtime values
above 100 ms with -EINVAL before the options are applied.
There is no separate check for N_As/N_Ar timeouts, as the transmission
time of a CAN frame has no real world effect compared to the protocol
timeouts of one and two seconds.
Reported-by: Wentian Ye <yewentian395@gmail.com>
Closes: https://lore.kernel.org/linux-can/eb5e9618-3dbf-42cb-a635-752ff9fbcb99@hartkopp.net/
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
---
net/can/isotp.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/net/can/isotp.c b/net/can/isotp.c
index 7be3d9322ad1..197dc7bdb6ec 100644
--- a/net/can/isotp.c
+++ b/net/can/isotp.c
@@ -125,10 +125,11 @@ MODULE_PARM_DESC(max_pdu_size, "maximum isotp pdu size (default "
#define ISOTP_FC_WT 1 /* wait */
#define ISOTP_FC_OVFLW 2 /* overflow */
#define ISOTP_FC_TIMEOUT 1 /* 1 sec */
#define ISOTP_ECHO_TIMEOUT 2 /* 2 secs */
+#define ISOTP_MAX_FRAME_TXTIME_NS (100 * NSEC_PER_MSEC) /* max N_Ar/N_As */
/* so->tx_result[so->tx_gen % ISOTP_TX_RESULT_SLOTS] holds the packed value
* (err << ISOTP_TX_RESULT_GEN_BITS | gen) for each tx generation slot, so it
* can be handled with a single READ_ONCE()/WRITE_ONCE() access.
*/
@@ -347,11 +348,12 @@ static int isotp_send_fc(struct sock *sk, int ae, u8 flowstatus)
/* reset last CF frame rx timestamp for rx stmin enforcement */
so->lastrxcf_tstamp = ktime_set(0, 0);
/* start rx timeout watchdog */
- hrtimer_start(&so->rxtimer, ktime_set(ISOTP_FC_TIMEOUT, 0),
+ hrtimer_start(&so->rxtimer,
+ ktime_set(ISOTP_FC_TIMEOUT, so->frame_txtime),
HRTIMER_MODE_REL_SOFT);
return 0;
}
static void isotp_rcv_skb(struct sk_buff *skb, struct sock *sk)
@@ -1331,11 +1333,11 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
wake_up_interruptible(&so->wait);
return -EADDRNOTAVAIL;
}
/* WAIT_FIRST_FC for standard FF, else stays ISOTP_SENDING */
WRITE_ONCE(so->tx.state, new_state);
- hrtimer_start(tx_hrt, ktime_set(hrtimer_sec, 0),
+ hrtimer_start(tx_hrt, ktime_set(hrtimer_sec, so->frame_txtime),
HRTIMER_MODE_REL_SOFT);
spin_unlock_bh(&so->rx_lock);
/* send the first or only CAN frame */
cf->flags = so->ll.tx_flags;
@@ -1749,10 +1751,15 @@ static int isotp_setsockopt_locked(struct socket *sock, int optname,
/* only one broadcast flag at a time */
if (hweight32(opt->flags & ISOTP_ALL_BC_FLAGS) > 1)
return -EINVAL;
+ /* limit the frame transmission time (N_As/N_Ar) */
+ if (opt->frame_txtime != CAN_ISOTP_FRAME_TXTIME_ZERO &&
+ opt->frame_txtime > ISOTP_MAX_FRAME_TXTIME_NS)
+ return -EINVAL;
+
memcpy(&so->opt, opt, sizeof(*opt));
/* no separate rx_ext_address is given => use ext_address */
if (!(so->opt.flags & CAN_ISOTP_RX_EXT_ADDR))
so->opt.rx_ext_address = so->opt.ext_address;
--
2.53.0
^ permalink raw reply related [flat|nested] 38+ messages in thread* Re: [PATCH can-next 05/22] can: isotp: add the frame transmission time to the protocol timeouts
2026-11-26 21:05 ` [PATCH can-next 05/22] can: isotp: add the frame transmission time to the protocol timeouts Oliver Hartkopp
@ 2026-11-28 10:20 ` netdev-bot+sashiko
0 siblings, 0 replies; 38+ messages in thread
From: netdev-bot+sashiko @ 2026-11-28 10:20 UTC (permalink / raw)
To: socketcan
Cc: linux-can, mkl, sashiko-bot, zihanx, o.rempel, yewentian395, kuba
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · 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 patch adds a new rule to isotp_setsockopt_locked()
(net/can/isotp.c:1756-1759): setsockopt(CAN_ISOTP_OPTS) now returns…
--
can: isotp: add the frame transmission time to the protocol timeouts
This patch adds so->frame_txtime (N_As/N_Ar) to the rx timeout started in
isotp_send_fc() and to the FC/echo timeout started in isotp_sendmsg(). It
also makes setsockopt(CAN_ISOTP_OPTS) return -EINVAL when frame_txtime is
above 100 ms, unless it is CAN_ISOTP_FRAME_TXTIME_ZERO.
Closes: https://lore.kernel.org/linux-can/eb5e9618-3dbf-42cb-a635-752ff9fbcb99@hartkopp.net/
> diff --git a/net/can/isotp.c b/net/can/isotp.c
> index 7be3d9322ad1a..197dc7bdb6ec0 100644
> --- a/net/can/isotp.c
> +++ b/net/can/isotp.c
> @@ -127,6 +127,7 @@ MODULE_PARM_DESC(max_pdu_size, "maximum isotp pdu size (default "
>
> #define ISOTP_FC_TIMEOUT 1 /* 1 sec */
> #define ISOTP_ECHO_TIMEOUT 2 /* 2 secs */
> +#define ISOTP_MAX_FRAME_TXTIME_NS (100 * NSEC_PER_MSEC) /* max N_Ar/N_As */
[ ... ]
> @@ -1751,6 +1753,11 @@ static int isotp_setsockopt_locked(struct socket *sock, int optname,
> if (hweight32(opt->flags & ISOTP_ALL_BC_FLAGS) > 1)
> return -EINVAL;
>
> + /* limit the frame transmission time (N_As/N_Ar) */
> + if (opt->frame_txtime != CAN_ISOTP_FRAME_TXTIME_ZERO &&
> + opt->frame_txtime > ISOTP_MAX_FRAME_TXTIME_NS)
> + return -EINVAL;
> +
> memcpy(&so->opt, opt, sizeof(*opt));
[Severity: Medium]
Could this break existing userspace? Before this patch,
setsockopt(CAN_ISOTP_OPTS) accepted any u32 value for frame_txtime. A value
above 100 ms now gets -EINVAL.
The check runs before the memcpy(), so the whole call is rejected. That
means none of the other options passed in the same call get applied either,
such as CAN_ISOTP_CF_BROADCAST, ext_address or the padding settings.
Do the timeout changes need this limit? ktime_set() takes an unsigned long
nsecs and computes secs * NSEC_PER_SEC + nsecs. Even 0xFFFFFFFE ns only
produces an FC timeout of about 5.3 s, with no overflow.
frame_txtime also works as a pacing value, not only as N_As/N_Ar.
isotp_rcv_fc() adds it to every consecutive frame gap:
so->tx_gap = ktime_add_ns(so->tx_gap, so->frame_txtime);
In CAN_ISOTP_CF_BROADCAST mode without CAN_ISOTP_FORCE_TXSTMIN,
isotp_sendmsg() uses it as the whole gap:
so->tx_gap = ktime_set(0, so->frame_txtime);
A broadcast gap above 100 ms was valid until now. CAN_ISOTP_FORCE_TXSTMIN
together with CAN_ISOTP_TX_STMIN can still produce such a gap. Even so,
existing configurations that use frame_txtime for this would stop working.
The uAPI header still describes frame_txtime as a plain nanosecond value:
include/uapi/linux/can/isotp.h:
__u32 frame_txtime; /* frame transmission time (N_As/N_Ar) */
/* __u32 value : time in nano secs */
The CAN_ISOTP_FRAME_TXTIME_ZERO comment block and
Documentation/networking/iso15765-2.rst list only 0 and
CAN_ISOTP_FRAME_TXTIME_ZERO as special values. Neither mentions an upper
bound or an -EINVAL case, and ISOTP_MAX_FRAME_TXTIME_NS is private to
net/can/isotp.c. Later patches in the series do not seem to update either
document.
If the limit stays, should the uAPI header and the rst document it? Could
the commit message also explain why 100 ms was chosen?
>
> /* no separate rx_ext_address is given => use ext_address */
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261126-getsockopt-memcg-isotp-v1-0-681ef8d8c2c9%40hartkopp.net
^ permalink raw reply [flat|nested] 38+ messages in thread
* [PATCH can-next 06/22] can: isotp: check the CAN FD tx_flags in CAN_ISOTP_LL_OPTS
2026-11-26 21:05 [PATCH can-next 00/22] can: memcg accounting, CAN_ISOTP fixes and cleanups Oliver Hartkopp
` (4 preceding siblings ...)
2026-11-26 21:05 ` [PATCH can-next 05/22] can: isotp: add the frame transmission time to the protocol timeouts Oliver Hartkopp
@ 2026-11-26 21:05 ` Oliver Hartkopp
2026-11-28 10:20 ` netdev-bot+sashiko
2026-11-26 21:05 ` [PATCH can-next 07/22] can: isotp: reject reserved STmin values in CAN_ISOTP_RECV_FC Oliver Hartkopp
` (16 subsequent siblings)
22 siblings, 1 reply; 38+ messages in thread
From: Oliver Hartkopp @ 2026-11-26 21:05 UTC (permalink / raw)
To: linux-can; +Cc: Marc Kleine-Budde, Oliver Hartkopp
The tx_flags of struct can_isotp_ll_options are set into the flags of
the created CAN FD frames. For CAN CC they have to be zero but for CAN
FD any value was accepted, so that CANFD_ESI and undefined flags were
sent in the CAN FD frames.
As CANFD_ESI is generated by the transmitting CAN controller only
CANFD_BRS is relevant for the transmission. Accept CANFD_BRS and the
CANFD_FDF marker (which is set by the CAN core anyway) and reject other
tx_flags with -EINVAL.
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
---
net/can/isotp.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/net/can/isotp.c b/net/can/isotp.c
index 197dc7bdb6ec..6ec7b10d7136 100644
--- a/net/can/isotp.c
+++ b/net/can/isotp.c
@@ -1798,10 +1798,15 @@ 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));
/* set ll_dl for tx path to similar place as for rx */
so->tx.ll_dl = ll->tx_dl;
break;
--
2.53.0
^ permalink raw reply related [flat|nested] 38+ messages in thread* Re: [PATCH can-next 06/22] can: isotp: check the CAN FD tx_flags in CAN_ISOTP_LL_OPTS
2026-11-26 21:05 ` [PATCH can-next 06/22] can: isotp: check the CAN FD tx_flags in CAN_ISOTP_LL_OPTS Oliver Hartkopp
@ 2026-11-28 10:20 ` netdev-bot+sashiko
0 siblings, 0 replies; 38+ messages in thread
From: netdev-bot+sashiko @ 2026-11-28 10:20 UTC (permalink / raw)
To: socketcan
Cc: linux-can, mkl, sashiko-bot, zihanx, o.rempel, yewentian395, kuba
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The patch narrows the accepted CAN FD tx_flags values in
isotp_setsockopt_locked() (net/can/isotp.c:1803-1806) to…
- [Low] The commit message describes the old behaviour as a defect ("any
value was accepted, so that CANFD_ESI and undefined flags were sent in…
--
can: isotp: check the CAN FD tx_flags in CAN_ISOTP_LL_OPTS
This commit restricts the tx_flags accepted by setsockopt(CAN_ISOTP_LL_OPTS)
for CAN FD sockets to CANFD_BRS and CANFD_FDF. Any other bit, including
CANFD_ESI, is now rejected with -EINVAL. Previously any value was accepted
and copied into the flags of the generated CAN FD frames.
> The tx_flags of struct can_isotp_ll_options are set into the flags of
> the created CAN FD frames. For CAN CC they have to be zero but for CAN
> FD any value was accepted, so that CANFD_ESI and undefined flags were
> sent in the CAN FD frames.
[Severity: Low]
This wording presents the old behaviour as a defect, but there is no
Fixes: tag. The unchecked CAN FD path in isotp_setsockopt_locked() dates
back to e057dd3fc20f ("can: add ISO 15765-2:2016 transport protocol").
A Fixes: tag is probably not the right answer here, though. It would invite
stable backports of a change that rejects setsockopt() input that used to
be valid. Drivers such as mcp251xfd (ESIGM) and vcan also honour CANFD_ESI
when userspace requests it.
Could the commit message state clearly whether this is a bug fix or an
intentional tightening of the uAPI?
> diff --git a/net/can/isotp.c b/net/can/isotp.c
> index 197dc7bdb6ec0..6ec7b10d7136d 100644
> --- a/net/can/isotp.c
> +++ b/net/can/isotp.c
> @@ -1800,6 +1800,11 @@ 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;
> +
[Severity: Low]
Should the uAPI documentation be updated along with this new restriction?
Documentation/networking/iso15765-2.rst still describes tx_flags as an
open set of frame flags:
* tx_flags: flags set into struct canfd_frame.flags at frame creation.
Only applies to CAN FD traffic (i.e.: mtu = CANFD_MTU).
The comment in include/uapi/linux/can/isotp.h for struct
can_isotp_ll_options is similar:
__u8 tx_flags; /* set into struct canfd_frame.flags */
/* at frame creation: e.g. CANFD_BRS */
Neither one says that only CANFD_BRS and CANFD_FDF are accepted, or that
other bits such as CANFD_ESI now return -EINVAL.
> memcpy(&so->ll, ll, sizeof(*ll));
>
> /* set ll_dl for tx path to similar place as for rx */
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261126-getsockopt-memcg-isotp-v1-0-681ef8d8c2c9%40hartkopp.net
^ permalink raw reply [flat|nested] 38+ messages in thread
* [PATCH can-next 07/22] can: isotp: reject reserved STmin values in CAN_ISOTP_RECV_FC
2026-11-26 21:05 [PATCH can-next 00/22] can: memcg accounting, CAN_ISOTP fixes and cleanups Oliver Hartkopp
` (5 preceding siblings ...)
2026-11-26 21:05 ` [PATCH can-next 06/22] can: isotp: check the CAN FD tx_flags in CAN_ISOTP_LL_OPTS Oliver Hartkopp
@ 2026-11-26 21:05 ` Oliver Hartkopp
2026-11-26 21:05 ` [PATCH can-next 08/22] can: isotp: reject CAN_ISOTP_CHK_PAD_DATA without CAN_ISOTP_RX_PADDING Oliver Hartkopp
` (15 subsequent siblings)
22 siblings, 0 replies; 38+ messages in thread
From: Oliver Hartkopp @ 2026-11-26 21:05 UTC (permalink / raw)
To: linux-can; +Cc: Marc Kleine-Budde, Oliver Hartkopp
The STmin value of struct can_isotp_fc_options is sent in the flow
control frames of the receiver. ISO 15765-2 reserves the values 0x80 -
0xF0 and 0xFA - 0xFF, but CAN_ISOTP_RECV_FC accepted any value and the
reserved values were sent on the bus. The sender side replaces received
reserved values with 0x7F already.
Reject the reserved STmin values with -EINVAL before the options are
applied.
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
---
net/can/isotp.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/net/can/isotp.c b/net/can/isotp.c
index 6ec7b10d7136..6471c0ef319a 100644
--- a/net/can/isotp.c
+++ b/net/can/isotp.c
@@ -1772,13 +1772,21 @@ static int isotp_setsockopt_locked(struct socket *sock, int optname,
so->frame_txtime = so->opt.frame_txtime;
}
break;
}
- case CAN_ISOTP_RECV_FC:
- memcpy(&so->rxfc, val, sizeof(so->rxfc));
+ case CAN_ISOTP_RECV_FC: {
+ const struct can_isotp_fc_options *fc = val;
+
+ /* reject the reserved STmin values 0x80 - 0xF0, 0xFA - 0xFF */
+ if (fc->stmin > 0x7F &&
+ (fc->stmin < 0xF1 || fc->stmin > 0xF9))
+ return -EINVAL;
+
+ memcpy(&so->rxfc, fc, sizeof(*fc));
break;
+ }
case CAN_ISOTP_TX_STMIN:
so->force_tx_stmin = *(const u32 *)val;
break;
--
2.53.0
^ permalink raw reply related [flat|nested] 38+ messages in thread* [PATCH can-next 08/22] can: isotp: reject CAN_ISOTP_CHK_PAD_DATA without CAN_ISOTP_RX_PADDING
2026-11-26 21:05 [PATCH can-next 00/22] can: memcg accounting, CAN_ISOTP fixes and cleanups Oliver Hartkopp
` (6 preceding siblings ...)
2026-11-26 21:05 ` [PATCH can-next 07/22] can: isotp: reject reserved STmin values in CAN_ISOTP_RECV_FC Oliver Hartkopp
@ 2026-11-26 21:05 ` Oliver Hartkopp
2026-11-28 10:20 ` netdev-bot+sashiko
2026-11-26 21:05 ` [PATCH can-next 09/22] can: isotp: drop frames without N_PCI Oliver Hartkopp
` (14 subsequent siblings)
22 siblings, 1 reply; 38+ messages in thread
From: Oliver Hartkopp @ 2026-11-26 21:05 UTC (permalink / raw)
To: linux-can; +Cc: Marc Kleine-Budde, Oliver Hartkopp
CAN_ISOTP_CHK_PAD_DATA checks the padding bytes of received frames
against the rxpad_content, which is only defined together with
CAN_ISOTP_RX_PADDING. Without CAN_ISOTP_RX_PADDING check_pad() fails
for every frame, so that no PDU can be received and every FC aborts the
transmission with EBADMSG.
Reject CAN_ISOTP_CHK_PAD_DATA without CAN_ISOTP_RX_PADDING with -EINVAL
before the options are applied. CAN_ISOTP_CHK_PAD_LEN without
CAN_ISOTP_RX_PADDING still checks for the optimized frame length.
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
---
net/can/isotp.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/net/can/isotp.c b/net/can/isotp.c
index 6471c0ef319a..0af1a689fdd3 100644
--- a/net/can/isotp.c
+++ b/net/can/isotp.c
@@ -1756,10 +1756,15 @@ static int isotp_setsockopt_locked(struct socket *sock, int optname,
/* limit the frame transmission time (N_As/N_Ar) */
if (opt->frame_txtime != CAN_ISOTP_FRAME_TXTIME_ZERO &&
opt->frame_txtime > ISOTP_MAX_FRAME_TXTIME_NS)
return -EINVAL;
+ /* the padding content check needs the rx padding content */
+ if ((opt->flags & CAN_ISOTP_CHK_PAD_DATA) &&
+ !(opt->flags & CAN_ISOTP_RX_PADDING))
+ return -EINVAL;
+
memcpy(&so->opt, opt, sizeof(*opt));
/* no separate rx_ext_address is given => use ext_address */
if (!(so->opt.flags & CAN_ISOTP_RX_EXT_ADDR))
so->opt.rx_ext_address = so->opt.ext_address;
--
2.53.0
^ permalink raw reply related [flat|nested] 38+ messages in thread* Re: [PATCH can-next 08/22] can: isotp: reject CAN_ISOTP_CHK_PAD_DATA without CAN_ISOTP_RX_PADDING
2026-11-26 21:05 ` [PATCH can-next 08/22] can: isotp: reject CAN_ISOTP_CHK_PAD_DATA without CAN_ISOTP_RX_PADDING Oliver Hartkopp
@ 2026-11-28 10:20 ` netdev-bot+sashiko
0 siblings, 0 replies; 38+ messages in thread
From: netdev-bot+sashiko @ 2026-11-28 10:20 UTC (permalink / raw)
To: socketcan
Cc: linux-can, mkl, sashiko-bot, zihanx, o.rempel, yewentian395, kuba
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.
Critical: 0 · High: 1 · 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).
- [High] The new check in isotp_setsockopt_locked()
(net/can/isotp.c:1761-1764) is too broad.
- [Medium] Documentation/networking/iso15765-2.rst (lines 176-178)
documents the UAPI semantics of CAN_ISOTP_CHK_PAD_DATA as: 'check…
- [Low] In check_pad() (net/can/isotp.c:420-427), the branch commented
'/* no valid test against empty value => ignore frame */ return 1;'…
--
can: isotp: reject CAN_ISOTP_CHK_PAD_DATA without CAN_ISOTP_RX_PADDING
With this patch, setsockopt(CAN_ISOTP_OPTS) returns -EINVAL when
CAN_ISOTP_CHK_PAD_DATA is set without CAN_ISOTP_RX_PADDING. The check
runs before the options are copied into so->opt. The goal is to avoid a
configuration in which check_pad() fails for every received frame.
> diff --git a/net/can/isotp.c b/net/can/isotp.c
> index 6471c0ef319a4..0af1a689fdd38 100644
> --- a/net/can/isotp.c
> +++ b/net/can/isotp.c
> @@ -1758,6 +1758,11 @@ static int isotp_setsockopt_locked(struct socket *sock, int optname,
> opt->frame_txtime > ISOTP_MAX_FRAME_TXTIME_NS)
> return -EINVAL;
>
> + /* the padding content check needs the rx padding content */
> + if ((opt->flags & CAN_ISOTP_CHK_PAD_DATA) &&
> + !(opt->flags & CAN_ISOTP_RX_PADDING))
> + return -EINVAL;
[Severity: High]
Does this also reject CAN_ISOTP_CHK_PAD_LEN | CAN_ISOTP_CHK_PAD_DATA
without CAN_ISOTP_RX_PADDING? That combination works before this patch.
When RX_PADDING is clear, check_pad() tests CHK_PAD_LEN first. It never
gets to the content check:
net/can/isotp.c:check_pad() {
/* no RX_PADDING value => check length of optimized frame length */
if (!(so->opt.flags & CAN_ISOTP_RX_PADDING)) {
if (so->opt.flags & CAN_ISOTP_CHK_PAD_LEN)
return check_optimized(cf, start_index);
/* no valid test against empty value => ignore frame */
return 1;
}
...
}
Only CHK_PAD_DATA without CHK_PAD_LEN reaches the return 1. This means
the following statement in the commit message does not hold for the
LEN|DATA combination:
Without CAN_ISOTP_RX_PADDING check_pad() fails for every frame, so that
no PDU can be received and every FC aborts the transmission with
EBADMSG.
The new check returns before memcpy(&so->opt, ...). As a result, every
other option in the same call is discarded too: ext_address,
rx_ext_address, txpad_content, frame_txtime and the remaining flags. An
application that ignores the setsockopt() return value would then keep
running on the default options without noticing.
A "check all padding" mode in userspace tools could produce LEN|DATA
without RX padding. As far as I understand, can-utils -P a is one
example, though I have not verified this.
Would a narrower condition close the broken case without rejecting the
working one? Something like:
if ((opt->flags & CAN_ISOTP_CHK_PAD_DATA) &&
!(opt->flags & (CAN_ISOTP_RX_PADDING | CAN_ISOTP_CHK_PAD_LEN)))
return -EINVAL;
Fixing check_pad() itself would also work.
[Severity: Medium]
Documentation/networking/iso15765-2.rst describes the flag like this:
* CAN_ISOTP_CHK_PAD_DATA: check padding bytes on the received frames
against rxpad_content; if CAN_ISOTP_RX_PADDING is not specified,
this flag is ignored.
After this patch the flag is no longer ignored, and setsockopt() returns
-EINVAL instead. The documentation is not updated in this patch.
The documented behaviour points to a different fix: check_pad() could
ignore CHK_PAD_DATA when RX_PADDING is clear, by returning 0 in that
branch instead of 1. Would that be closer to the existing UAPI contract?
If rejecting the flag is the intended semantics, should
iso15765-2.rst be updated to match?
[Severity: Low]
This isn't a bug, but with this validation in place the "ignore frame"
return 1 branch in check_pad() can no longer be reached.
All callers (isotp_rcv_fc(), isotp_rcv_sf(), isotp_rcv_ff(),
isotp_rcv_cf()) call check_pad() only when ISOTP_CHECK_PADDING is set.
so->opt.flags is written in two places only: isotp_init() sets it to
CAN_ISOTP_DEFAULT_FLAGS, and the memcpy() below copies it after this new
check.
The comment in that branch also says "ignore frame". The code actually
reports a failed check, which drops the frame or aborts the transmission
with EBADMSG.
Could the comment be updated, or the branch removed or reworded to say
that setsockopt() prevents this state?
> +
> memcpy(&so->opt, opt, sizeof(*opt));
>
> /* no separate rx_ext_address is given => use ext_address */
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261126-getsockopt-memcg-isotp-v1-0-681ef8d8c2c9%40hartkopp.net
^ permalink raw reply [flat|nested] 38+ messages in thread
* [PATCH can-next 09/22] can: isotp: drop frames without N_PCI
2026-11-26 21:05 [PATCH can-next 00/22] can: memcg accounting, CAN_ISOTP fixes and cleanups Oliver Hartkopp
` (7 preceding siblings ...)
2026-11-26 21:05 ` [PATCH can-next 08/22] can: isotp: reject CAN_ISOTP_CHK_PAD_DATA without CAN_ISOTP_RX_PADDING Oliver Hartkopp
@ 2026-11-26 21:05 ` Oliver Hartkopp
2026-11-28 10:20 ` netdev-bot+sashiko
2026-11-26 21:05 ` [PATCH can-next 10/22] can: isotp: drop FF frames with invalid length extension Oliver Hartkopp
` (13 subsequent siblings)
22 siblings, 1 reply; 38+ messages in thread
From: Oliver Hartkopp @ 2026-11-26 21:05 UTC (permalink / raw)
To: linux-can; +Cc: Marc Kleine-Budde, Oliver Hartkopp
isotp_rcv() reads the address extension and the N_PCI without checking
the CAN frame data length. So frames with CAN_DL < ae + N_PCI_SZ are
processed with stale data beyond CAN_DL, e.g. as SF, CF or FC.
Drop these frames as they are no valid N_PDUs.
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
---
net/can/isotp.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/net/can/isotp.c b/net/can/isotp.c
index 0af1a689fdd3..e51a513402b3 100644
--- a/net/can/isotp.c
+++ b/net/can/isotp.c
@@ -777,10 +777,14 @@ static void isotp_rcv(struct sk_buff *skb, void *data)
return;
}
cf = (struct canfd_frame *)skb->data;
+ /* frames without N_PCI (and AE) are no N_PDUs */
+ if (cf->len < ae + N_PCI_SZ)
+ return;
+
/* if enabled: check reception of my configured extended address */
if (ae && cf->data[0] != so->opt.rx_ext_address)
return;
n_pci_type = cf->data[ae] & 0xF0;
--
2.53.0
^ permalink raw reply related [flat|nested] 38+ messages in thread* Re: [PATCH can-next 09/22] can: isotp: drop frames without N_PCI
2026-11-26 21:05 ` [PATCH can-next 09/22] can: isotp: drop frames without N_PCI Oliver Hartkopp
@ 2026-11-28 10:20 ` netdev-bot+sashiko
0 siblings, 0 replies; 38+ messages in thread
From: netdev-bot+sashiko @ 2026-11-28 10:20 UTC (permalink / raw)
To: socketcan
Cc: linux-can, mkl, sashiko-bot, zihanx, o.rempel, yewentian395, kuba
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The commit "can: isotp: drop frames without N_PCI" fixes a
receive-path defect that has existed since ISO-TP was added in commit…
--
can: isotp: drop frames without N_PCI
This commit adds a length check to isotp_rcv() in net/can/isotp.c. CAN
frames whose data length is shorter than the address extension plus the
N_PCI byte are now dropped. Before this, they were decoded from stale data
beyond CAN_DL.
> isotp_rcv() reads the address extension and the N_PCI without checking
> the CAN frame data length. So frames with CAN_DL < ae + N_PCI_SZ are
> processed with stale data beyond CAN_DL, e.g. as SF, CF or FC.
>
> Drop these frames as they are no valid N_PDUs.
>
> Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
[Severity: Low]
Should this patch carry a Fixes: tag?
The unchecked reads of cf->data[0] and cf->data[ae] in isotp_rcv() seem
to date back to the original ISO-TP code:
Fixes: e057dd3fc20f ("can: add ISO 15765-2:2016 transport protocol")
Without the tag, stable backporting will probably miss this patch.
Could the commit message also describe the concrete impact? CAN drivers
zero-fill the frame data through alloc_can_skb()->skb_put_zero(). A DLC 0
frame on the rx CAN ID therefore decodes as N_PCI_SF with SF_DL 0.
isotp_rcv_sf() then resets the rx state before it checks the length:
net/can/isotp.c:isotp_rcv_sf() {
...
hrtimer_cancel(&so->rxtimer);
WRITE_ONCE(so->rx.state, ISOTP_IDLE);
if (!len || len > cf->len - pcilen)
return 1;
...
}
So any node on the bus can silently abort a multi-frame reception that is
in progress. The CFs that follow are ignored, and the application gets
neither the PDU nor an error.
The stale bytes may also be non-zero, for example when the frame comes from
a local CAN_RAW or vcan sender. The frame can then be decoded as a CF,
which uses up a sequence number. It can also be decoded as an FC, which
aborts a transmission.
A backport dependency may also be worth recording. The later commit
"can: isotp: check the data length of the last CF" relies on this check:
isotp_rcv() ensures cf->len >= ae + N_PCI_SZ, so the payload size can
not underflow
What happens if that commit is backported without this one? The signed
value cf->len - ae - N_PCI_SZ could go negative. It is converted to
unsigned in the comparison, so wouldn't that check then never fire?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261126-getsockopt-memcg-isotp-v1-0-681ef8d8c2c9%40hartkopp.net
^ permalink raw reply [flat|nested] 38+ messages in thread
* [PATCH can-next 10/22] can: isotp: drop FF frames with invalid length extension
2026-11-26 21:05 [PATCH can-next 00/22] can: memcg accounting, CAN_ISOTP fixes and cleanups Oliver Hartkopp
` (8 preceding siblings ...)
2026-11-26 21:05 ` [PATCH can-next 09/22] can: isotp: drop frames without N_PCI Oliver Hartkopp
@ 2026-11-26 21:05 ` Oliver Hartkopp
2026-11-26 21:05 ` [PATCH can-next 11/22] can: isotp: check the minimum FF_DL Oliver Hartkopp
` (12 subsequent siblings)
22 siblings, 0 replies; 38+ messages in thread
From: Oliver Hartkopp @ 2026-11-26 21:05 UTC (permalink / raw)
To: linux-can; +Cc: Marc Kleine-Budde, Oliver Hartkopp
The FF data length usually consists of 12 bits for values up to 4095 byte.
ISO 15765-2:2016 introduced an escape sequence where the 32 bit length
information is retrieved from the following 4 byte when the FF data length
is set to the reserved value 0.
This escape sequence is only allowed for FF data length values greater than
4095 and therefore PDUs with length values that would also fit into the 12
bit value representation shall be ignored according to ISO 15765-2:2016.
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
---
net/can/isotp.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/net/can/isotp.c b/net/can/isotp.c
index e51a513402b3..3167a0690b84 100644
--- a/net/can/isotp.c
+++ b/net/can/isotp.c
@@ -601,10 +601,14 @@ static int isotp_rcv_ff(struct sock *sk, struct canfd_frame *cf, int ae)
so->rx.len = cf->data[ae + 2] << 24;
so->rx.len += cf->data[ae + 3] << 16;
so->rx.len += cf->data[ae + 4] << 8;
so->rx.len += cf->data[ae + 5];
ff_pci_sz = FF_PCI_SZ32;
+
+ /* unneeded escape sequence => ignore PDU according to spec */
+ if (so->rx.len <= MAX_12BIT_PDU_SIZE)
+ return 1;
}
/* take care of a potential SF_DL ESC offset for TX_DL > 8 */
off = (so->rx.ll_dl > CAN_MAX_DLEN) ? 1 : 0;
--
2.53.0
^ permalink raw reply related [flat|nested] 38+ messages in thread* [PATCH can-next 11/22] can: isotp: check the minimum FF_DL
2026-11-26 21:05 [PATCH can-next 00/22] can: memcg accounting, CAN_ISOTP fixes and cleanups Oliver Hartkopp
` (9 preceding siblings ...)
2026-11-26 21:05 ` [PATCH can-next 10/22] can: isotp: drop FF frames with invalid length extension Oliver Hartkopp
@ 2026-11-26 21:05 ` Oliver Hartkopp
2026-11-28 10:20 ` netdev-bot+sashiko
2026-11-26 21:05 ` [PATCH can-next 12/22] can: isotp: check the data length of the last CF Oliver Hartkopp
` (11 subsequent siblings)
22 siblings, 1 reply; 38+ messages in thread
From: Oliver Hartkopp @ 2026-11-26 21:05 UTC (permalink / raw)
To: linux-can; +Cc: Marc Kleine-Budde, Oliver Hartkopp
ISO 15765-2 requires FF_DL >= FF_DLmin: a PDU that fits into a SF must
not be segmented. The rx check only ensured that a CF is needed and
contained a SF_DL escape offset for LL_DL > 8 which is only required on
the tx side. So e.g. FF_DL 7 was accepted for LL_DL 8.
Check the FF_DL against the maximum SF_DL of the sender LL_DL like
isotp_sendmsg() does on the tx path. As only FF_DL is on the left side
the check does not wrap around for FF_DL values close to 2^32.
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
---
net/can/isotp.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/net/can/isotp.c b/net/can/isotp.c
index 3167a0690b84..8aeec4ca1d19 100644
--- a/net/can/isotp.c
+++ b/net/can/isotp.c
@@ -573,12 +573,12 @@ static int isotp_rcv_sf(struct sock *sk, struct canfd_frame *cf, int pcilen,
}
static int isotp_rcv_ff(struct sock *sk, struct canfd_frame *cf, int ae)
{
struct isotp_sock *so = isotp_sk(sk);
+ unsigned int sf_max;
int i;
- int off;
int ff_pci_sz;
hrtimer_cancel(&so->rxtimer);
WRITE_ONCE(so->rx.state, ISOTP_IDLE);
@@ -607,14 +607,17 @@ static int isotp_rcv_ff(struct sock *sk, struct canfd_frame *cf, int ae)
/* unneeded escape sequence => ignore PDU according to spec */
if (so->rx.len <= MAX_12BIT_PDU_SIZE)
return 1;
}
- /* take care of a potential SF_DL ESC offset for TX_DL > 8 */
- off = (so->rx.ll_dl > CAN_MAX_DLEN) ? 1 : 0;
+ /* the PDU must not fit into a SF (FF_DLmin) */
+ if (so->rx.ll_dl == CAN_MAX_DLEN)
+ sf_max = CAN_MAX_DLEN - SF_PCI_SZ4 - ae;
+ else
+ sf_max = so->rx.ll_dl - SF_PCI_SZ8 - ae;
- if (so->rx.len + ae + off + ff_pci_sz < so->rx.ll_dl)
+ if (so->rx.len <= sf_max)
return 1;
/* PDU size > default => try max_pdu_size
*
* This buffer is not accounted to a memory cgroup: In softirq
--
2.53.0
^ permalink raw reply related [flat|nested] 38+ messages in thread* Re: [PATCH can-next 11/22] can: isotp: check the minimum FF_DL
2026-11-26 21:05 ` [PATCH can-next 11/22] can: isotp: check the minimum FF_DL Oliver Hartkopp
@ 2026-11-28 10:20 ` netdev-bot+sashiko
0 siblings, 0 replies; 38+ messages in thread
From: netdev-bot+sashiko @ 2026-11-28 10:20 UTC (permalink / raw)
To: socketcan
Cc: linux-can, mkl, sashiko-bot, zihanx, o.rempel, yewentian395, kuba
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The commit message for "can: isotp: check the minimum FF_DL"
describes the old receive check in isotp_rcv_ff() (net/can/isotp.c)…
- [Low] "can: isotp: check the minimum FF_DL" fixes a receive-path
protocol bug in isotp_rcv_ff() (net/can/isotp.c) but has no Fixes: tag.
--
can: isotp: check the minimum FF_DL
This commit replaces the FF_DL lower bound check in isotp_rcv_ff() with a
check against the maximum SF_DL for the sender LL_DL. A PDU that would fit
into a SF is then no longer accepted as a FF, which matches what
isotp_sendmsg() does on the tx path.
> ISO 15765-2 requires FF_DL >= FF_DLmin: a PDU that fits into a SF must
> not be segmented. The rx check only ensured that a CF is needed and
> contained a SF_DL escape offset for LL_DL > 8 which is only required on
> the tx side. So e.g. FF_DL 7 was accepted for LL_DL 8.
[Severity: Low]
Does this describe the old check accurately? This was the old check in
isotp_rcv_ff() in net/can/isotp.c:
off = (so->rx.ll_dl > CAN_MAX_DLEN) ? 1 : 0;
if (so->rx.len + ae + off + ff_pci_sz < so->rx.ll_dl)
return 1;
It only rejected FF_DL < LL_DL - ae - off - ff_pci_sz. That means it did
not guarantee that a CF was needed.
For CAN CC (LL_DL 8, ae 0, off 0, FF_PCI_SZ12), only FF_DL < 6 was
rejected. FF_DL 6 was accepted even though the FF already carries all 6
bytes.
For CAN FD (LL_DL 64, ae 0, off 1), FF_DL 61 and 62 were accepted. The FF
copy loop is bounded by ll_dl, not rx.len:
for (i = ae + ff_pci_sz; i < so->rx.ll_dl; i++)
so->rx.buf[so->rx.idx++] = cf->data[i];
So for FF_DL 61 it copied 62 bytes and left rx.idx > rx.len.
In both cases the receiver still moved to ISOTP_WAIT_DATA and sent FC CTS
for a CF that a compliant sender never sends.
Could the commit message say that the old check also accepted FFs whose
whole FF_DL already fits into the FF? The FF_DL 7 at LL_DL 8 example
understates what was accepted. The code change itself looks correct.
> Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
[Severity: Low]
Should this have a Fixes: tag? Without this patch, kernels accept FFs below
FF_DLmin in isotp_rcv_ff(). They then arm the rx timer and send FC CTS on
the bus. ISO 15765-2 says such FFs should be ignored.
git blame shows that the replaced check and the off computation come from
the original isotp commit, so this tag might fit:
Fixes: e057dd3fc20f ("can: add ISO 15765-2:2016 transport protocol")
Without it, the stable trees won't pick this up.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261126-getsockopt-memcg-isotp-v1-0-681ef8d8c2c9%40hartkopp.net
^ permalink raw reply [flat|nested] 38+ messages in thread
* [PATCH can-next 12/22] can: isotp: check the data length of the last CF
2026-11-26 21:05 [PATCH can-next 00/22] can: memcg accounting, CAN_ISOTP fixes and cleanups Oliver Hartkopp
` (10 preceding siblings ...)
2026-11-26 21:05 ` [PATCH can-next 11/22] can: isotp: check the minimum FF_DL Oliver Hartkopp
@ 2026-11-26 21:05 ` Oliver Hartkopp
2026-11-28 10:20 ` netdev-bot+sashiko
2026-11-26 21:05 ` [PATCH can-next 13/22] can: isotp: do not send FC.OVFLW in listen mode Oliver Hartkopp
` (10 subsequent siblings)
22 siblings, 1 reply; 38+ messages in thread
From: Oliver Hartkopp @ 2026-11-26 21:05 UTC (permalink / raw)
To: linux-can; +Cc: Marc Kleine-Budde, Oliver Hartkopp
A CF shorter than LL_DL is only allowed as last CF and therefore has to
carry all missing bytes of the PDU. But the missing bytes were compared
with the payload of a full CF. So a short CF without all missing bytes
was accepted and the reception continued with further CFs.
Drop a short CF when the missing PDU bytes exceed its possible payload
(cf->len - ae - N_PCI_SZ). Padding is still possible as it only
increases cf->len. isotp_rcv() ensures cf->len >= ae + N_PCI_SZ, so
the payload size can not underflow.
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
---
net/can/isotp.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/net/can/isotp.c b/net/can/isotp.c
index 8aeec4ca1d19..8ae314fe68d2 100644
--- a/net/can/isotp.c
+++ b/net/can/isotp.c
@@ -672,12 +672,14 @@ static int isotp_rcv_cf(struct sock *sk, struct canfd_frame *cf, int ae,
if (cf->len > so->rx.ll_dl)
return 1;
/* CFs have usually the LL_DL length */
if (cf->len < so->rx.ll_dl) {
- /* this is only allowed for the last CF */
- if (so->rx.len - so->rx.idx > so->rx.ll_dl - ae - N_PCI_SZ)
+ /* only the last CF may be shorter: drop it when the
+ * missing PDU bytes exceed its possible payload
+ */
+ if (so->rx.len - so->rx.idx > cf->len - ae - N_PCI_SZ)
return 1;
}
if (READ_ONCE(so->rx.state) != ISOTP_WAIT_DATA)
return 0;
--
2.53.0
^ permalink raw reply related [flat|nested] 38+ messages in thread* Re: [PATCH can-next 12/22] can: isotp: check the data length of the last CF
2026-11-26 21:05 ` [PATCH can-next 12/22] can: isotp: check the data length of the last CF Oliver Hartkopp
@ 2026-11-28 10:20 ` netdev-bot+sashiko
0 siblings, 0 replies; 38+ messages in thread
From: netdev-bot+sashiko @ 2026-11-28 10:20 UTC (permalink / raw)
To: socketcan
Cc: linux-can, mkl, sashiko-bot, zihanx, o.rempel, yewentian395, kuba
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The commit "can: isotp: check the data length of the last CF"
fixes a long-standing receive-path validation bug in isotp_rcv_cf()…
--
can: isotp: check the data length of the last CF
This commit fixes the short CF length check in isotp_rcv_cf(). A CF
shorter than LL_DL now has to carry all of the missing PDU bytes in its
own payload (cf->len - ae - N_PCI_SZ), not in the payload of a full CF.
> diff --git a/net/can/isotp.c b/net/can/isotp.c
> index 8aeec4ca1d19a..8ae314fe68d25 100644
> --- a/net/can/isotp.c
> +++ b/net/can/isotp.c
> @@ -674,8 +674,10 @@ static int isotp_rcv_cf(struct sock *sk, struct canfd_frame *cf, int ae,
>
> /* CFs have usually the LL_DL length */
> if (cf->len < so->rx.ll_dl) {
> - /* this is only allowed for the last CF */
> - if (so->rx.len - so->rx.idx > so->rx.ll_dl - ae - N_PCI_SZ)
> + /* only the last CF may be shorter: drop it when the
> + * missing PDU bytes exceed its possible payload
> + */
> + if (so->rx.len - so->rx.idx > cf->len - ae - N_PCI_SZ)
> return 1;
> }
[Severity: Low]
Should this commit have a Fixes: tag and Cc: stable?
The old check against so->rx.ll_dl - ae - N_PCI_SZ seems to date back
to the original isotp code in e057dd3fc20f ("can: add ISO 15765-2:2016
transport protocol").
Take classic CAN with ll_dl = 8, ae = 0 and 7 bytes still missing. A 4
byte CF carries only 3 bytes, but the old check evaluates 7 > 7. The
frame is accepted and reception keeps waiting for more CFs.
Commit 4b558c0ccb62 ("can: isotp: always start the rx timeout in
ISOTP_WAIT_DATA state") moved this block ahead of hrtimer_cancel() but
left the comparison as it was. That commit has Fixes: e057dd3fc20f and
Cc: stable@vger.kernel.org.
Stable trees that pick up 4b558c0ccb62 would get the moved check with
the old comparison. Nothing in this commit would tell them to take this
fix as well.
Would tags like these fit?
Fixes: e057dd3fc20f ("can: add ISO 15765-2:2016 transport protocol")
Cc: stable@vger.kernel.org
None of the patches in this series seem to have Fixes: tags. If the
series is meant only for net-next, could the commit message say so?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261126-getsockopt-memcg-isotp-v1-0-681ef8d8c2c9%40hartkopp.net
^ permalink raw reply [flat|nested] 38+ messages in thread
* [PATCH can-next 13/22] can: isotp: do not send FC.OVFLW in listen mode
2026-11-26 21:05 [PATCH can-next 00/22] can: memcg accounting, CAN_ISOTP fixes and cleanups Oliver Hartkopp
` (11 preceding siblings ...)
2026-11-26 21:05 ` [PATCH can-next 12/22] can: isotp: check the data length of the last CF Oliver Hartkopp
@ 2026-11-26 21:05 ` Oliver Hartkopp
2026-11-28 10:20 ` netdev-bot+sashiko
2026-11-26 21:05 ` [PATCH can-next 14/22] can: isotp: ignore invalid SF and FF frames during a reception Oliver Hartkopp
` (9 subsequent siblings)
22 siblings, 1 reply; 38+ messages in thread
From: Oliver Hartkopp @ 2026-11-26 21:05 UTC (permalink / raw)
To: linux-can; +Cc: Marc Kleine-Budde, Oliver Hartkopp
isotp_rcv_ff() sends a FC with overflow status when the FF_DL exceeds
the receive buffer without checking CAN_ISOTP_LISTEN_MODE. So a
listening socket sends a FC on the bus, which can abort the transfer
between other nodes using the same CAN IDs.
Move the listen mode check from the callers into isotp_send_fc() before
any state changes to cover all FC frames.
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
---
net/can/isotp.c | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/net/can/isotp.c b/net/can/isotp.c
index 8ae314fe68d2..f6801c18172c 100644
--- a/net/can/isotp.c
+++ b/net/can/isotp.c
@@ -293,10 +293,14 @@ static int isotp_send_fc(struct sock *sk, int ae, u8 flowstatus)
struct can_skb_ext *csx;
struct canfd_frame *ncf;
struct isotp_sock *so = isotp_sk(sk);
int can_send_ret;
+ /* no creation of flow control frames in listen mode */
+ if (so->opt.flags & CAN_ISOTP_LISTEN_MODE)
+ return 0;
+
nskb = alloc_skb(so->ll.mtu, gfp_any());
if (!nskb)
return 1;
csx = can_skb_ext_add(nskb);
@@ -650,14 +654,10 @@ static int isotp_rcv_ff(struct sock *sk, struct canfd_frame *cf, int ae)
/* start rx timeout, isotp_send_fc() restarts it */
hrtimer_start(&so->rxtimer, ktime_set(ISOTP_FC_TIMEOUT, 0),
HRTIMER_MODE_REL_SOFT);
- /* no creation of flow control frames */
- if (so->opt.flags & CAN_ISOTP_LISTEN_MODE)
- return 0;
-
/* send our first FC frame */
isotp_send_fc(sk, ae, ISOTP_FC_CTS);
return 0;
}
@@ -753,14 +753,10 @@ static int isotp_rcv_cf(struct sock *sk, struct canfd_frame *cf, int ae,
/* perform blocksize handling, if enabled */
if (!so->rxfc.bs || ++so->rx.bs < so->rxfc.bs)
return 0;
- /* no creation of flow control frames */
- if (so->opt.flags & CAN_ISOTP_LISTEN_MODE)
- return 0;
-
/* we reached the specified blocksize so->rxfc.bs */
isotp_send_fc(sk, ae, ISOTP_FC_CTS);
return 0;
}
--
2.53.0
^ permalink raw reply related [flat|nested] 38+ messages in thread* Re: [PATCH can-next 13/22] can: isotp: do not send FC.OVFLW in listen mode
2026-11-26 21:05 ` [PATCH can-next 13/22] can: isotp: do not send FC.OVFLW in listen mode Oliver Hartkopp
@ 2026-11-28 10:20 ` netdev-bot+sashiko
0 siblings, 0 replies; 38+ messages in thread
From: netdev-bot+sashiko @ 2026-11-28 10:20 UTC (permalink / raw)
To: socketcan
Cc: linux-can, mkl, sashiko-bot, zihanx, o.rempel, yewentian395, kuba
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] Commit "can: isotp: do not send FC.OVFLW in listen mode" fixes a
bug that is visible on the bus and has existed since isotp was first…
--
can: isotp: do not send FC.OVFLW in listen mode
This commit moves the CAN_ISOTP_LISTEN_MODE check out of isotp_rcv_ff()
and isotp_rcv_cf() and into isotp_send_fc(). With the check there, a
listen-mode socket no longer sends any flow control frame. That includes
the FC.OVFLW frame that isotp_rcv_ff() sent when the FF_DL exceeded the
receive buffer.
> isotp_rcv_ff() sends a FC with overflow status when the FF_DL exceeds
> the receive buffer without checking CAN_ISOTP_LISTEN_MODE. So a
> listening socket sends a FC on the bus, which can abort the transfer
> between other nodes using the same CAN IDs.
>
> Move the listen mode check from the callers into isotp_send_fc() before
> any state changes to cover all FC frames.
>
> Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
[Severity: Low]
Should this have Fixes: and Cc: stable tags?
The ordering this patch fixes was there in the original isotp commit. In
isotp_rcv_ff(), the overflow branch sent FC.OVFLW before the listen-mode
check was reached:
if (so->rx.len > MAX_MSG_LENGTH) {
isotp_send_fc(sk, ae, ISOTP_FC_OVFLW);
return 1;
}
...
if (so->opt.flags & CAN_ISOTP_LISTEN_MODE)
return 0;
Without tags, stable kernels since v5.10 may not get this fix. A
listen-mode socket on those kernels would still answer an oversized First
Frame with FC.OVFLW on so->txid. The real sender would then abort a
transfer between other nodes.
Would something like this be appropriate?
Fixes: e057dd3fc20f ("can: add ISO 15765-2:2016 transport protocol")
Cc: stable@vger.kernel.org
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261126-getsockopt-memcg-isotp-v1-0-681ef8d8c2c9%40hartkopp.net
^ permalink raw reply [flat|nested] 38+ messages in thread
* [PATCH can-next 14/22] can: isotp: ignore invalid SF and FF frames during a reception
2026-11-26 21:05 [PATCH can-next 00/22] can: memcg accounting, CAN_ISOTP fixes and cleanups Oliver Hartkopp
` (12 preceding siblings ...)
2026-11-26 21:05 ` [PATCH can-next 13/22] can: isotp: do not send FC.OVFLW in listen mode Oliver Hartkopp
@ 2026-11-26 21:05 ` Oliver Hartkopp
2026-11-28 10:20 ` netdev-bot+sashiko
2026-11-26 21:05 ` [PATCH can-next 15/22] can: isotp: drop inline keyword, let the compiler decide Oliver Hartkopp
` (8 subsequent siblings)
22 siblings, 1 reply; 38+ messages in thread
From: Oliver Hartkopp @ 2026-11-26 21:05 UTC (permalink / raw)
To: linux-can; +Cc: Marc Kleine-Budde, Oliver Hartkopp
isotp_rcv_sf() and isotp_rcv_ff() stop the rx timeout and set the rx
state to ISOTP_IDLE before the received frame is checked. So an invalid
SF or FF which has to be ignored (e.g. SF_DL 0 or a FF with a CAN_DL
below its LL_DL) terminated an ongoing reception silently.
Check the SF/FF first and terminate an ongoing reception only for a
valid SF/FF. isotp_rcv_ff() reads the LL_DL and FF_DL into local
variables to keep the data of an ongoing reception for invalid FFs.
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
---
net/can/isotp.c | 46 ++++++++++++++++++++++++++--------------------
1 file changed, 26 insertions(+), 20 deletions(-)
diff --git a/net/can/isotp.c b/net/can/isotp.c
index f6801c18172c..39bae46701cc 100644
--- a/net/can/isotp.c
+++ b/net/can/isotp.c
@@ -547,16 +547,18 @@ static int isotp_rcv_sf(struct sock *sk, struct canfd_frame *cf, int pcilen,
struct sk_buff *skb, int len)
{
struct isotp_sock *so = isotp_sk(sk);
struct sk_buff *nskb;
- hrtimer_cancel(&so->rxtimer);
- WRITE_ONCE(so->rx.state, ISOTP_IDLE);
-
+ /* ignore invalid SFs (ongoing reception is not affected) */
if (!len || len > cf->len - pcilen)
return 1;
+ /* terminate a potentially ongoing reception */
+ hrtimer_cancel(&so->rxtimer);
+ WRITE_ONCE(so->rx.state, ISOTP_IDLE);
+
if ((so->opt.flags & ISOTP_CHECK_PADDING) &&
check_pad(so, cf, pcilen + len, so->opt.rxpad_content)) {
/* malformed PDU - report 'not a data message' */
sk->sk_err = EBADMSG;
if (!sock_flag(sk, SOCK_DEAD))
@@ -577,53 +579,57 @@ static int isotp_rcv_sf(struct sock *sk, struct canfd_frame *cf, int pcilen,
}
static int isotp_rcv_ff(struct sock *sk, struct canfd_frame *cf, int ae)
{
struct isotp_sock *so = isotp_sk(sk);
- unsigned int sf_max;
+ unsigned int ll_dl, len, sf_max;
int i;
int ff_pci_sz;
- hrtimer_cancel(&so->rxtimer);
- WRITE_ONCE(so->rx.state, ISOTP_IDLE);
-
/* get the used sender LL_DL from the (first) CAN frame data length */
- so->rx.ll_dl = padlen(cf->len);
+ ll_dl = padlen(cf->len);
/* the first frame has to use the entire frame up to LL_DL length */
- if (cf->len != so->rx.ll_dl)
+ if (cf->len != ll_dl)
return 1;
/* get the FF_DL */
- so->rx.len = (cf->data[ae] & 0x0F) << 8;
- so->rx.len += cf->data[ae + 1];
+ len = (cf->data[ae] & 0x0F) << 8;
+ len += cf->data[ae + 1];
/* Check for FF_DL escape sequence supporting 32 bit PDU length */
- if (so->rx.len) {
+ if (len) {
ff_pci_sz = FF_PCI_SZ12;
} else {
/* FF_DL = 0 => get real length from next 4 bytes */
- so->rx.len = cf->data[ae + 2] << 24;
- so->rx.len += cf->data[ae + 3] << 16;
- so->rx.len += cf->data[ae + 4] << 8;
- so->rx.len += cf->data[ae + 5];
+ len = cf->data[ae + 2] << 24;
+ len += cf->data[ae + 3] << 16;
+ len += cf->data[ae + 4] << 8;
+ len += cf->data[ae + 5];
ff_pci_sz = FF_PCI_SZ32;
/* unneeded escape sequence => ignore PDU according to spec */
- if (so->rx.len <= MAX_12BIT_PDU_SIZE)
+ if (len <= MAX_12BIT_PDU_SIZE)
return 1;
}
/* the PDU must not fit into a SF (FF_DLmin) */
- if (so->rx.ll_dl == CAN_MAX_DLEN)
+ if (ll_dl == CAN_MAX_DLEN)
sf_max = CAN_MAX_DLEN - SF_PCI_SZ4 - ae;
else
- sf_max = so->rx.ll_dl - SF_PCI_SZ8 - ae;
+ sf_max = ll_dl - SF_PCI_SZ8 - ae;
- if (so->rx.len <= sf_max)
+ if (len <= sf_max)
return 1;
+ /* valid FF => terminate a potentially ongoing reception */
+ hrtimer_cancel(&so->rxtimer);
+ WRITE_ONCE(so->rx.state, ISOTP_IDLE);
+
+ so->rx.ll_dl = ll_dl;
+ so->rx.len = len;
+
/* PDU size > default => try max_pdu_size
*
* This buffer is not accounted to a memory cgroup: In softirq
* context the charge would either have to be forced beyond the
* limit of the cgroup or the reception would fail at the limit.
--
2.53.0
^ permalink raw reply related [flat|nested] 38+ messages in thread* Re: [PATCH can-next 14/22] can: isotp: ignore invalid SF and FF frames during a reception
2026-11-26 21:05 ` [PATCH can-next 14/22] can: isotp: ignore invalid SF and FF frames during a reception Oliver Hartkopp
@ 2026-11-28 10:20 ` netdev-bot+sashiko
0 siblings, 0 replies; 38+ messages in thread
From: netdev-bot+sashiko @ 2026-11-28 10:20 UTC (permalink / raw)
To: socketcan
Cc: linux-can, mkl, sashiko-bot, zihanx, o.rempel, yewentian395, kuba
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_rcv_sf() (net/can/isotp.c), the patch moves the
termination of an ongoing reception (hrtimer_cancel(&so->rxtimer);…
- [Low] The commit 'can: isotp: ignore invalid SF and FF frames during a
reception' fixes a real, user-visible bug, but it has no Fixes: tag…
--
can: isotp: ignore invalid SF and FF frames during a reception
This commit moves the rx timer cancel and the ISOTP_IDLE state reset in
isotp_rcv_sf() and isotp_rcv_ff() so they run after the frame validity
checks. An invalid SF or FF should then no longer end an ongoing
reception. isotp_rcv_ff() now parses LL_DL and FF_DL into local variables
and stores them in so->rx only after the FF has been validated.
> Check the SF/FF first and terminate an ongoing reception only for a
> valid SF/FF. isotp_rcv_ff() reads the LL_DL and FF_DL into local
> variables to keep the data of an ongoing reception for invalid FFs.
>
> Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
[Severity: Low]
Should this patch have a Fixes: tag and Cc: stable?
The hrtimer_cancel() calls that run before the validity checks in
isotp_rcv_sf() and isotp_rcv_ff() come from commit e057dd3fc20f ("can: add
ISO 15765-2:2016 transport protocol"). The WRITE_ONCE() state resets in the
same place were last changed by commit 050f010f920d ("can: isotp: fix timer
drain order, wakeup handling and tx_gen ordering").
In those kernels, any node on the bus can end an ongoing reception without
any notice. It only has to send an invalid SF (SF_DL 0) or an invalid FF
(CAN_DL != padlen(CAN_DL), FF_DL below FF_DLmin, or an unneeded 32 bit
escape). isotp_rcv_cf() then drops the remaining CFs:
if (READ_ONCE(so->rx.state) != ISOTP_WAIT_DATA)
return 0;
Because the timer has been cancelled, no ETIMEDOUT is reported for the lost
PDU either. Earlier isotp fixes such as 050f010f920d had both Fixes: and
Cc: stable.
> diff --git a/net/can/isotp.c b/net/can/isotp.c
> index f6801c18172cf..39bae46701cc3 100644
> --- a/net/can/isotp.c
> +++ b/net/can/isotp.c
> @@ -549,12 +549,14 @@ static int isotp_rcv_sf(struct sock *sk, struct canfd_frame *cf, int pcilen,
> struct isotp_sock *so = isotp_sk(sk);
> struct sk_buff *nskb;
>
> - hrtimer_cancel(&so->rxtimer);
> - WRITE_ONCE(so->rx.state, ISOTP_IDLE);
> -
> + /* ignore invalid SFs (ongoing reception is not affected) */
> if (!len || len > cf->len - pcilen)
> return 1;
>
> + /* terminate a potentially ongoing reception */
> + hrtimer_cancel(&so->rxtimer);
> + WRITE_ONCE(so->rx.state, ISOTP_IDLE);
> +
> if ((so->opt.flags & ISOTP_CHECK_PADDING) &&
> check_pad(so, cf, pcilen + len, so->opt.rxpad_content)) {
> /* malformed PDU - report 'not a data message' */
[Severity: Medium]
Has the SF been fully validated at this point?
When CAN_ISOTP_CHK_PAD_LEN or CAN_ISOTP_CHK_PAD_DATA is set, an SF with a
valid SF_DL but wrong padding is still rejected as malformed by the
check_pad() test. That test now runs after the ongoing reception has
already been aborted.
Take a socket that has received a valid FF, so rx.state is ISOTP_WAIT_DATA
and the rx timer is running. An SF with a valid SF_DL and bad padding then
arrives:
isotp_rcv()
isotp_rcv_sf()
SF_DL length check passes
hrtimer_cancel(&so->rxtimer)
WRITE_ONCE(so->rx.state, ISOTP_IDLE)
check_pad() fails -> sk->sk_err = EBADMSG, return
isotp_rcv_cf() then drops the remaining CFs of the interrupted PDU, because
rx.state is no longer ISOTP_WAIT_DATA. Since the timer was cancelled, no
ETIMEDOUT is reported for that PDU. The application only sees EBADMSG for
the SF, which was never delivered.
This seems to contradict the new comment "ignore invalid SFs (ongoing
reception is not affected)". It also contradicts the commit message, which
says "terminate an ongoing reception only for a valid SF/FF".
Should the termination also move after the padding check?
The ordering stays the same later in the series, after these functions
are changed to return void and check_pad() is renamed to chk_pad_fail().
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261126-getsockopt-memcg-isotp-v1-0-681ef8d8c2c9%40hartkopp.net
^ permalink raw reply [flat|nested] 38+ messages in thread
* [PATCH can-next 15/22] can: isotp: drop inline keyword, let the compiler decide
2026-11-26 21:05 [PATCH can-next 00/22] can: memcg accounting, CAN_ISOTP fixes and cleanups Oliver Hartkopp
` (13 preceding siblings ...)
2026-11-26 21:05 ` [PATCH can-next 14/22] can: isotp: ignore invalid SF and FF frames during a reception Oliver Hartkopp
@ 2026-11-26 21:05 ` Oliver Hartkopp
2026-11-26 21:05 ` [PATCH can-next 16/22] can: isotp: rename rx_lock as it has become state machine lock Oliver Hartkopp
` (7 subsequent siblings)
22 siblings, 0 replies; 38+ messages in thread
From: Oliver Hartkopp @ 2026-11-26 21:05 UTC (permalink / raw)
To: linux-can; +Cc: Marc Kleine-Budde, Oliver Hartkopp
Modern kernel style avoids forcing inlining via the inline keyword on
static functions - the compiler heuristics decide better on their own.
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
---
net/can/isotp.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/can/isotp.c b/net/can/isotp.c
index 39bae46701cc..fc03dedb0c86 100644
--- a/net/can/isotp.c
+++ b/net/can/isotp.c
@@ -247,11 +247,11 @@ static bool isotp_tx_gen_done(struct isotp_sock *so, u32 gen)
return state == ISOTP_IDLE || state == ISOTP_SHUTDOWN ||
READ_ONCE(so->tx_gen) != gen;
}
-static inline struct isotp_sock *isotp_sk(const struct sock *sk)
+static struct isotp_sock *isotp_sk(const struct sock *sk)
{
return (struct isotp_sock *)sk;
}
static u32 isotp_bc_flags(struct isotp_sock *so)
--
2.53.0
^ permalink raw reply related [flat|nested] 38+ messages in thread* [PATCH can-next 16/22] can: isotp: rename rx_lock as it has become state machine lock
2026-11-26 21:05 [PATCH can-next 00/22] can: memcg accounting, CAN_ISOTP fixes and cleanups Oliver Hartkopp
` (14 preceding siblings ...)
2026-11-26 21:05 ` [PATCH can-next 15/22] can: isotp: drop inline keyword, let the compiler decide Oliver Hartkopp
@ 2026-11-26 21:05 ` Oliver Hartkopp
2026-11-28 10:20 ` netdev-bot+sashiko
2026-11-26 21:05 ` [PATCH can-next 17/22] can: isotp: introduce isotp_invalid_canid() to verify proper CAN-IDs Oliver Hartkopp
` (6 subsequent siblings)
22 siblings, 1 reply; 38+ messages in thread
From: Oliver Hartkopp @ 2026-11-26 21:05 UTC (permalink / raw)
To: linux-can; +Cc: Marc Kleine-Budde, Oliver Hartkopp
rx_lock has been used to lock some receive path functionalities.
With the latest changes the semantic has been extended as a full
state machine locking primitive so give it a proper name sm_lock.
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
---
net/can/isotp.c | 52 ++++++++++++++++++++++++++--------------------------
1 file changed, 26 insertions(+), 26 deletions(-)
diff --git a/net/can/isotp.c b/net/can/isotp.c
index fc03dedb0c86..8e8f838160af 100644
--- a/net/can/isotp.c
+++ b/net/can/isotp.c
@@ -180,11 +180,11 @@ struct isotp_sock {
u32 tx_gen; /* transfer generation, increased per new tx transfer */
u32 tx_result[ISOTP_TX_RESULT_SLOTS]; /* per-generation result slots */
struct tpcon rx, tx;
struct list_head notifier;
wait_queue_head_t wait;
- spinlock_t rx_lock; /* protect single thread state machine */
+ spinlock_t sm_lock; /* protect single thread state machine */
struct mutex conf_lock; /* protects bind and sockopts */
};
static LIST_HEAD(isotp_notifier_list);
static DEFINE_SPINLOCK(isotp_notifier_lock);
@@ -802,11 +802,11 @@ static void isotp_rcv(struct sk_buff *skb, void *data)
/* Make sure the state changes and data structures stay consistent at
* CAN frame reception time. This locking is not needed in real world
* use cases but the inconsistency can be triggered with syzkaller.
*/
- spin_lock(&so->rx_lock);
+ spin_lock(&so->sm_lock);
if (so->opt.flags & CAN_ISOTP_HALF_DUPLEX) {
/* check rx/tx path half duplex expectations */
if ((READ_ONCE(so->tx.state) != ISOTP_IDLE &&
n_pci_type != N_PCI_FC) ||
@@ -861,11 +861,11 @@ static void isotp_rcv(struct sk_buff *skb, void *data)
isotp_rcv_cf(sk, cf, ae, skb);
break;
}
out_unlock:
- spin_unlock(&so->rx_lock);
+ spin_unlock(&so->sm_lock);
}
static void isotp_fill_dataframe(struct canfd_frame *cf, struct isotp_sock *so,
int ae, int off)
{
@@ -1013,14 +1013,14 @@ static void isotp_rcv_echo(struct sk_buff *skb, void *data)
return;
if (WARN_ON_ONCE(!csx))
return;
- /* unlike isotp_rcv_fc()/isotp_rcv_cf(), not already under so->rx_lock
+ /* unlike isotp_rcv_fc()/isotp_rcv_cf(), not already under so->sm_lock
* (no isotp_rcv() caller here), so take it ourselves
*/
- spin_lock(&so->rx_lock);
+ spin_lock(&so->sm_lock);
/* so->cfecho may since belong to a new transfer; recheck under lock */
if (READ_ONCE(so->cfecho) != csx->can_skb_uid)
goto out_unlock;
@@ -1028,11 +1028,11 @@ static void isotp_rcv_echo(struct sk_buff *skb, void *data)
hrtimer_cancel(&so->echotimer);
/* local echo skb with consecutive frame has been consumed */
WRITE_ONCE(so->cfecho, 0);
- /* claiming a transfer also takes so->rx_lock, so a plain recheck
+ /* claiming a transfer also takes so->sm_lock, so a plain recheck
* is enough: so->tx.state can't have flipped to ISOTP_SENDING for
* a new claim while we're still in here
*/
if (READ_ONCE(so->tx.state) != ISOTP_SENDING)
goto out_unlock;
@@ -1066,17 +1066,17 @@ static void isotp_rcv_echo(struct sk_buff *skb, void *data)
/* start timer to send next consecutive frame with correct delay */
hrtimer_start(&so->txfrtimer, so->tx_gap, HRTIMER_MODE_REL_SOFT);
out_unlock:
- spin_unlock(&so->rx_lock);
+ spin_unlock(&so->sm_lock);
}
/* isotp_tx_timeout: we did not get any flow control or echo frame in time
*
* Shared by so->txtimer's and so->echotimer's callbacks. Both timers get
- * cancelled under so->rx_lock elsewhere, so this must stay lock-free.
+ * cancelled under so->sm_lock elsewhere, so this must stay lock-free.
*
* tx.state is acquired before tx_gen. Common sequence in isotp_tx_gen_done().
* cmpxchg() only orders itself, not the two preceding loads.
*/
static enum hrtimer_restart isotp_tx_timeout(struct isotp_sock *so)
@@ -1161,19 +1161,19 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
int err;
if (!READ_ONCE(so->bound) || READ_ONCE(so->tx.state) == ISOTP_SHUTDOWN)
return -EADDRNOTAVAIL;
- /* claim the socket under so->rx_lock: this serializes the claim
+ /* claim the socket under so->sm_lock: this serializes the claim
* with the RX path and with sendmsg()'s own error paths below, so
* none of them can ever see a transfer mid-claim
*/
for (;;) {
- spin_lock_bh(&so->rx_lock);
+ spin_lock_bh(&so->sm_lock);
if (READ_ONCE(so->tx.state) == ISOTP_IDLE)
break;
- spin_unlock_bh(&so->rx_lock);
+ spin_unlock_bh(&so->sm_lock);
/* we do not support multiple buffers - for now */
if (msg->msg_flags & MSG_DONTWAIT)
return -EAGAIN;
@@ -1198,11 +1198,11 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
isotp_set_tx_result(so, my_gen, ECOMM); /* prevent stale slot matching */
WRITE_ONCE(so->tx_gen, my_gen);
smp_wmb(); /* see smp_load_acquire() in isotp_tx_[timeout|gen_done] */
WRITE_ONCE(so->tx.state, ISOTP_SENDING);
WRITE_ONCE(so->cfecho, 0);
- spin_unlock_bh(&so->rx_lock);
+ spin_unlock_bh(&so->sm_lock);
/* so->bound is only checked once above - a wakeup may have
* unbound/rebound the socket meanwhile => recheck
*/
if (!READ_ONCE(so->bound)) {
@@ -1335,26 +1335,26 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
/* no CF echo tag for isotp_rcv_echo() (FF-mode) */
WRITE_ONCE(so->cfecho, 0);
}
}
- spin_lock_bh(&so->rx_lock);
+ spin_lock_bh(&so->sm_lock);
if (READ_ONCE(so->tx.state) == ISOTP_SHUTDOWN) {
/* isotp_release() has since taken over and already drained
* our timers - don't send into a socket that's going away
*/
- spin_unlock_bh(&so->rx_lock);
+ spin_unlock_bh(&so->sm_lock);
kfree_skb(skb);
dev_put(dev);
wake_up_interruptible(&so->wait);
return -EADDRNOTAVAIL;
}
/* WAIT_FIRST_FC for standard FF, else stays ISOTP_SENDING */
WRITE_ONCE(so->tx.state, new_state);
hrtimer_start(tx_hrt, ktime_set(hrtimer_sec, so->frame_txtime),
HRTIMER_MODE_REL_SOFT);
- spin_unlock_bh(&so->rx_lock);
+ spin_unlock_bh(&so->sm_lock);
/* send the first or only CAN frame */
cf->flags = so->ll.tx_flags;
skb->dev = dev;
@@ -1363,18 +1363,18 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
dev_put(dev);
if (err) {
pr_notice_once("can-isotp: %s: can_send_ret %pe\n",
__func__, ERR_PTR(err));
- spin_lock_bh(&so->rx_lock);
+ spin_lock_bh(&so->sm_lock);
/* new transfer already claimed by a concurrent completion,
* timeout or sendmsg() while we were stuck in can_send()?
*/
if (READ_ONCE(so->tx_gen) != my_gen) {
/* don't touch timers and state of the new transfer */
- spin_unlock_bh(&so->rx_lock);
+ spin_unlock_bh(&so->sm_lock);
return err;
}
/* no transmission -> no timeout monitoring */
hrtimer_cancel(tx_hrt);
@@ -1413,34 +1413,34 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
return size;
err_out_drop:
/* claimed but nothing sent yet - no timer to cancel */
- spin_lock_bh(&so->rx_lock);
+ spin_lock_bh(&so->sm_lock);
goto err_out_drop_locked;
err_event_drop:
/* interrupted or shut down while waiting on our own transfer */
- spin_lock_bh(&so->rx_lock);
+ spin_lock_bh(&so->sm_lock);
/* new transfer already started by concurrent sendmsg()? */
if (READ_ONCE(so->tx_gen) != my_gen) {
/* don't touch timers and states of the new transfer */
- spin_unlock_bh(&so->rx_lock);
+ spin_unlock_bh(&so->sm_lock);
return err;
}
hrtimer_cancel(&so->txfrtimer);
hrtimer_cancel(&so->txtimer);
hrtimer_cancel(&so->echotimer);
err_out_drop_locked:
- /* release the claim; so->rx_lock still held from above */
+ /* release the claim; so->sm_lock still held from above */
WRITE_ONCE(so->cfecho, 0);
/* only claim to IDLE if isotp_release() has not taken over */
if (READ_ONCE(so->tx.state) != ISOTP_SHUTDOWN)
WRITE_ONCE(so->tx.state, ISOTP_IDLE);
- spin_unlock_bh(&so->rx_lock);
+ spin_unlock_bh(&so->sm_lock);
wake_up_interruptible(&so->wait);
return err;
}
@@ -1506,17 +1506,17 @@ static int isotp_release(struct socket *sock)
while (READ_ONCE(so->tx.state) != ISOTP_IDLE &&
wait_event_interruptible(so->wait,
READ_ONCE(so->tx.state) == ISOTP_IDLE) == 0)
;
- /* claim the socket under so->rx_lock like sendmsg() does, so its
+ /* claim the socket under so->sm_lock like sendmsg() does, so its
* claim can't race the forced ISOTP_SHUTDOWN below; force it
* unconditionally, even when a signal cut the wait above short
*/
- spin_lock_bh(&so->rx_lock);
+ spin_lock_bh(&so->sm_lock);
WRITE_ONCE(so->tx.state, ISOTP_SHUTDOWN);
- spin_unlock_bh(&so->rx_lock);
+ spin_unlock_bh(&so->sm_lock);
WRITE_ONCE(so->rx.state, ISOTP_IDLE);
/* forced SHUTDOWN may have skipped IDLE (gave up on a signal) */
wake_up_interruptible(&so->wait);
@@ -2105,11 +2105,11 @@ static int isotp_init(struct sock *sk)
CLOCK_MONOTONIC, HRTIMER_MODE_REL_SOFT);
hrtimer_setup(&so->txfrtimer, isotp_txfr_timer_handler,
CLOCK_MONOTONIC, HRTIMER_MODE_REL_SOFT);
init_waitqueue_head(&so->wait);
- spin_lock_init(&so->rx_lock);
+ spin_lock_init(&so->sm_lock);
spin_lock(&isotp_notifier_lock);
list_add_tail(&so->notifier, &isotp_notifier_list);
spin_unlock(&isotp_notifier_lock);
--
2.53.0
^ permalink raw reply related [flat|nested] 38+ messages in thread* Re: [PATCH can-next 16/22] can: isotp: rename rx_lock as it has become state machine lock
2026-11-26 21:05 ` [PATCH can-next 16/22] can: isotp: rename rx_lock as it has become state machine lock Oliver Hartkopp
@ 2026-11-28 10:20 ` netdev-bot+sashiko
0 siblings, 0 replies; 38+ messages in thread
From: netdev-bot+sashiko @ 2026-11-28 10:20 UTC (permalink / raw)
To: socketcan
Cc: linux-can, mkl, sashiko-bot, zihanx, o.rempel, yewentian395, kuba
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The rename leaves one comment that still describes the old,
narrower purpose of the lock.
--
can: isotp: rename rx_lock as it has become state machine lock
This renames the isotp_sock spinlock from rx_lock to sm_lock. The lock now
serializes the whole tx/rx state machine, not just parts of the receive
path. All lock call sites and the comments that mention the lock are
updated.
> diff --git a/net/can/isotp.c b/net/can/isotp.c
> index fc03dedb0c86c..8e8f838160aff 100644
> --- a/net/can/isotp.c
> +++ b/net/can/isotp.c
[ ... ]
> @@ -804,7 +804,7 @@ static void isotp_rcv(struct sk_buff *skb, void *data)
> * CAN frame reception time. This locking is not needed in real world
> * use cases but the inconsistency can be triggered with syzkaller.
> */
> - spin_lock(&so->rx_lock);
> + spin_lock(&so->sm_lock);
[Severity: Low]
This isn't a bug, but should this comment in isotp_rcv() be updated along
with the rename?
The commit message describes sm_lock as "a full state machine locking
primitive". This comment still says the locking "is not needed in real
world use cases".
Other comments touched by this patch depend on the RX path taking the
lock. In isotp_sendmsg():
/* claim the socket under so->sm_lock: this serializes the claim
* with the RX path and with sendmsg()'s own error paths below, so
* none of them can ever see a transfer mid-claim
*/
And in isotp_rcv_echo():
/* claiming a transfer also takes so->sm_lock, so a plain recheck
* is enough: so->tx.state can't have flipped to ISOTP_SENDING for
* a new claim while we're still in here
*/
isotp_release() also forces ISOTP_SHUTDOWN under sm_lock so that it
can't race a sendmsg() claim. The isotp_tx_timeout() comment says the
timers get cancelled under sm_lock.
This serialization also matters in normal use. Softirq processing in
isotp_rcv()->isotp_rcv_fc() and the half duplex check read tx.state while
isotp_sendmsg() may be claiming a new transfer in process context, for
example when a late flow control frame arrives.
As far as I can tell, the comment is still unchanged at the end of the
series, after "can: isotp: introduce CAN_ISOTP_MIN_TX_DL".
Could the comment be reworded so it doesn't suggest the RX path locking
is optional?
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261126-getsockopt-memcg-isotp-v1-0-681ef8d8c2c9%40hartkopp.net
^ permalink raw reply [flat|nested] 38+ messages in thread
* [PATCH can-next 17/22] can: isotp: introduce isotp_invalid_canid() to verify proper CAN-IDs
2026-11-26 21:05 [PATCH can-next 00/22] can: memcg accounting, CAN_ISOTP fixes and cleanups Oliver Hartkopp
` (15 preceding siblings ...)
2026-11-26 21:05 ` [PATCH can-next 16/22] can: isotp: rename rx_lock as it has become state machine lock Oliver Hartkopp
@ 2026-11-26 21:05 ` Oliver Hartkopp
2026-11-26 21:06 ` [PATCH can-next 18/22] can: isotp: rename variable for the required content length Oliver Hartkopp
` (5 subsequent siblings)
22 siblings, 0 replies; 38+ messages in thread
From: Oliver Hartkopp @ 2026-11-26 21:05 UTC (permalink / raw)
To: linux-can; +Cc: Marc Kleine-Budde, Oliver Hartkopp
Move duplicated code into a separate function as preparation for the
CAN XL support which will need this functionality too.
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
---
net/can/isotp.c | 41 ++++++++++++++++++++++-------------------
1 file changed, 22 insertions(+), 19 deletions(-)
diff --git a/net/can/isotp.c b/net/can/isotp.c
index 8e8f838160af..1f8d767b603d 100644
--- a/net/can/isotp.c
+++ b/net/can/isotp.c
@@ -1573,10 +1573,27 @@ static int isotp_release(struct socket *sock)
sock_put(sk);
return 0;
}
+static bool isotp_invalid_canid(canid_t canid)
+{
+ canid_t sanitized_id = canid;
+
+ /* sanitize CAN identifier */
+ if (sanitized_id & CAN_EFF_FLAG)
+ sanitized_id &= (CAN_EFF_FLAG | CAN_EFF_MASK);
+ else
+ sanitized_id &= CAN_SFF_MASK;
+
+ /* give feedback on wrong CAN-ID value */
+ if (sanitized_id != canid)
+ return true;
+
+ return false;
+}
+
static int isotp_bind(struct socket *sock, struct sockaddr_unsized *uaddr, int len)
{
struct sockaddr_can *addr = (struct sockaddr_can *)uaddr;
struct sock *sk = sock->sk;
struct isotp_sock *so = isotp_sk(sk);
@@ -1591,31 +1608,17 @@ static int isotp_bind(struct socket *sock, struct sockaddr_unsized *uaddr, int l
return -EINVAL;
if (addr->can_family != AF_CAN)
return -EINVAL;
- /* sanitize tx CAN identifier */
- if (tx_id & CAN_EFF_FLAG)
- tx_id &= (CAN_EFF_FLAG | CAN_EFF_MASK);
- else
- tx_id &= CAN_SFF_MASK;
-
- /* give feedback on wrong CAN-ID value */
- if (tx_id != addr->can_addr.tp.tx_id)
+ /* check for correct tx CAN identifier */
+ if (isotp_invalid_canid(tx_id))
return -EINVAL;
- /* sanitize rx CAN identifier (if needed) */
- if (isotp_register_rxid(so)) {
- if (rx_id & CAN_EFF_FLAG)
- rx_id &= (CAN_EFF_FLAG | CAN_EFF_MASK);
- else
- rx_id &= CAN_SFF_MASK;
-
- /* give feedback on wrong CAN-ID value */
- if (rx_id != addr->can_addr.tp.rx_id)
- return -EINVAL;
- }
+ /* check for correct rx CAN identifier (if needed) */
+ if (isotp_register_rxid(so) && isotp_invalid_canid(rx_id))
+ return -EINVAL;
if (!addr->can_ifindex)
return -ENODEV;
/* so->conf_lock serializes the binding with isotp_notify() */
--
2.53.0
^ permalink raw reply related [flat|nested] 38+ messages in thread* [PATCH can-next 18/22] can: isotp: rename variable for the required content length
2026-11-26 21:05 [PATCH can-next 00/22] can: memcg accounting, CAN_ISOTP fixes and cleanups Oliver Hartkopp
` (16 preceding siblings ...)
2026-11-26 21:05 ` [PATCH can-next 17/22] can: isotp: introduce isotp_invalid_canid() to verify proper CAN-IDs Oliver Hartkopp
@ 2026-11-26 21:06 ` Oliver Hartkopp
2026-11-26 21:06 ` [PATCH can-next 19/22] can: isotp: rename checkpad functions returning bool values Oliver Hartkopp
` (4 subsequent siblings)
22 siblings, 0 replies; 38+ messages in thread
From: Oliver Hartkopp @ 2026-11-26 21:06 UTC (permalink / raw)
To: linux-can; +Cc: Marc Kleine-Budde, Oliver Hartkopp
Rename the meaningless 'num' variable to 'reqlen' to simplify the review
for the CAN XL integration.
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
---
net/can/isotp.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/net/can/isotp.c b/net/can/isotp.c
index 1f8d767b603d..61021d7052d4 100644
--- a/net/can/isotp.c
+++ b/net/can/isotp.c
@@ -869,17 +869,17 @@ static void isotp_rcv(struct sk_buff *skb, void *data)
static void isotp_fill_dataframe(struct canfd_frame *cf, struct isotp_sock *so,
int ae, int off)
{
int pcilen = N_PCI_SZ + ae + off;
int space = so->tx.ll_dl - pcilen;
- int num = min_t(int, so->tx.len - so->tx.idx, space);
+ int reqlen = min_t(int, so->tx.len - so->tx.idx, space);
int i;
cf->can_id = so->txid;
- cf->len = num + pcilen;
+ cf->len = reqlen + pcilen;
- if (num < space) {
+ if (reqlen < space) {
if (so->opt.flags & CAN_ISOTP_TX_PADDING) {
/* user requested padding */
cf->len = padlen(cf->len);
memset(cf->data, so->opt.txpad_content, cf->len);
} else if (cf->len > CAN_MAX_DLEN) {
@@ -888,11 +888,11 @@ static void isotp_fill_dataframe(struct canfd_frame *cf, struct isotp_sock *so,
memset(cf->data, CAN_ISOTP_DEFAULT_PAD_CONTENT,
cf->len);
}
}
- for (i = 0; i < num; i++)
+ for (i = 0; i < reqlen; i++)
cf->data[pcilen + i] = so->tx.buf[so->tx.idx++];
if (ae)
cf->data[0] = so->opt.ext_address;
}
--
2.53.0
^ permalink raw reply related [flat|nested] 38+ messages in thread* [PATCH can-next 19/22] can: isotp: rename checkpad functions returning bool values
2026-11-26 21:05 [PATCH can-next 00/22] can: memcg accounting, CAN_ISOTP fixes and cleanups Oliver Hartkopp
` (17 preceding siblings ...)
2026-11-26 21:06 ` [PATCH can-next 18/22] can: isotp: rename variable for the required content length Oliver Hartkopp
@ 2026-11-26 21:06 ` Oliver Hartkopp
2026-11-26 21:06 ` [PATCH can-next 20/22] can: isotp: change return type of functions to void Oliver Hartkopp
` (3 subsequent siblings)
22 siblings, 0 replies; 38+ messages in thread
From: Oliver Hartkopp @ 2026-11-26 21:06 UTC (permalink / raw)
To: linux-can; +Cc: Marc Kleine-Budde, Oliver Hartkopp
The checkpad functions return true when failing. Rename the functions
to reflect their functionality together with a conversion to bool
return values.
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
---
net/can/isotp.c | 27 ++++++++++++++-------------
1 file changed, 14 insertions(+), 13 deletions(-)
diff --git a/net/can/isotp.c b/net/can/isotp.c
index 61021d7052d4..31acff7c33aa 100644
--- a/net/can/isotp.c
+++ b/net/can/isotp.c
@@ -393,12 +393,12 @@ static u8 padlen(u8 datalen)
return 64;
return plen[datalen];
}
-/* check for length optimization and return 1/true when the check fails */
-static int check_optimized(struct canfd_frame *cf, int start_index)
+/* check for length optimization and return true when the check fails */
+static bool chk_optimized_fail(struct canfd_frame *cf, int start_index)
{
/* for CAN_DL <= 8 the start_index is equal to the CAN_DL as the
* padding would start at this point. E.g. if the padding would
* start at cf.data[7] cf->len has to be 7 to be optimal.
* Note: The data[] index starts with zero.
@@ -413,37 +413,38 @@ static int check_optimized(struct canfd_frame *cf, int start_index)
* point the padlen(cf->len) is always equal to cf->len.
*/
return (cf->len != padlen(start_index));
}
-/* check padding and return 1/true when the check fails */
-static int check_pad(struct isotp_sock *so, struct canfd_frame *cf,
- int start_index, u8 content)
+/* check padding and return true when the check fails */
+static bool chk_pad_fail(struct isotp_sock *so, struct canfd_frame *cf,
+ int start_index, u8 content)
{
int i;
/* no RX_PADDING value => check length of optimized frame length */
if (!(so->opt.flags & CAN_ISOTP_RX_PADDING)) {
if (so->opt.flags & CAN_ISOTP_CHK_PAD_LEN)
- return check_optimized(cf, start_index);
+ return chk_optimized_fail(cf, start_index);
/* no valid test against empty value => ignore frame */
- return 1;
+ return true;
}
/* check datalength of correctly padded CAN frame */
if ((so->opt.flags & CAN_ISOTP_CHK_PAD_LEN) &&
cf->len != padlen(cf->len))
- return 1;
+ return true;
/* check padding content */
if (so->opt.flags & CAN_ISOTP_CHK_PAD_DATA) {
for (i = start_index; i < cf->len; i++)
if (cf->data[i] != content)
- return 1;
+ return true;
}
- return 0;
+
+ return false;
}
static void isotp_send_cframe(struct isotp_sock *so);
static int isotp_rcv_fc(struct isotp_sock *so, struct canfd_frame *cf, int ae)
@@ -464,11 +465,11 @@ static int isotp_rcv_fc(struct isotp_sock *so, struct canfd_frame *cf, int ae)
READ_ONCE(so->tx.state) != ISOTP_WAIT_FIRST_FC)
return 1;
if ((cf->len < ae + FC_CONTENT_SZ) ||
((so->opt.flags & ISOTP_CHECK_PADDING) &&
- check_pad(so, cf, ae + FC_CONTENT_SZ, so->opt.rxpad_content))) {
+ chk_pad_fail(so, cf, ae + FC_CONTENT_SZ, so->opt.rxpad_content))) {
/* malformed PDU - report 'not a data message' */
sk->sk_err = EBADMSG;
if (!sock_flag(sk, SOCK_DEAD))
sk_error_report(sk);
@@ -556,11 +557,11 @@ static int isotp_rcv_sf(struct sock *sk, struct canfd_frame *cf, int pcilen,
/* terminate a potentially ongoing reception */
hrtimer_cancel(&so->rxtimer);
WRITE_ONCE(so->rx.state, ISOTP_IDLE);
if ((so->opt.flags & ISOTP_CHECK_PADDING) &&
- check_pad(so, cf, pcilen + len, so->opt.rxpad_content)) {
+ chk_pad_fail(so, cf, pcilen + len, so->opt.rxpad_content)) {
/* malformed PDU - report 'not a data message' */
sk->sk_err = EBADMSG;
if (!sock_flag(sk, SOCK_DEAD))
sk_error_report(sk);
return 1;
@@ -730,11 +731,11 @@ static int isotp_rcv_cf(struct sock *sk, struct canfd_frame *cf, int ae,
if (so->rx.idx >= so->rx.len) {
/* we are done */
WRITE_ONCE(so->rx.state, ISOTP_IDLE);
if ((so->opt.flags & ISOTP_CHECK_PADDING) &&
- check_pad(so, cf, i + 1, so->opt.rxpad_content)) {
+ chk_pad_fail(so, cf, i + 1, so->opt.rxpad_content)) {
/* malformed PDU - report 'not a data message' */
sk->sk_err = EBADMSG;
if (!sock_flag(sk, SOCK_DEAD))
sk_error_report(sk);
return 1;
--
2.53.0
^ permalink raw reply related [flat|nested] 38+ messages in thread* [PATCH can-next 20/22] can: isotp: change return type of functions to void
2026-11-26 21:05 [PATCH can-next 00/22] can: memcg accounting, CAN_ISOTP fixes and cleanups Oliver Hartkopp
` (18 preceding siblings ...)
2026-11-26 21:06 ` [PATCH can-next 19/22] can: isotp: rename checkpad functions returning bool values Oliver Hartkopp
@ 2026-11-26 21:06 ` Oliver Hartkopp
2026-11-28 10:20 ` netdev-bot+sashiko
2026-11-26 21:06 ` [PATCH can-next 21/22] can: isotp: rename pointer in isotp_rcv() prototype Oliver Hartkopp
` (2 subsequent siblings)
22 siblings, 1 reply; 38+ messages in thread
From: Oliver Hartkopp @ 2026-11-26 21:06 UTC (permalink / raw)
To: linux-can; +Cc: Marc Kleine-Budde, Oliver Hartkopp
The return values of some functions have never been used and needed.
Make those functions void to remove unused return values.
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
---
net/can/isotp.c | 77 ++++++++++++++++++++++++++++++---------------------------
1 file changed, 41 insertions(+), 36 deletions(-)
diff --git a/net/can/isotp.c b/net/can/isotp.c
index 31acff7c33aa..a9182588aeb7 100644
--- a/net/can/isotp.c
+++ b/net/can/isotp.c
@@ -284,37 +284,37 @@ static enum hrtimer_restart isotp_rx_timer_handler(struct hrtimer *hrtimer)
}
return HRTIMER_NORESTART;
}
-static int isotp_send_fc(struct sock *sk, int ae, u8 flowstatus)
+static void isotp_send_fc(struct sock *sk, int ae, u8 flowstatus)
{
struct net_device *dev;
struct sk_buff *nskb;
struct can_skb_ext *csx;
struct canfd_frame *ncf;
struct isotp_sock *so = isotp_sk(sk);
int can_send_ret;
/* no creation of flow control frames in listen mode */
if (so->opt.flags & CAN_ISOTP_LISTEN_MODE)
- return 0;
+ return;
nskb = alloc_skb(so->ll.mtu, gfp_any());
if (!nskb)
- return 1;
+ return;
csx = can_skb_ext_add(nskb);
if (!csx) {
kfree_skb(nskb);
- return 1;
+ return;
}
dev = dev_get_by_index(sock_net(sk), so->ifindex);
if (!dev) {
kfree_skb(nskb);
- return 1;
+ return;
}
csx->can_iif = dev->ifindex;
nskb->dev = dev;
can_skb_set_owner(nskb, sk);
@@ -355,11 +355,12 @@ static int isotp_send_fc(struct sock *sk, int ae, u8 flowstatus)
/* start rx timeout watchdog */
hrtimer_start(&so->rxtimer,
ktime_set(ISOTP_FC_TIMEOUT, so->frame_txtime),
HRTIMER_MODE_REL_SOFT);
- return 0;
+
+ return;
}
static void isotp_rcv_skb(struct sk_buff *skb, struct sock *sk)
{
struct sockaddr_can *addr = (struct sockaddr_can *)skb->cb;
@@ -445,27 +446,27 @@ static bool chk_pad_fail(struct isotp_sock *so, struct canfd_frame *cf,
return false;
}
static void isotp_send_cframe(struct isotp_sock *so);
-static int isotp_rcv_fc(struct isotp_sock *so, struct canfd_frame *cf, int ae)
+static void isotp_rcv_fc(struct isotp_sock *so, struct canfd_frame *cf, int ae)
{
struct sock *sk = &so->sk;
int tx_err = EBADMSG; /* default for unknown FC status */
if (READ_ONCE(so->tx.state) != ISOTP_WAIT_FC &&
READ_ONCE(so->tx.state) != ISOTP_WAIT_FIRST_FC)
- return 0;
+ return;
hrtimer_cancel(&so->txtimer);
/* isotp_tx_timeout() may have given up on this job while
* hrtimer_cancel() above waited for it to finish => recheck
*/
if (READ_ONCE(so->tx.state) != ISOTP_WAIT_FC &&
READ_ONCE(so->tx.state) != ISOTP_WAIT_FIRST_FC)
- return 1;
+ return;
if ((cf->len < ae + FC_CONTENT_SZ) ||
((so->opt.flags & ISOTP_CHECK_PADDING) &&
chk_pad_fail(so, cf, ae + FC_CONTENT_SZ, so->opt.rxpad_content))) {
/* malformed PDU - report 'not a data message' */
@@ -475,11 +476,11 @@ static int isotp_rcv_fc(struct isotp_sock *so, struct canfd_frame *cf, int ae)
isotp_set_tx_result(so, so->tx_gen, EBADMSG);
/* set to IDLE after publishing tx_result */
smp_store_release(&so->tx.state, ISOTP_IDLE);
wake_up_interruptible(&so->wait);
- return 1;
+ return;
}
/* get static/dynamic communication params from first/every FC frame */
if (READ_ONCE(so->tx.state) == ISOTP_WAIT_FIRST_FC ||
so->opt.flags & CAN_ISOTP_DYN_FC_PARMS) {
@@ -539,22 +540,23 @@ static int isotp_rcv_fc(struct isotp_sock *so, struct canfd_frame *cf, int ae)
isotp_set_tx_result(so, so->tx_gen, tx_err);
/* set to IDLE after publishing tx_result */
smp_store_release(&so->tx.state, ISOTP_IDLE);
wake_up_interruptible(&so->wait);
}
- return 0;
+
+ return;
}
-static int isotp_rcv_sf(struct sock *sk, struct canfd_frame *cf, int pcilen,
- struct sk_buff *skb, int len)
+static void isotp_rcv_sf(struct sock *sk, struct canfd_frame *cf, int pcilen,
+ struct sk_buff *skb, int len)
{
struct isotp_sock *so = isotp_sk(sk);
struct sk_buff *nskb;
/* ignore invalid SFs (ongoing reception is not affected) */
if (!len || len > cf->len - pcilen)
- return 1;
+ return;
/* terminate a potentially ongoing reception */
hrtimer_cancel(&so->rxtimer);
WRITE_ONCE(so->rx.state, ISOTP_IDLE);
@@ -562,26 +564,27 @@ static int isotp_rcv_sf(struct sock *sk, struct canfd_frame *cf, int pcilen,
chk_pad_fail(so, cf, pcilen + len, so->opt.rxpad_content)) {
/* malformed PDU - report 'not a data message' */
sk->sk_err = EBADMSG;
if (!sock_flag(sk, SOCK_DEAD))
sk_error_report(sk);
- return 1;
+ return;
}
nskb = alloc_skb(len, gfp_any());
if (!nskb)
- return 1;
+ return;
memcpy(skb_put(nskb, len), &cf->data[pcilen], len);
nskb->tstamp = skb->tstamp;
nskb->dev = skb->dev;
isotp_rcv_skb(nskb, sk);
- return 0;
+
+ return;
}
-static int isotp_rcv_ff(struct sock *sk, struct canfd_frame *cf, int ae)
+static void isotp_rcv_ff(struct sock *sk, struct canfd_frame *cf, int ae)
{
struct isotp_sock *so = isotp_sk(sk);
unsigned int ll_dl, len, sf_max;
int i;
int ff_pci_sz;
@@ -589,11 +592,11 @@ static int isotp_rcv_ff(struct sock *sk, struct canfd_frame *cf, int ae)
/* get the used sender LL_DL from the (first) CAN frame data length */
ll_dl = padlen(cf->len);
/* the first frame has to use the entire frame up to LL_DL length */
if (cf->len != ll_dl)
- return 1;
+ return;
/* get the FF_DL */
len = (cf->data[ae] & 0x0F) << 8;
len += cf->data[ae + 1];
@@ -608,21 +611,21 @@ static int isotp_rcv_ff(struct sock *sk, struct canfd_frame *cf, int ae)
len += cf->data[ae + 5];
ff_pci_sz = FF_PCI_SZ32;
/* unneeded escape sequence => ignore PDU according to spec */
if (len <= MAX_12BIT_PDU_SIZE)
- return 1;
+ return;
}
/* the PDU must not fit into a SF (FF_DLmin) */
if (ll_dl == CAN_MAX_DLEN)
sf_max = CAN_MAX_DLEN - SF_PCI_SZ4 - ae;
else
sf_max = ll_dl - SF_PCI_SZ8 - ae;
if (len <= sf_max)
- return 1;
+ return;
/* valid FF => terminate a potentially ongoing reception */
hrtimer_cancel(&so->rxtimer);
WRITE_ONCE(so->rx.state, ISOTP_IDLE);
@@ -645,11 +648,11 @@ static int isotp_rcv_ff(struct sock *sk, struct canfd_frame *cf, int ae)
}
if (so->rx.len > so->rx.buflen) {
/* send FC frame with overflow status */
isotp_send_fc(sk, ae, ISOTP_FC_OVFLW);
- return 1;
+ return;
}
/* copy the first received data bytes */
so->rx.idx = 0;
for (i = ae + ff_pci_sz; i < so->rx.ll_dl; i++)
@@ -663,41 +666,42 @@ static int isotp_rcv_ff(struct sock *sk, struct canfd_frame *cf, int ae)
hrtimer_start(&so->rxtimer, ktime_set(ISOTP_FC_TIMEOUT, 0),
HRTIMER_MODE_REL_SOFT);
/* send our first FC frame */
isotp_send_fc(sk, ae, ISOTP_FC_CTS);
- return 0;
+
+ return;
}
-static int isotp_rcv_cf(struct sock *sk, struct canfd_frame *cf, int ae,
- struct sk_buff *skb)
+static void isotp_rcv_cf(struct sock *sk, struct canfd_frame *cf, int ae,
+ struct sk_buff *skb)
{
struct isotp_sock *so = isotp_sk(sk);
struct sk_buff *nskb;
int i;
/* CFs are never longer than the FF */
if (cf->len > so->rx.ll_dl)
- return 1;
+ return;
/* CFs have usually the LL_DL length */
if (cf->len < so->rx.ll_dl) {
/* only the last CF may be shorter: drop it when the
* missing PDU bytes exceed its possible payload
*/
if (so->rx.len - so->rx.idx > cf->len - ae - N_PCI_SZ)
- return 1;
+ return;
}
if (READ_ONCE(so->rx.state) != ISOTP_WAIT_DATA)
- return 0;
+ return;
/* drop if timestamp gap is less than force_rx_stmin nano secs */
if (so->opt.flags & CAN_ISOTP_FORCE_RXSTMIN) {
if (ktime_to_ns(ktime_sub(skb->tstamp, so->lastrxcf_tstamp)) <
so->force_rx_stmin)
- return 0;
+ return;
so->lastrxcf_tstamp = skb->tstamp;
}
/* stop the rx timeout only for valid CFs (checked above) */
@@ -705,21 +709,21 @@ static int isotp_rcv_cf(struct sock *sk, struct canfd_frame *cf, int ae,
/* isotp_rx_timer_handler() may have raced us for so->rx.state
* while hrtimer_cancel() above waited for it to finish => recheck
*/
if (READ_ONCE(so->rx.state) != ISOTP_WAIT_DATA)
- return 1;
+ return;
if ((cf->data[ae] & 0x0F) != so->rx.sn) {
/* wrong sn detected - report 'illegal byte sequence' */
sk->sk_err = EILSEQ;
if (!sock_flag(sk, SOCK_DEAD))
sk_error_report(sk);
/* reset rx state */
WRITE_ONCE(so->rx.state, ISOTP_IDLE);
- return 1;
+ return;
}
so->rx.sn++;
so->rx.sn %= 16;
for (i = ae + N_PCI_SZ; i < cf->len; i++) {
@@ -736,37 +740,38 @@ static int isotp_rcv_cf(struct sock *sk, struct canfd_frame *cf, int ae,
chk_pad_fail(so, cf, i + 1, so->opt.rxpad_content)) {
/* malformed PDU - report 'not a data message' */
sk->sk_err = EBADMSG;
if (!sock_flag(sk, SOCK_DEAD))
sk_error_report(sk);
- return 1;
+ return;
}
nskb = alloc_skb(so->rx.len, gfp_any());
if (!nskb)
- return 1;
+ return;
memcpy(skb_put(nskb, so->rx.len), so->rx.buf,
so->rx.len);
nskb->tstamp = skb->tstamp;
nskb->dev = skb->dev;
isotp_rcv_skb(nskb, sk);
- return 0;
+ return;
}
/* start rx timeout, isotp_send_fc() restarts it */
hrtimer_start(&so->rxtimer, ktime_set(ISOTP_FC_TIMEOUT, 0),
HRTIMER_MODE_REL_SOFT);
/* perform blocksize handling, if enabled */
if (!so->rxfc.bs || ++so->rx.bs < so->rxfc.bs)
- return 0;
+ return;
/* we reached the specified blocksize so->rxfc.bs */
isotp_send_fc(sk, ae, ISOTP_FC_CTS);
- return 0;
+
+ return;
}
static void isotp_rcv(struct sk_buff *skb, void *data)
{
struct sock *sk = (struct sock *)data;
--
2.53.0
^ permalink raw reply related [flat|nested] 38+ messages in thread* Re: [PATCH can-next 20/22] can: isotp: change return type of functions to void
2026-11-26 21:06 ` [PATCH can-next 20/22] can: isotp: change return type of functions to void Oliver Hartkopp
@ 2026-11-28 10:20 ` netdev-bot+sashiko
0 siblings, 0 replies; 38+ messages in thread
From: netdev-bot+sashiko @ 2026-11-28 10:20 UTC (permalink / raw)
To: socketcan
Cc: linux-can, mkl, sashiko-bot, zihanx, o.rempel, yewentian395, kuba
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] Commit "can: isotp: change return type of functions to void"
turns five functions into void functions: isotp_send_fc(),…
--
can: isotp: change return type of functions to void
This commit changes isotp_send_fc(), isotp_rcv_fc(), isotp_rcv_sf(),
isotp_rcv_ff() and isotp_rcv_cf() in net/can/isotp.c from int to void.
None of their callers ever used the return values.
> diff --git a/net/can/isotp.c b/net/can/isotp.c
> index 31acff7c33aa5..a9182588aeb77 100644
> --- a/net/can/isotp.c
> +++ b/net/can/isotp.c
[ ... ]
> @@ -357,7 +357,8 @@ static int isotp_send_fc(struct sock *sk, int ae, u8 flowstatus)
> hrtimer_start(&so->rxtimer,
> ktime_set(ISOTP_FC_TIMEOUT, so->frame_txtime),
> HRTIMER_MODE_REL_SOFT);
> - return 0;
> +
> + return;
> }
[Severity: Low]
This isn't a bug, but could the trailing return 0 be dropped here rather
than turned into a blank line plus return?
A bare return as the last statement of a void function has no effect.
checkpatch.pl also warns about it under RETURN_VOID ("void function return
statements are not generally useful").
The same pattern appears at the end of isotp_rcv_fc(), isotp_rcv_sf(),
isotp_rcv_ff() and isotp_rcv_cf(). The early returns inside these
functions are fine as they are.
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261126-getsockopt-memcg-isotp-v1-0-681ef8d8c2c9%40hartkopp.net
^ permalink raw reply [flat|nested] 38+ messages in thread
* [PATCH can-next 21/22] can: isotp: rename pointer in isotp_rcv() prototype
2026-11-26 21:05 [PATCH can-next 00/22] can: memcg accounting, CAN_ISOTP fixes and cleanups Oliver Hartkopp
` (19 preceding siblings ...)
2026-11-26 21:06 ` [PATCH can-next 20/22] can: isotp: change return type of functions to void Oliver Hartkopp
@ 2026-11-26 21:06 ` Oliver Hartkopp
2026-11-26 21:06 ` [PATCH can-next 22/22] can: isotp: introduce CAN_ISOTP_MIN_TX_DL Oliver Hartkopp
2026-11-28 17:54 ` [PATCH can-next 00/22] can: memcg accounting, CAN_ISOTP fixes and cleanups Oliver Hartkopp
22 siblings, 0 replies; 38+ messages in thread
From: Oliver Hartkopp @ 2026-11-26 21:06 UTC (permalink / raw)
To: linux-can; +Cc: Marc Kleine-Budde, Oliver Hartkopp
Preparation for CAN XL support where a 'data' pointer is commonly used.
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
---
net/can/isotp.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/net/can/isotp.c b/net/can/isotp.c
index a9182588aeb7..47f91e88dedb 100644
--- a/net/can/isotp.c
+++ b/net/can/isotp.c
@@ -770,13 +770,13 @@ static void isotp_rcv_cf(struct sock *sk, struct canfd_frame *cf, int ae,
isotp_send_fc(sk, ae, ISOTP_FC_CTS);
return;
}
-static void isotp_rcv(struct sk_buff *skb, void *data)
+static void isotp_rcv(struct sk_buff *skb, void *skdata)
{
- struct sock *sk = (struct sock *)data;
+ struct sock *sk = (struct sock *)skdata;
struct isotp_sock *so = isotp_sk(sk);
struct canfd_frame *cf;
int ae = (so->opt.flags & CAN_ISOTP_EXTEND_ADDR) ? 1 : 0;
u8 n_pci_type, sf_dl;
--
2.53.0
^ permalink raw reply related [flat|nested] 38+ messages in thread* [PATCH can-next 22/22] can: isotp: introduce CAN_ISOTP_MIN_TX_DL
2026-11-26 21:05 [PATCH can-next 00/22] can: memcg accounting, CAN_ISOTP fixes and cleanups Oliver Hartkopp
` (20 preceding siblings ...)
2026-11-26 21:06 ` [PATCH can-next 21/22] can: isotp: rename pointer in isotp_rcv() prototype Oliver Hartkopp
@ 2026-11-26 21:06 ` Oliver Hartkopp
2026-11-28 10:20 ` netdev-bot+sashiko
2026-11-28 17:54 ` [PATCH can-next 00/22] can: memcg accounting, CAN_ISOTP fixes and cleanups Oliver Hartkopp
22 siblings, 1 reply; 38+ messages in thread
From: Oliver Hartkopp @ 2026-11-26 21:06 UTC (permalink / raw)
To: linux-can; +Cc: Marc Kleine-Budde, Oliver Hartkopp
The minimum TX_DL value is 8 and the CAN_MAX_DLEN is also 8.
To not mix the intention and context of the defines introduce a separate
CAN_ISOTP_MIN_TX_DL definition to perform TX_DL related checks.
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
---
include/uapi/linux/can/isotp.h | 3 ++-
net/can/isotp.c | 10 +++++-----
2 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/include/uapi/linux/can/isotp.h b/include/uapi/linux/can/isotp.h
index bd990917f7c4..580d2aef2c53 100644
--- a/include/uapi/linux/can/isotp.h
+++ b/include/uapi/linux/can/isotp.h
@@ -160,12 +160,13 @@ struct can_isotp_ll_options {
* consistency and copied directly into the flow control (FC) frame.
*/
/* link layer default values => make use of Classical CAN frames */
+#define CAN_ISOTP_MIN_TX_DL CAN_MAX_DLEN
#define CAN_ISOTP_DEFAULT_LL_MTU CAN_MTU
-#define CAN_ISOTP_DEFAULT_LL_TX_DL CAN_MAX_DLEN
+#define CAN_ISOTP_DEFAULT_LL_TX_DL CAN_ISOTP_MIN_TX_DL
#define CAN_ISOTP_DEFAULT_LL_TX_FLAGS 0
/*
* The CAN_ISOTP_DEFAULT_FRAME_TXTIME has become a non-zero value as
* it only makes sense for isotp implementation tests to run without
diff --git a/net/can/isotp.c b/net/can/isotp.c
index 47f91e88dedb..acea58db9ccd 100644
--- a/net/can/isotp.c
+++ b/net/can/isotp.c
@@ -402,11 +402,11 @@ static bool chk_optimized_fail(struct canfd_frame *cf, int start_index)
/* for CAN_DL <= 8 the start_index is equal to the CAN_DL as the
* padding would start at this point. E.g. if the padding would
* start at cf.data[7] cf->len has to be 7 to be optimal.
* Note: The data[] index starts with zero.
*/
- if (cf->len <= CAN_MAX_DLEN)
+ if (cf->len <= CAN_ISOTP_MIN_TX_DL)
return (cf->len != start_index);
/* This relation is also valid in the non-linear DLC range, where
* we need to take care of the minimal next possible CAN_DL.
* The correct check would be (padlen(cf->len) != padlen(start_index)).
@@ -615,12 +615,12 @@ static void isotp_rcv_ff(struct sock *sk, struct canfd_frame *cf, int ae)
if (len <= MAX_12BIT_PDU_SIZE)
return;
}
/* the PDU must not fit into a SF (FF_DLmin) */
- if (ll_dl == CAN_MAX_DLEN)
- sf_max = CAN_MAX_DLEN - SF_PCI_SZ4 - ae;
+ if (ll_dl == CAN_ISOTP_MIN_TX_DL)
+ sf_max = CAN_ISOTP_MIN_TX_DL - SF_PCI_SZ4 - ae;
else
sf_max = ll_dl - SF_PCI_SZ8 - ae;
if (len <= sf_max)
return;
@@ -1234,11 +1234,11 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
err = -EINVAL;
goto err_out_drop;
}
/* take care of a potential SF_DL ESC offset for TX_DL > 8 */
- off = (so->tx.ll_dl > CAN_MAX_DLEN) ? 1 : 0;
+ off = (so->tx.ll_dl > CAN_ISOTP_MIN_TX_DL) ? 1 : 0;
/* does the given data fit into a single frame for SF_BROADCAST? */
if ((isotp_bc_flags(so) == CAN_ISOTP_SF_BROADCAST) &&
(size > so->tx.ll_dl - SF_PCI_SZ4 - ae - off)) {
err = -EINVAL;
@@ -1295,11 +1295,11 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
* When TX_DL is greater 8 but the message would still fit
* into a 8 byte CAN frame, we can omit the offset.
* This prevents a protocol caused length extension from
* CAN_DL = 8 to CAN_DL = 12 due to the SF_SL ESC handling.
*/
- if (size <= CAN_MAX_DLEN - SF_PCI_SZ4 - ae)
+ if (size <= CAN_ISOTP_MIN_TX_DL - SF_PCI_SZ4 - ae)
off = 0;
isotp_fill_dataframe(cf, so, ae, off);
/* place single frame N_PCI w/o length in appropriate index */
--
2.53.0
^ permalink raw reply related [flat|nested] 38+ messages in thread* Re: [PATCH can-next 22/22] can: isotp: introduce CAN_ISOTP_MIN_TX_DL
2026-11-26 21:06 ` [PATCH can-next 22/22] can: isotp: introduce CAN_ISOTP_MIN_TX_DL Oliver Hartkopp
@ 2026-11-28 10:20 ` netdev-bot+sashiko
0 siblings, 0 replies; 38+ messages in thread
From: netdev-bot+sashiko @ 2026-11-28 10:20 UTC (permalink / raw)
To: socketcan
Cc: linux-can, mkl, sashiko-bot, zihanx, o.rempel, yewentian395, kuba
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The commit says CAN_ISOTP_MIN_TX_DL is added "to perform TX_DL
related checks" so the meanings of the two defines stay separate.
- [Low] In include/uapi/linux/can/isotp.h the new `#define
CAN_ISOTP_MIN_TX_DL CAN_MAX_DLEN` (line 165) is the first entry under…
--
can: isotp: introduce CAN_ISOTP_MIN_TX_DL
This commit adds a CAN_ISOTP_MIN_TX_DL define to the isotp UAPI header.
It has the same value as CAN_MAX_DLEN (8), and CAN_ISOTP_DEFAULT_LL_TX_DL
is now based on it.
Several CAN_MAX_DLEN users in net/can/isotp.c are switched to the new
define, so that TX_DL checks stay separate from CAN frame length checks.
> diff --git a/include/uapi/linux/can/isotp.h b/include/uapi/linux/can/isotp.h
> index bd990917f7c43..580d2aef2c531 100644
> --- a/include/uapi/linux/can/isotp.h
> +++ b/include/uapi/linux/can/isotp.h
> @@ -162,8 +162,9 @@ struct can_isotp_ll_options {
>
> /* link layer default values => make use of Classical CAN frames */
>
> +#define CAN_ISOTP_MIN_TX_DL CAN_MAX_DLEN
[Severity: Low]
This isn't a bug, but CAN_ISOTP_MIN_TX_DL is a protocol lower bound, not
a default. It is now the first entry under the "link layer default
values" comment, next to CAN_ISOTP_DEFAULT_LL_MTU,
CAN_ISOTP_DEFAULT_LL_TX_DL and CAN_ISOTP_DEFAULT_LL_TX_FLAGS.
It has to come before CAN_ISOTP_DEFAULT_LL_TX_DL, which uses it. Could it
go in its own block above the defaults, or could the comment be updated?
That way, people reading this userspace header won't mistake it for a
default value.
> #define CAN_ISOTP_DEFAULT_LL_MTU CAN_MTU
> -#define CAN_ISOTP_DEFAULT_LL_TX_DL CAN_MAX_DLEN
> +#define CAN_ISOTP_DEFAULT_LL_TX_DL CAN_ISOTP_MIN_TX_DL
> #define CAN_ISOTP_DEFAULT_LL_TX_FLAGS 0
>
> /*
> diff --git a/net/can/isotp.c b/net/can/isotp.c
> index 47f91e88dedbe..acea58db9ccde 100644
> --- a/net/can/isotp.c
> +++ b/net/can/isotp.c
> @@ -404,7 +404,7 @@ static bool chk_optimized_fail(struct canfd_frame *cf, int start_index)
> * start at cf.data[7] cf->len has to be 7 to be optimal.
> * Note: The data[] index starts with zero.
> */
> - if (cf->len <= CAN_MAX_DLEN)
> + if (cf->len <= CAN_ISOTP_MIN_TX_DL)
> return (cf->len != start_index);
>
> /* This relation is also valid in the non-linear DLC range, where
> @@ -617,8 +617,8 @@ static void isotp_rcv_ff(struct sock *sk, struct canfd_frame *cf, int ae)
> }
>
> /* the PDU must not fit into a SF (FF_DLmin) */
> - if (ll_dl == CAN_MAX_DLEN)
> - sf_max = CAN_MAX_DLEN - SF_PCI_SZ4 - ae;
> + if (ll_dl == CAN_ISOTP_MIN_TX_DL)
> + sf_max = CAN_ISOTP_MIN_TX_DL - SF_PCI_SZ4 - ae;
> else
> sf_max = ll_dl - SF_PCI_SZ8 - ae;
[Severity: Low]
The commit message says the new define is used "to perform TX_DL related
checks". Is the check in chk_optimized_fail() really a TX_DL check?
It tests cf->len of a received frame. The function's own comment calls
this the "for CAN_DL <= 8" range, which is what CAN_MAX_DLEN means. The
matching padding check in isotp_fill_dataframe() still uses
CAN_MAX_DLEN:
net/can/isotp.c:isotp_fill_dataframe() {
...
} else if (cf->len > CAN_MAX_DLEN) {
/* mandatory padding for CAN FD frames */
...
}
isotp_rcv_ff() now uses CAN_ISOTP_MIN_TX_DL for the LL_DL == 8 choice
between SF_PCI_SZ4 and SF_PCI_SZ8. isotp_rcv() makes the same choice for
single frames, and its comment calls it the "LL_DL == 8" check, but it
still uses CAN_MAX_DLEN:
net/can/isotp.c:isotp_rcv() {
...
if (cf->len <= CAN_MAX_DLEN) {
isotp_rcv_sf(sk, cf, SF_PCI_SZ4 + ae, skb, sf_dl);
...
}
Both defines expand to 8, so nothing changes at runtime. However, the RX
single frame, RX first frame, RX padding and TX padding paths now use
different constants for the same 8-byte limit.
Would it be more consistent to keep CAN_MAX_DLEN in chk_optimized_fail(),
and to convert both isotp_rcv_ff() and isotp_rcv(), or neither?
The two conversions in isotp_sendmsg() compare against so->tx.ll_dl and
look like real TX_DL checks.
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261126-getsockopt-memcg-isotp-v1-0-681ef8d8c2c9%40hartkopp.net
^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: [PATCH can-next 00/22] can: memcg accounting, CAN_ISOTP fixes and cleanups
2026-11-26 21:05 [PATCH can-next 00/22] can: memcg accounting, CAN_ISOTP fixes and cleanups Oliver Hartkopp
` (21 preceding siblings ...)
2026-11-26 21:06 ` [PATCH can-next 22/22] can: isotp: introduce CAN_ISOTP_MIN_TX_DL Oliver Hartkopp
@ 2026-11-28 17:54 ` Oliver Hartkopp
22 siblings, 0 replies; 38+ messages in thread
From: Oliver Hartkopp @ 2026-11-28 17:54 UTC (permalink / raw)
To: linux-can
Cc: Marc Kleine-Budde, Sashiko, Zihan Xi, Oleksij Rempel, Wentian Ye
Hello all,
thanks to Sashiko for the review of this series.
I've addressed the findings for the patches 5, 6, 8, 9, 11, 12, 13, 14,
16, 20 and 22 in v2. The changes are listed in the v2 cover letter.
The high severity finding for "can: isotp: reject CAN_ISOTP_CHK_PAD_DATA
without CAN_ISOTP_RX_PADDING" was correct: rejecting the option also
broke the working CAN_ISOTP_CHK_PAD_LEN | CAN_ISOTP_CHK_PAD_DATA
combination without CAN_ISOTP_RX_PADDING. In v2 this patch is replaced
by "can: isotp: ignore CAN_ISOTP_CHK_PAD_DATA without
CAN_ISOTP_RX_PADDING", which fixes check_pad() as documented.
v2:
https://lore.kernel.org/linux-can/20261128-getsockopt-memcg-isotp-v2-0-034ba95e17a4@hartkopp.net/
pw-bot: cr
Best regards,
Oliver
On 26.11.26 22:05, Oliver Hartkopp wrote:
> Patches 1-3 are the remaining CAN patches of the former lock_sock() and
> memcg series, whose first patches have been applied via the net tree.
> They are followed by CAN_ISOTP fixes and cleanups that have been found
> while preparing the CAN XL support for CAN_ISOTP.
>
> Patches 1-2 read the CAN_RAW and CAN_ISOTP socket options under
> conf_lock, so that a concurrent setsockopt() can not lead to a mix of
> old and new values in getsockopt().
>
> Patch 3 enables the memcg accounting for the CAN allocations that can
> be triggered by unprivileged users (socket structures, receivers,
> CAN_BCM ops and frames, CAN_RAW/J1939 filters, the CAN_ISOTP TX buffer
> for large PDUs and the J1939 per device data).
>
> Patches 4-8 improve the CAN_ISOTP socket options:
> - check the CAN_ISOTP_OPTS values before applying them
> - add the documented frame transmission time (N_As/N_Ar) to the
> protocol timeouts
> - reject undefined CAN FD tx_flags, reserved STmin values and
> CAN_ISOTP_CHK_PAD_DATA without CAN_ISOTP_RX_PADDING
>
> Patches 9-14 fix the CAN_ISOTP reception against ISO 15765-2:
> - drop frames without N_PCI and FFs with an invalid length extension
> - check FF_DLmin and the data length of the last CF
> - do not send FC.OVFLW in listen mode
> - ignore invalid SF/FF frames without terminating an ongoing reception
>
> Patches 15-22 are cleanups in preparation of the CAN XL support for
> CAN_ISOTP.
>
> As patches 4-14 reject socket option values and frames that have been
> accepted before, they are intended for can-next and do not carry Fixes
> tags.
>
> ---
> Oliver Hartkopp (22):
> can: raw: read socket options under conf_lock in raw_getsockopt()
> can: isotp: read socket options under conf_lock in isotp_getsockopt()
> can: enable memcg accounting for user triggered allocations
> can: isotp: check the CAN_ISOTP_OPTS values before applying them
> can: isotp: add the frame transmission time to the protocol timeouts
> can: isotp: check the CAN FD tx_flags in CAN_ISOTP_LL_OPTS
> can: isotp: reject reserved STmin values in CAN_ISOTP_RECV_FC
> can: isotp: reject CAN_ISOTP_CHK_PAD_DATA without CAN_ISOTP_RX_PADDING
> can: isotp: drop frames without N_PCI
> can: isotp: drop FF frames with invalid length extension
> can: isotp: check the minimum FF_DL
> can: isotp: check the data length of the last CF
> can: isotp: do not send FC.OVFLW in listen mode
> can: isotp: ignore invalid SF and FF frames during a reception
> can: isotp: drop inline keyword, let the compiler decide
> can: isotp: rename rx_lock as it has become state machine lock
> can: isotp: introduce isotp_invalid_canid() to verify proper CAN-IDs
> can: isotp: rename variable for the required content length
> can: isotp: rename checkpad functions returning bool values
> can: isotp: change return type of functions to void
> can: isotp: rename pointer in isotp_rcv() prototype
> can: isotp: introduce CAN_ISOTP_MIN_TX_DL
>
> include/uapi/linux/can/isotp.h | 3 +-
> net/can/af_can.c | 12 +-
> net/can/bcm.c | 10 +-
> net/can/isotp.c | 380 ++++++++++++++++++++++++-----------------
> net/can/j1939/main.c | 2 +-
> net/can/j1939/socket.c | 12 +-
> net/can/raw.c | 78 +++++----
> 7 files changed, 291 insertions(+), 206 deletions(-)
> ---
> base-commit: e1055cbfd6eb578417f3ce983cf44462e8465267
> change-id: 20261126-getsockopt-memcg-isotp-052433c7adda
>
> Best regards,
> --
> Oliver Hartkopp <socketcan@hartkopp.net>
>
^ permalink raw reply [flat|nested] 38+ messages in thread