* [PATCH can-next v3 01/23] can: raw: read socket options under conf_lock in raw_getsockopt()
2026-11-30 13:22 [PATCH can-next v3 00/23] can: memcg accounting, CAN_ISOTP fixes and cleanups Oliver Hartkopp
@ 2026-11-30 13:22 ` Oliver Hartkopp
2026-11-30 13:22 ` [PATCH can-next v3 02/23] can: isotp: read socket options under conf_lock in isotp_getsockopt() Oliver Hartkopp
` (21 subsequent siblings)
22 siblings, 0 replies; 29+ messages in thread
From: Oliver Hartkopp @ 2026-11-30 13:22 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] 29+ messages in thread* [PATCH can-next v3 02/23] can: isotp: read socket options under conf_lock in isotp_getsockopt()
2026-11-30 13:22 [PATCH can-next v3 00/23] can: memcg accounting, CAN_ISOTP fixes and cleanups Oliver Hartkopp
2026-11-30 13:22 ` [PATCH can-next v3 01/23] can: raw: read socket options under conf_lock in raw_getsockopt() Oliver Hartkopp
@ 2026-11-30 13:22 ` Oliver Hartkopp
2026-11-30 13:22 ` [PATCH can-next v3 03/23] can: enable memcg accounting for user triggered allocations Oliver Hartkopp
` (20 subsequent siblings)
22 siblings, 0 replies; 29+ messages in thread
From: Oliver Hartkopp @ 2026-11-30 13:22 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] 29+ messages in thread* [PATCH can-next v3 03/23] can: enable memcg accounting for user triggered allocations
2026-11-30 13:22 [PATCH can-next v3 00/23] can: memcg accounting, CAN_ISOTP fixes and cleanups Oliver Hartkopp
2026-11-30 13:22 ` [PATCH can-next v3 01/23] can: raw: read socket options under conf_lock in raw_getsockopt() Oliver Hartkopp
2026-11-30 13:22 ` [PATCH can-next v3 02/23] can: isotp: read socket options under conf_lock in isotp_getsockopt() Oliver Hartkopp
@ 2026-11-30 13:22 ` Oliver Hartkopp
2026-12-02 3:48 ` netdev-bot+sashiko
2026-11-30 13:22 ` [PATCH can-next v3 04/23] can: isotp: do not send FC.OVFLW in listen mode Oliver Hartkopp
` (19 subsequent siblings)
22 siblings, 1 reply; 29+ messages in thread
From: Oliver Hartkopp @ 2026-11-30 13:22 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>
Acked-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
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] 29+ messages in thread* Re: [PATCH can-next v3 03/23] can: enable memcg accounting for user triggered allocations
2026-11-30 13:22 ` [PATCH can-next v3 03/23] can: enable memcg accounting for user triggered allocations Oliver Hartkopp
@ 2026-12-02 3:48 ` netdev-bot+sashiko
0 siblings, 0 replies; 29+ messages in thread
From: netdev-bot+sashiko @ 2026-12-02 3:48 UTC (permalink / raw)
To: socketcan; +Cc: linux-can, mkl, 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] Two CAN allocations that a user can trigger are still not
charged to any memory cgroup after this patch, so the memcg bypass the…
- [Low] The commit message says the can-gw jobs 'are not changed', but
adding SLAB_ACCOUNT to the shared rcv_cache in can_init()…
--
can: enable memcg accounting for user triggered allocations
This commit charges CAN allocations that unprivileged users can trigger to
the memory cgroup of the allocating process. That covers socket structures,
receivers, per-netns lists, bcm_op frames, raw and j1939 filters, the isotp
TX buffer and j1939_priv. A few softirq-context and privileged allocations
are left out on purpose, and the commit message gives the reasons.
Link: https://lore.kernel.org/linux-can/350df96b-5f69-490e-b39e-ed6e9bca4754@hartkopp.net/
> diff --git a/net/can/af_can.c b/net/can/af_can.c
> index 0f3051a61aab5..6f958c2bb49d0 100644
> --- a/net/can/af_can.c
> +++ b/net/can/af_can.c
[ ... ]
> @@ -919,7 +921,7 @@ static __init int can_init(void)
> 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);
[Severity: Low]
The commit message says the can-gw jobs "are not changed". Doesn't
SLAB_ACCOUNT on the shared rcv_cache also charge the receivers that can-gw
registers?
cgw_register_filter() in net/can/gw.c gets its receiver from
can_rx_register(), and can_rx_register() allocates from rcv_cache:
static inline int cgw_register_filter(struct net *net, struct cgw_job *gwj)
{
return can_rx_register(net, gwj->src.dev, gwj->ccgw.filter.can_id,
gwj->ccgw.filter.can_mask, can_can_gw_rcv,
gwj, 0, NULL);
}
So for each can-gw job created via RTM_NEWROUTE, the receiver is now
charged to the memcg of the sending process. The cgw_job itself still comes
from cgw_cache, which cgw_module_init() creates without SLAB_ACCOUNT:
cgw_cache = kmem_cache_create("can_gw", sizeof(struct cgw_job),
0, 0, NULL);
This isn't a functional bug. Could the commit message say that can-gw
receivers are now accounted while the jobs are not, so that it matches the
code?
> if (!rcv_cache)
> return -ENOMEM;
>
[ ... ]
> diff --git a/net/can/isotp.c b/net/can/isotp.c
> index 98a7e489ca3e5..3b83507a8c21b 100644
> --- a/net/can/isotp.c
> +++ b/net/can/isotp.c
> @@ -609,7 +609,12 @@ static int isotp_rcv_ff(struct sock *sk, struct canfd_frame *cf, int ae)
> 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);
[Severity: Medium]
Is the memcg bypass from the commit message still reachable through this
buffer?
The buffer can be up to max_pdu_size (MAX_PDU_SIZE, 1025 KiB) per socket. A
local user can trigger it by sending First Frames with a large FF_DL to
their own isotp sockets via loopback. The buffer then stays allocated until
the socket is released. This only applies when max_pdu_size has been raised
above the default.
The commit message points out that a forced GFP_ATOMIC charge could exceed
the limit by up to max_pdu_size per socket. Would a forced charge still be
preferable to no charge at all? A forced charge counts against the cgroup
that owns the socket. An uncharged buffer is invisible to the memcg limit
and to OOM-killer attribution.
A related question about this part of the commit message:
The j1939 RX sessions are allocated in softirq context
before a socket is involved and can not be attributed to a process.
Is that accurate? j1939_xtp_rx_rts_session_new() in
net/can/j1939/transport.c returns early unless a local j1939 socket
matches:
if (!j1939_sk_recv_match(priv, &skcb))
return NULL;
Only after that does it call j1939_session_fresh_new(), which does:
skb = alloc_skb(size, GFP_ATOMIC);
The only upper bound on size here is priv->tp_max_packet_size. It defaults
to J1939_MAX_ETP_PACKET_SIZE (about 117 MB), although in practice kmalloc
caps a single buffer at KMALLOC_MAX_SIZE. Point-to-point ETP sessions also
require J1939_ECU_LOCAL_DST, so a locally bound ECU is involved too.
j1939_session_activate() allows one active session per address pair. A
single bound socket could therefore hold sessions from up to about 254
source addresses, each with an uncharged buffer of several MB.
Since a socket is always involved, could these session buffers be charged
to the memcg of the matching socket, or of the now-accounted j1939_priv,
rather than being left unaccounted?
>
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130-getsockopt-memcg-isotp-v3-0-21d72c15ad1d%40hartkopp.net
^ permalink raw reply [flat|nested] 29+ messages in thread
* [PATCH can-next v3 04/23] can: isotp: do not send FC.OVFLW in listen mode
2026-11-30 13:22 [PATCH can-next v3 00/23] can: memcg accounting, CAN_ISOTP fixes and cleanups Oliver Hartkopp
` (2 preceding siblings ...)
2026-11-30 13:22 ` [PATCH can-next v3 03/23] can: enable memcg accounting for user triggered allocations Oliver Hartkopp
@ 2026-11-30 13:22 ` Oliver Hartkopp
2026-11-30 13:22 ` [PATCH can-next v3 05/23] can: isotp: check the CAN_ISOTP_OPTS values before applying them Oliver Hartkopp
` (18 subsequent siblings)
22 siblings, 0 replies; 29+ messages in thread
From: Oliver Hartkopp @ 2026-11-30 13:22 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 before CAN_ISOTP_LISTEN_MODE is checked. So a socket
in listen mode, which is intended to monitor the ISO-TP traffic
passively, sends a FC.OVFLW on the bus when a received FF exceeds its
receive buffer (max_pdu_size). This aborts 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.
Fixes: e057dd3fc20f ("can: add ISO 15765-2:2016 transport protocol")
Cc: stable@vger.kernel.org
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 3b83507a8c21..650d93e84c8e 100644
--- a/net/can/isotp.c
+++ b/net/can/isotp.c
@@ -292,10 +292,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);
@@ -641,14 +645,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;
}
@@ -742,14 +742,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] 29+ messages in thread* [PATCH can-next v3 05/23] can: isotp: check the CAN_ISOTP_OPTS values before applying them
2026-11-30 13:22 [PATCH can-next v3 00/23] can: memcg accounting, CAN_ISOTP fixes and cleanups Oliver Hartkopp
` (3 preceding siblings ...)
2026-11-30 13:22 ` [PATCH can-next v3 04/23] can: isotp: do not send FC.OVFLW in listen mode Oliver Hartkopp
@ 2026-11-30 13:22 ` Oliver Hartkopp
2026-11-30 13:22 ` [PATCH can-next v3 06/23] can: isotp: add the frame transmission time to the CF broadcast gap Oliver Hartkopp
` (17 subsequent siblings)
22 siblings, 0 replies; 29+ messages in thread
From: Oliver Hartkopp @ 2026-11-30 13:22 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 650d93e84c8e..8817f0ef7fd9 100644
--- a/net/can/isotp.c
+++ b/net/can/isotp.c
@@ -1738,34 +1738,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] 29+ messages in thread* [PATCH can-next v3 06/23] can: isotp: add the frame transmission time to the CF broadcast gap
2026-11-30 13:22 [PATCH can-next v3 00/23] can: memcg accounting, CAN_ISOTP fixes and cleanups Oliver Hartkopp
` (4 preceding siblings ...)
2026-11-30 13:22 ` [PATCH can-next v3 05/23] can: isotp: check the CAN_ISOTP_OPTS values before applying them Oliver Hartkopp
@ 2026-11-30 13:22 ` Oliver Hartkopp
2026-12-02 3:48 ` netdev-bot+sashiko
2026-11-30 13:22 ` [PATCH can-next v3 07/23] can: isotp: add the frame transmission time to the protocol timeouts Oliver Hartkopp
` (16 subsequent siblings)
22 siblings, 1 reply; 29+ messages in thread
From: Oliver Hartkopp @ 2026-11-30 13:22 UTC (permalink / raw)
To: linux-can; +Cc: Marc Kleine-Budde, Oliver Hartkopp
With flow control the gap between the consecutive frames is the frame
transmission time (N_As) plus the minimum separation time (N_Cs). N_Cs is
the STmin value from the received FC or the value of the
CAN_ISOTP_TX_STMIN socket option when the CAN_ISOTP_FORCE_TXSTMIN flag is
set.
In CAN_ISOTP_CF_BROADCAST mode there is no FC and the gap is set in
isotp_sendmsg(). With the CAN_ISOTP_FORCE_TXSTMIN flag only the value of
the CAN_ISOTP_TX_STMIN socket option is used and the frame transmission
time is missing.
Add the frame transmission time to the CF broadcast gap in both cases
like in the flow control mode and document the gap in iso15765-2.rst.
Additionally fix the unit of the values of the CAN_ISOTP_TX_STMIN and
CAN_ISOTP_RX_STMIN socket options in iso15765-2.rst. Both values are
handled in nanoseconds by the implementation, as documented in isotp.h.
As the uAPI header isotp.h has always documented the stmin values in
nanoseconds, there is no Fixes tag for the documentation.
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
---
Documentation/networking/iso15765-2.rst | 9 ++++++---
net/can/isotp.c | 8 ++++----
2 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/Documentation/networking/iso15765-2.rst b/Documentation/networking/iso15765-2.rst
index 37ebb2c417cb..badcd16c070b 100644
--- a/Documentation/networking/iso15765-2.rst
+++ b/Documentation/networking/iso15765-2.rst
@@ -197,11 +197,14 @@ where the ``can_isotp_options`` structure has the following contents:
* ``CAN_ISOTP_SF_BROADCAST``: use 1-to-N functional addressing (cannot be
specified alongside ``CAN_ISOTP_CF_BROADCAST``).
* ``CAN_ISOTP_CF_BROADCAST``: use 1-to-N transmission without flow control
- (cannot be specified alongside ``CAN_ISOTP_SF_BROADCAST``).
+ (cannot be specified alongside ``CAN_ISOTP_SF_BROADCAST``). The gap
+ between the consecutive frames is ``frame_txtime`` plus the value of the
+ ``CAN_ISOTP_TX_STMIN`` socket option when the ``CAN_ISOTP_FORCE_TXSTMIN``
+ flag is set.
NOTE: this is not covered by the ISO 15765-2 standard.
* ``CAN_ISOTP_DYN_FC_PARMS``: enable dynamic update of flow control
parameters.
@@ -284,11 +287,11 @@ where the ``can_isotp_ll_options`` structure has the following contents:
Transmission stmin
~~~~~~~~~~~~~~~~~~
The transmission minimum separation time (stmin) can be forced using the
-``CAN_ISOTP_TX_STMIN`` optname and providing an stmin value in microseconds as
+``CAN_ISOTP_TX_STMIN`` optname and providing an stmin value in nanoseconds as
a 32bit unsigned integer; this will overwrite the value sent by the receiver in
flow control frames:
.. code-block:: C
@@ -297,11 +300,11 @@ flow control frames:
Reception stmin
~~~~~~~~~~~~~~~
The reception minimum separation time (stmin) can be forced using the
-``CAN_ISOTP_RX_STMIN`` optname and providing an stmin value in microseconds as
+``CAN_ISOTP_RX_STMIN`` optname and providing an stmin value in nanoseconds as
a 32bit unsigned integer; received Consecutive Frames (CF) which timestamps
differ less than this value will be ignored:
.. code-block:: C
diff --git a/net/can/isotp.c b/net/can/isotp.c
index 8817f0ef7fd9..7b88b3ace919 100644
--- a/net/can/isotp.c
+++ b/net/can/isotp.c
@@ -1290,15 +1290,15 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
/* send first frame */
isotp_create_fframe(cf, so, ae);
if (isotp_bc_flags(so) == CAN_ISOTP_CF_BROADCAST) {
- /* set timer for FC-less operation (STmin = 0) */
+ /* set timer for FC-less operation (N_As + N_Cs) */
+ so->tx_gap = ktime_set(0, so->frame_txtime);
if (so->opt.flags & CAN_ISOTP_FORCE_TXSTMIN)
- so->tx_gap = ktime_set(0, so->force_tx_stmin);
- else
- so->tx_gap = ktime_set(0, so->frame_txtime);
+ so->tx_gap = ktime_add_ns(so->tx_gap,
+ so->force_tx_stmin);
/* disable wait for FCs due to activated block size */
so->txfc.bs = 0;
/* set CF echo tag for isotp_rcv_echo() (CF-mode) */
--
2.53.0
^ permalink raw reply related [flat|nested] 29+ messages in thread* Re: [PATCH can-next v3 06/23] can: isotp: add the frame transmission time to the CF broadcast gap
2026-11-30 13:22 ` [PATCH can-next v3 06/23] can: isotp: add the frame transmission time to the CF broadcast gap Oliver Hartkopp
@ 2026-12-02 3:48 ` netdev-bot+sashiko
0 siblings, 0 replies; 29+ messages in thread
From: netdev-bot+sashiko @ 2026-12-02 3:48 UTC (permalink / raw)
To: socketcan; +Cc: linux-can, mkl, 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: add the frame transmission time to the CF
broadcast gap" changes how the CF gap is computed in isotp_sendmsg()…
--
can: isotp: add the frame transmission time to the CF broadcast gap
This patch changes the consecutive frame gap in CAN_ISOTP_CF_BROADCAST
mode. When CAN_ISOTP_FORCE_TXSTMIN is set, the gap is now frame_txtime
plus force_tx_stmin, which matches the flow control path. It also fixes
the documented unit of the CAN_ISOTP_TX_STMIN and CAN_ISOTP_RX_STMIN
socket options in iso15765-2.rst, from microseconds to nanoseconds.
[ ... ]
> diff --git a/net/can/isotp.c b/net/can/isotp.c
> index 8817f0ef7fd9e..7b88b3ace919e 100644
> --- a/net/can/isotp.c
> +++ b/net/can/isotp.c
> @@ -1292,11 +1292,11 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
> isotp_create_fframe(cf, so, ae);
>
> if (isotp_bc_flags(so) == CAN_ISOTP_CF_BROADCAST) {
> - /* set timer for FC-less operation (STmin = 0) */
> + /* set timer for FC-less operation (N_As + N_Cs) */
> + so->tx_gap = ktime_set(0, so->frame_txtime);
> if (so->opt.flags & CAN_ISOTP_FORCE_TXSTMIN)
> - so->tx_gap = ktime_set(0, so->force_tx_stmin);
> - else
> - so->tx_gap = ktime_set(0, so->frame_txtime);
> + so->tx_gap = ktime_add_ns(so->tx_gap,
> + so->force_tx_stmin);
[Severity: Low]
This isn't a bug in the code, but should this change carry a Fixes: tag?
The code now matches what isotp_rcv_fc() already does in flow control
mode:
net/can/isotp.c:isotp_rcv_fc() {
...
so->tx_gap = ktime_add_ns(so->tx_gap, so->frame_txtime);
/* add waiting time for consecutive frames N_Cs */
if (so->opt.flags & CAN_ISOTP_FORCE_TXSTMIN)
so->tx_gap = ktime_add_ns(so->tx_gap,
so->force_tx_stmin);
...
}
The commit message calls the missing frame transmission time a defect.
However, it only explains why the documentation part has no Fixes tag:
"As the uAPI header isotp.h has always documented the stmin values in
nanoseconds, there is no Fixes tag for the documentation."
The old broadcast gap logic in isotp_sendmsg() came from commit
9f39d36530e5 ("can: isotp: add support for transmission without flow
control").
With CF_BROADCAST and CAN_ISOTP_FORCE_TXSTMIN, this patch changes the CF
spacing on the bus. Without a Fixes: tag, or a note on why there isn't
one, stable backporters can't tell whether to treat this as a fix or as
a behaviour change.
Would it make sense to add:
Fixes: 9f39d36530e5 ("can: isotp: add support for transmission without flow control")
or to say in the commit message why it is left out?
>
> /* disable wait for FCs due to activated block size */
> so->txfc.bs = 0;
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130-getsockopt-memcg-isotp-v3-0-21d72c15ad1d%40hartkopp.net
^ permalink raw reply [flat|nested] 29+ messages in thread
* [PATCH can-next v3 07/23] can: isotp: add the frame transmission time to the protocol timeouts
2026-11-30 13:22 [PATCH can-next v3 00/23] can: memcg accounting, CAN_ISOTP fixes and cleanups Oliver Hartkopp
` (5 preceding siblings ...)
2026-11-30 13:22 ` [PATCH can-next v3 06/23] can: isotp: add the frame transmission time to the CF broadcast gap Oliver Hartkopp
@ 2026-11-30 13:22 ` Oliver Hartkopp
2026-11-30 13:22 ` [PATCH can-next v3 08/23] can: isotp: use the N_As timeout for the local echo Oliver Hartkopp
` (15 subsequent siblings)
22 siblings, 0 replies; 29+ messages in thread
From: Oliver Hartkopp @ 2026-11-30 13:22 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 with 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 timeouts are started with the transmission of
the CAN frames as well and are extended by the frame transmission time
too: for single frames and first frames without flow control in
isotp_sendmsg() and for consecutive frames in isotp_rcv_fc(),
isotp_rcv_echo() and isotp_txfr_timer_handler(). The flow control
timeout after a completed block is started with the reception of the
local echo of the last consecutive frame, i.e. after its transmission,
and needs no extension.
ISO 15765-2 defines a timeout of 1000 ms for N_As/N_Ar, i.e. for the
transmission of a CAN frame on the sender and the receiver side. So far
frame_txtime accepted any value up to 0xFFFFFFFE ns (about 4.3 s). Reject
frame_txtime values above the N_As/N_Ar timeout of 1 s with -EINVAL
before the options are applied and document the limit in isotp.h and
iso15765-2.rst. Larger gaps between the consecutive frames can be
configured with the CAN_ISOTP_TX_STMIN socket option and the
CAN_ISOTP_FORCE_TXSTMIN flag.
There is no separate timer for N_As/N_Ar, as the frame transmission
time is covered by the protocol timeout that is started with the
transmission of the CAN frame.
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>
---
Documentation/networking/iso15765-2.rst | 12 ++++++++----
include/uapi/linux/can/isotp.h | 1 +
net/can/isotp.c | 20 +++++++++++++++-----
3 files changed, 24 insertions(+), 9 deletions(-)
diff --git a/Documentation/networking/iso15765-2.rst b/Documentation/networking/iso15765-2.rst
index badcd16c070b..191580c4e496 100644
--- a/Documentation/networking/iso15765-2.rst
+++ b/Documentation/networking/iso15765-2.rst
@@ -206,14 +206,18 @@ where the ``can_isotp_options`` structure has the following contents:
NOTE: this is not covered by the ISO 15765-2 standard.
* ``CAN_ISOTP_DYN_FC_PARMS``: enable dynamic update of flow control
parameters.
-* ``frame_txtime``: frame transmission time (defined as N_As/N_Ar inside the
- ISO standard); if ``0``, the default (or the last set value) is used.
- To set the transmission time to ``0``, the ``CAN_ISOTP_FRAME_TXTIME_ZERO``
- macro (equal to 0xFFFFFFFF) shall be used.
+* ``frame_txtime``: frame transmission time in nanoseconds (defined as
+ N_As/N_Ar inside the ISO standard); if ``0``, the default (or the last set
+ value) is used. To set the transmission time to ``0``, the
+ ``CAN_ISOTP_FRAME_TXTIME_ZERO`` macro (equal to 0xFFFFFFFF) shall be used.
+ The frame transmission time is limited to the N_As/N_Ar timeout of 1 s
+ (1000000000 ns) defined in the ISO standard. It is added to the gap between
+ the consecutive frames and to the timeouts that are started with the
+ transmission of a CAN frame.
* ``ext_address``: extended addressing byte, used if the
``CAN_ISOTP_EXTEND_ADDR`` flag is specified.
* ``txpad_content``: byte used as padding value for transmitted frames.
diff --git a/include/uapi/linux/can/isotp.h b/include/uapi/linux/can/isotp.h
index bd990917f7c4..a2e5aa6f9e82 100644
--- a/include/uapi/linux/can/isotp.h
+++ b/include/uapi/linux/can/isotp.h
@@ -72,10 +72,11 @@ struct can_isotp_options {
__u32 flags; /* set flags for isotp behaviour. */
/* __u32 value : flags see below */
__u32 frame_txtime; /* frame transmission time (N_As/N_Ar) */
/* __u32 value : time in nano secs */
+ /* max. 1 s (N_As/N_Ar timeout) */
__u8 ext_address; /* set address for extended addressing */
/* __u8 value : extended address */
__u8 txpad_content; /* set content of padding byte (tx) */
diff --git a/net/can/isotp.c b/net/can/isotp.c
index 7b88b3ace919..18b1e815db4d 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 NSEC_PER_SEC /* N_As/N_Ar timeout */
/* 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.
*/
@@ -351,11 +352,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)
@@ -508,11 +510,12 @@ static int isotp_rcv_fc(struct isotp_sock *so, struct canfd_frame *cf, int ae)
switch (cf->data[ae] & 0x0F) {
case ISOTP_FC_CTS:
so->tx.bs = 0;
WRITE_ONCE(so->tx.state, ISOTP_SENDING);
/* send CF frame and enable echo timeout handling */
- hrtimer_start(&so->echotimer, ktime_set(ISOTP_ECHO_TIMEOUT, 0),
+ hrtimer_start(&so->echotimer,
+ ktime_set(ISOTP_ECHO_TIMEOUT, so->frame_txtime),
HRTIMER_MODE_REL_SOFT);
isotp_send_cframe(so);
break;
case ISOTP_FC_WT:
@@ -1035,11 +1038,12 @@ static void isotp_rcv_echo(struct sk_buff *skb, void *data)
}
/* no gap between data frames needed => use burst mode */
if (!so->tx_gap) {
/* enable echo timeout handling */
- hrtimer_start(&so->echotimer, ktime_set(ISOTP_ECHO_TIMEOUT, 0),
+ hrtimer_start(&so->echotimer,
+ ktime_set(ISOTP_ECHO_TIMEOUT, so->frame_txtime),
HRTIMER_MODE_REL_SOFT);
isotp_send_cframe(so);
goto out_unlock;
}
@@ -1109,11 +1113,12 @@ static enum hrtimer_restart isotp_txfr_timer_handler(struct hrtimer *hrtimer)
{
struct isotp_sock *so = container_of(hrtimer, struct isotp_sock,
txfrtimer);
/* start echo timeout handling and cover below protocol error */
- hrtimer_start(&so->echotimer, ktime_set(ISOTP_ECHO_TIMEOUT, 0),
+ hrtimer_start(&so->echotimer,
+ ktime_set(ISOTP_ECHO_TIMEOUT, so->frame_txtime),
HRTIMER_MODE_REL_SOFT);
/* cfecho should be consumed by isotp_rcv_echo() here */
if (READ_ONCE(so->tx.state) == ISOTP_SENDING && !READ_ONCE(so->cfecho))
isotp_send_cframe(so);
@@ -1327,11 +1332,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;
@@ -1745,10 +1750,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;
+ /* frame_txtime must not exceed the N_As/N_Ar timeout */
+ 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] 29+ messages in thread* [PATCH can-next v3 08/23] can: isotp: use the N_As timeout for the local echo
2026-11-30 13:22 [PATCH can-next v3 00/23] can: memcg accounting, CAN_ISOTP fixes and cleanups Oliver Hartkopp
` (6 preceding siblings ...)
2026-11-30 13:22 ` [PATCH can-next v3 07/23] can: isotp: add the frame transmission time to the protocol timeouts Oliver Hartkopp
@ 2026-11-30 13:22 ` Oliver Hartkopp
2026-11-30 13:22 ` [PATCH can-next v3 09/23] can: isotp: check the CAN FD tx_flags in CAN_ISOTP_LL_OPTS Oliver Hartkopp
` (14 subsequent siblings)
22 siblings, 0 replies; 29+ messages in thread
From: Oliver Hartkopp @ 2026-11-30 13:22 UTC (permalink / raw)
To: linux-can; +Cc: Marc Kleine-Budde, Oliver Hartkopp
The local echo of a sent CAN frame confirms its transmission on the bus.
ISO 15765-2 defines a timeout of 1000 ms for N_As, i.e. for the
transmission of a CAN frame on the sender side. So far the local echo
timeout was 2 s to cover the frame transmission time (N_As) that was
not added to the timeouts, while the flow control timeout (N_Bs) and
the consecutive frame timeout (N_Cr) use 1 s.
As the frame transmission time is now added to all timeouts that are
started with the transmission of a CAN frame, use the timeout of 1 s for
the local echo as well and replace ISOTP_FC_TIMEOUT and
ISOTP_ECHO_TIMEOUT with ISOTP_TIMEOUT.
A CAN frame that can not be sent, e.g. due to a missing acknowledge on
the bus, is now reported with ECOMM after 1 s instead of 2 s. Document
the ECOMM error for the local echo timeout in isotp.c and
iso15765-2.rst.
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
---
Documentation/networking/iso15765-2.rst | 2 +-
net/can/isotp.c | 27 ++++++++++++---------------
2 files changed, 13 insertions(+), 16 deletions(-)
diff --git a/Documentation/networking/iso15765-2.rst b/Documentation/networking/iso15765-2.rst
index 191580c4e496..9d758b6e95e3 100644
--- a/Documentation/networking/iso15765-2.rst
+++ b/Documentation/networking/iso15765-2.rst
@@ -347,11 +347,11 @@ RX path errors
TX path errors
~~~~~~~~~~~~~~
========== =================================================================
--ECOMM flow control reception timeout
+-ECOMM flow control or local echo reception timeout
-EMSGSIZE flow control reception overflow
-EBADMSG flow control reception with wrong layout/padding
========== =================================================================
Examples
diff --git a/net/can/isotp.c b/net/can/isotp.c
index 18b1e815db4d..aa7bfed15500 100644
--- a/net/can/isotp.c
+++ b/net/can/isotp.c
@@ -5,11 +5,11 @@
* userspace.
*
* - RX path timeout of data reception leads to -ETIMEDOUT
* - RX path SN mismatch leads to -EILSEQ
* - RX path data reception with wrong padding leads to -EBADMSG
- * - TX path flowcontrol reception timeout leads to -ECOMM
+ * - TX path flowcontrol or local echo reception timeout leads to -ECOMM
* - TX path flowcontrol reception overflow leads to -EMSGSIZE
* - TX path flowcontrol reception with wrong layout/padding leads to -EBADMSG
* - when a transfer (tx) is on the run the next write() blocks until it's done
* - use CAN_ISOTP_WAIT_TX_DONE flag to block the caller until the PDU is sent
* - as we have static buffers the check whether the PDU fits into the buffer
@@ -123,12 +123,11 @@ MODULE_PARM_DESC(max_pdu_size, "maximum isotp pdu size (default "
/* Flow Status given in FC frame */
#define ISOTP_FC_CTS 0 /* clear to send */
#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_TIMEOUT 1 /* 1 sec (N_As, N_Bs, N_Cr) */
#define ISOTP_MAX_FRAME_TXTIME_NS NSEC_PER_SEC /* N_As/N_Ar timeout */
/* 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.
@@ -353,11 +352,11 @@ 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, so->frame_txtime),
+ ktime_set(ISOTP_TIMEOUT, so->frame_txtime),
HRTIMER_MODE_REL_SOFT);
return 0;
}
static void isotp_rcv_skb(struct sk_buff *skb, struct sock *sk)
@@ -511,18 +510,18 @@ static int isotp_rcv_fc(struct isotp_sock *so, struct canfd_frame *cf, int ae)
case ISOTP_FC_CTS:
so->tx.bs = 0;
WRITE_ONCE(so->tx.state, ISOTP_SENDING);
/* send CF frame and enable echo timeout handling */
hrtimer_start(&so->echotimer,
- ktime_set(ISOTP_ECHO_TIMEOUT, so->frame_txtime),
+ ktime_set(ISOTP_TIMEOUT, so->frame_txtime),
HRTIMER_MODE_REL_SOFT);
isotp_send_cframe(so);
break;
case ISOTP_FC_WT:
/* start timer to wait for next FC frame */
- hrtimer_start(&so->txtimer, ktime_set(ISOTP_FC_TIMEOUT, 0),
+ hrtimer_start(&so->txtimer, ktime_set(ISOTP_TIMEOUT, 0),
HRTIMER_MODE_REL_SOFT);
break;
case ISOTP_FC_OVFLW:
/* overflow on receiver side - report 'message too long' */
@@ -645,11 +644,11 @@ static int isotp_rcv_ff(struct sock *sk, struct canfd_frame *cf, int ae)
/* initial setup for this pdu reception */
so->rx.sn = 1;
WRITE_ONCE(so->rx.state, ISOTP_WAIT_DATA);
/* start rx timeout, isotp_send_fc() restarts it */
- hrtimer_start(&so->rxtimer, ktime_set(ISOTP_FC_TIMEOUT, 0),
+ hrtimer_start(&so->rxtimer, ktime_set(ISOTP_TIMEOUT, 0),
HRTIMER_MODE_REL_SOFT);
/* send our first FC frame */
isotp_send_fc(sk, ae, ISOTP_FC_CTS);
return 0;
@@ -738,11 +737,11 @@ static int isotp_rcv_cf(struct sock *sk, struct canfd_frame *cf, int ae,
isotp_rcv_skb(nskb, sk);
return 0;
}
/* start rx timeout, isotp_send_fc() restarts it */
- hrtimer_start(&so->rxtimer, ktime_set(ISOTP_FC_TIMEOUT, 0),
+ hrtimer_start(&so->rxtimer, ktime_set(ISOTP_TIMEOUT, 0),
HRTIMER_MODE_REL_SOFT);
/* perform blocksize handling, if enabled */
if (!so->rxfc.bs || ++so->rx.bs < so->rxfc.bs)
return 0;
@@ -1030,20 +1029,20 @@ static void isotp_rcv_echo(struct sk_buff *skb, void *data)
}
if (so->txfc.bs && so->tx.bs >= so->txfc.bs) {
/* stop and wait for FC with timeout */
WRITE_ONCE(so->tx.state, ISOTP_WAIT_FC);
- hrtimer_start(&so->txtimer, ktime_set(ISOTP_FC_TIMEOUT, 0),
+ hrtimer_start(&so->txtimer, ktime_set(ISOTP_TIMEOUT, 0),
HRTIMER_MODE_REL_SOFT);
goto out_unlock;
}
/* no gap between data frames needed => use burst mode */
if (!so->tx_gap) {
/* enable echo timeout handling */
hrtimer_start(&so->echotimer,
- ktime_set(ISOTP_ECHO_TIMEOUT, so->frame_txtime),
+ ktime_set(ISOTP_TIMEOUT, so->frame_txtime),
HRTIMER_MODE_REL_SOFT);
isotp_send_cframe(so);
goto out_unlock;
}
@@ -1114,11 +1113,11 @@ static enum hrtimer_restart isotp_txfr_timer_handler(struct hrtimer *hrtimer)
struct isotp_sock *so = container_of(hrtimer, struct isotp_sock,
txfrtimer);
/* start echo timeout handling and cover below protocol error */
hrtimer_start(&so->echotimer,
- ktime_set(ISOTP_ECHO_TIMEOUT, so->frame_txtime),
+ ktime_set(ISOTP_TIMEOUT, so->frame_txtime),
HRTIMER_MODE_REL_SOFT);
/* cfecho should be consumed by isotp_rcv_echo() here */
if (READ_ONCE(so->tx.state) == ISOTP_SENDING && !READ_ONCE(so->cfecho))
isotp_send_cframe(so);
@@ -1134,11 +1133,10 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
struct can_skb_ext *csx;
struct net_device *dev;
struct canfd_frame *cf;
int ae;
int wait_tx_done;
- s64 hrtimer_sec = ISOTP_ECHO_TIMEOUT;
struct hrtimer *tx_hrt = &so->echotimer;
u32 new_state = ISOTP_SENDING;
u32 my_gen;
u32 old_cfecho;
int off;
@@ -1310,12 +1308,11 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
WRITE_ONCE(so->cfecho, csx->can_skb_uid);
} else {
/* standard flow control check */
new_state = ISOTP_WAIT_FIRST_FC;
- /* start timeout for FC */
- hrtimer_sec = ISOTP_FC_TIMEOUT;
+ /* select txtimer for the FC timeout */
tx_hrt = &so->txtimer;
/* no CF echo tag for isotp_rcv_echo() (FF-mode) */
WRITE_ONCE(so->cfecho, 0);
}
@@ -1332,11 +1329,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, so->frame_txtime),
+ hrtimer_start(tx_hrt, ktime_set(ISOTP_TIMEOUT, 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;
--
2.53.0
^ permalink raw reply related [flat|nested] 29+ messages in thread* [PATCH can-next v3 09/23] can: isotp: check the CAN FD tx_flags in CAN_ISOTP_LL_OPTS
2026-11-30 13:22 [PATCH can-next v3 00/23] can: memcg accounting, CAN_ISOTP fixes and cleanups Oliver Hartkopp
` (7 preceding siblings ...)
2026-11-30 13:22 ` [PATCH can-next v3 08/23] can: isotp: use the N_As timeout for the local echo Oliver Hartkopp
@ 2026-11-30 13:22 ` Oliver Hartkopp
2026-12-02 3:48 ` netdev-bot+sashiko
2026-11-30 13:22 ` [PATCH can-next v3 10/23] can: isotp: reject reserved STmin values in CAN_ISOTP_RECV_FC Oliver Hartkopp
` (13 subsequent siblings)
22 siblings, 1 reply; 29+ messages in thread
From: Oliver Hartkopp @ 2026-11-30 13:22 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 and copied into the CAN FD frames, including
CANFD_ESI and undefined flags.
For the ISO-TP transmission only the bit rate switch (CANFD_BRS) is a
relevant property of the CAN FD frames. The error state indicator
(CANFD_ESI) reflects the error state of the transmitting CAN controller
and is no transmission parameter of the ISO-TP protocol.
This is an intentional tightening of the uAPI and no bug fix: accept
CANFD_BRS and the CANFD_FDF marker (which is set by the CAN core anyway)
and reject other tx_flags with -EINVAL. CAN FD frames with CANFD_ESI
can still be sent with CAN_RAW sockets, e.g. for testing purposes.
The CAN core sets the CANFD_FDF marker in the CAN FD frames when they
are sent. Add CANFD_FDF to the stored tx_flags for CAN FD already in
setsockopt(), so that getsockopt() returns the flags of the created CAN
FD frames. The CAN frames on the bus are not changed by this.
Document the accepted tx_flags in isotp.h and iso15765-2.rst.
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
---
Documentation/networking/iso15765-2.rst | 6 +++++-
include/uapi/linux/can/isotp.h | 2 ++
net/can/isotp.c | 9 +++++++++
3 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/Documentation/networking/iso15765-2.rst b/Documentation/networking/iso15765-2.rst
index 9d758b6e95e3..e8288afe9a01 100644
--- a/Documentation/networking/iso15765-2.rst
+++ b/Documentation/networking/iso15765-2.rst
@@ -285,11 +285,15 @@ where the ``can_isotp_ll_options`` structure has the following contents:
* ``tx_dl``: maximum payload length for transmitted frames, can have one value
among: 8, 12, 16, 20, 24, 32, 48, 64. Values above 8 only apply to CAN FD
traffic (i.e.: ``mtu = CANFD_MTU``).
* ``tx_flags``: flags set into ``struct canfd_frame.flags`` at frame creation.
- Only applies to CAN FD traffic (i.e.: ``mtu = CANFD_MTU``).
+ Only applies to CAN FD traffic (i.e.: ``mtu = CANFD_MTU``) and has to be
+ ``0`` for classical CAN frames. Only the ``CANFD_BRS`` flag (and the
+ ``CANFD_FDF`` marker) can be set, other flags are rejected with ``-EINVAL``.
+ The ``CANFD_FDF`` marker is always added for CAN FD traffic, so that
+ ``getsockopt()`` returns the flags of the created CAN FD frames.
Transmission stmin
~~~~~~~~~~~~~~~~~~
The transmission minimum separation time (stmin) can be forced using the
diff --git a/include/uapi/linux/can/isotp.h b/include/uapi/linux/can/isotp.h
index a2e5aa6f9e82..eb8b5298f7a5 100644
--- a/include/uapi/linux/can/isotp.h
+++ b/include/uapi/linux/can/isotp.h
@@ -117,10 +117,12 @@ struct can_isotp_ll_options {
/* __u8 value : 8,12,16,20,24,32,48,64 */
/* => rx path supports all LL_DL values */
__u8 tx_flags; /* set into struct canfd_frame.flags */
/* at frame creation: e.g. CANFD_BRS */
+ /* only CANFD_BRS and CANFD_FDF allowed */
+ /* CANFD_FDF is always set for CAN FD */
/* Obsolete when the BRS flag is fixed */
/* by the CAN netdriver configuration */
};
/* flags for isotp behaviour */
diff --git a/net/can/isotp.c b/net/can/isotp.c
index aa7bfed15500..992e8d016e9d 100644
--- a/net/can/isotp.c
+++ b/net/can/isotp.c
@@ -1794,12 +1794,21 @@ static int isotp_setsockopt_locked(struct socket *sock, int optname,
if (ll->mtu == CAN_MTU &&
(ll->tx_dl > CAN_MAX_DLEN || ll->tx_flags != 0))
return -EINVAL;
+ /* only CANFD_BRS (and the CANFD_FDF marker) for CAN FD frames */
+ if (ll->mtu == CANFD_MTU &&
+ (ll->tx_flags & ~(CANFD_BRS | CANFD_FDF)))
+ return -EINVAL;
+
memcpy(&so->ll, ll, sizeof(*ll));
+ /* CAN FD frames are always marked with CANFD_FDF */
+ if (so->ll.mtu == CANFD_MTU)
+ so->ll.tx_flags |= CANFD_FDF;
+
/* set ll_dl for tx path to similar place as for rx */
so->tx.ll_dl = ll->tx_dl;
break;
}
--
2.53.0
^ permalink raw reply related [flat|nested] 29+ messages in thread* Re: [PATCH can-next v3 09/23] can: isotp: check the CAN FD tx_flags in CAN_ISOTP_LL_OPTS
2026-11-30 13:22 ` [PATCH can-next v3 09/23] can: isotp: check the CAN FD tx_flags in CAN_ISOTP_LL_OPTS Oliver Hartkopp
@ 2026-12-02 3:48 ` netdev-bot+sashiko
0 siblings, 0 replies; 29+ messages in thread
From: netdev-bot+sashiko @ 2026-12-02 3:48 UTC (permalink / raw)
To: socketcan; +Cc: linux-can, mkl, 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] In isotp_setsockopt_locked() (net/can/isotp.c), the
CAN_ISOTP_LL_OPTS handler now always runs `so->ll.tx_flags |=…
--
can: isotp: check the CAN FD tx_flags in CAN_ISOTP_LL_OPTS
This patch tightens the CAN_ISOTP_LL_OPTS checks so that CAN FD sockets
only accept CANFD_BRS and CANFD_FDF in tx_flags. All other flags are
rejected with -EINVAL. It also always adds CANFD_FDF to the stored
tx_flags for CAN FD, so that getsockopt() reports the flags of the
created CAN FD frames.
> diff --git a/net/can/isotp.c b/net/can/isotp.c
> index aa7bfed15500e..992e8d016e9d4 100644
> --- a/net/can/isotp.c
> +++ b/net/can/isotp.c
> @@ -1796,8 +1796,17 @@ static int isotp_setsockopt_locked(struct socket *sock, int optname,
> (ll->tx_dl > CAN_MAX_DLEN || ll->tx_flags != 0))
> return -EINVAL;
>
> + /* only CANFD_BRS (and the CANFD_FDF marker) for CAN FD frames */
> + if (ll->mtu == CANFD_MTU &&
> + (ll->tx_flags & ~(CANFD_BRS | CANFD_FDF)))
> + return -EINVAL;
> +
> memcpy(&so->ll, ll, sizeof(*ll));
>
> + /* CAN FD frames are always marked with CANFD_FDF */
> + if (so->ll.mtu == CANFD_MTU)
> + so->ll.tx_flags |= CANFD_FDF;
> +
[Severity: Medium]
Could this break a getsockopt()/setsockopt() round trip that worked
before?
Say an unbound socket is set up with {mtu = CANFD_MTU, tx_dl = 64,
tx_flags = 0}. The stored tx_flags now becomes CANFD_FDF (0x04), and
isotp_getsockopt() returns it unchanged:
net/can/isotp.c:isotp_getsockopt() {
...
val.ll = so->ll;
...
}
If userspace then reads the options, changes only mtu to CAN_MTU and
tx_dl to 8, and writes the struct back, the existing classical CAN
check in isotp_setsockopt_locked() rejects it:
if (ll->mtu == CAN_MTU &&
(ll->tx_dl > CAN_MAX_DLEN || ll->tx_flags != 0))
return -EINVAL;
Before this patch the same sequence succeeded. In addition, code that
writes tx_flags = 0 and compares the value it reads back now sees 0x04.
can_send() in net/can/af_can.c already sets the marker on every CAN FD
frame:
cfd->flags |= CANFD_FDF;
So storing it in so->ll does not change what goes on the bus. It only
changes the value userspace sees.
The commit message describes the tightening in terms of CANFD_ESI and
undefined flags. Neither it nor the iso15765-2.rst text says that
CANFD_FDF has to be cleared before switching an existing configuration
back to classical CAN. Would it be better to not store CANFD_FDF in
so->ll.tx_flags? Another option is to ignore or mask CANFD_FDF in the
CAN_MTU check, so the value returned by getsockopt() is always
accepted by setsockopt().
> /* set ll_dl for tx path to similar place as for rx */
> so->tx.ll_dl = ll->tx_dl;
> break;
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130-getsockopt-memcg-isotp-v3-0-21d72c15ad1d%40hartkopp.net
^ permalink raw reply [flat|nested] 29+ messages in thread
* [PATCH can-next v3 10/23] can: isotp: reject reserved STmin values in CAN_ISOTP_RECV_FC
2026-11-30 13:22 [PATCH can-next v3 00/23] can: memcg accounting, CAN_ISOTP fixes and cleanups Oliver Hartkopp
` (8 preceding siblings ...)
2026-11-30 13:22 ` [PATCH can-next v3 09/23] can: isotp: check the CAN FD tx_flags in CAN_ISOTP_LL_OPTS Oliver Hartkopp
@ 2026-11-30 13:22 ` Oliver Hartkopp
2026-11-30 13:22 ` [PATCH can-next v3 11/23] can: isotp: ignore CAN_ISOTP_CHK_PAD_DATA without CAN_ISOTP_RX_PADDING Oliver Hartkopp
` (12 subsequent siblings)
22 siblings, 0 replies; 29+ messages in thread
From: Oliver Hartkopp @ 2026-11-30 13:22 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.
So far the STmin value was intentionally not checked, as stated in the
remark on the CAN_ISOTP_DEFAULT_RECV_* values in isotp.h, so that a
CAN_ISOTP socket could also act like a non-compliant ECU for testing
purposes. But a CAN_ISOTP socket should only send flow control frames
that comply with ISO 15765-2. Flow control frames with reserved STmin
values to test other ISO-TP implementations can be sent with CAN_RAW
sockets.
This is an intentional tightening of the uAPI and no bug fix: reject
the reserved STmin values with -EINVAL before the options are applied.
Update the remark in isotp.h and document the rejected values in
iso15765-2.rst. Additionally fix the name of struct
can_isotp_fc_options in iso15765-2.rst.
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
---
Documentation/networking/iso15765-2.rst | 5 +++--
include/uapi/linux/can/isotp.h | 7 +++----
net/can/isotp.c | 12 ++++++++++--
3 files changed, 16 insertions(+), 8 deletions(-)
diff --git a/Documentation/networking/iso15765-2.rst b/Documentation/networking/iso15765-2.rst
index e8288afe9a01..7d1e4e37e5f0 100644
--- a/Documentation/networking/iso15765-2.rst
+++ b/Documentation/networking/iso15765-2.rst
@@ -240,20 +240,21 @@ to provide the communication parameters for receiving ISO-TP PDUs.
where the ``can_isotp_fc_options`` structure has the following contents:
.. code-block:: C
- struct can_isotp_options {
+ struct can_isotp_fc_options {
u8 bs;
u8 stmin;
u8 wftmax;
};
* ``bs``: blocksize provided in flow control frames.
* ``stmin``: minimum separation time provided in flow control frames; can
- have the following values (others are reserved):
+ have the following values (others are reserved and rejected with
+ ``-EINVAL``):
* 0x00 - 0x7F : 0 - 127 ms
* 0xF1 - 0xF9 : 100 us - 900 us
diff --git a/include/uapi/linux/can/isotp.h b/include/uapi/linux/can/isotp.h
index eb8b5298f7a5..2970570e0b63 100644
--- a/include/uapi/linux/can/isotp.h
+++ b/include/uapi/linux/can/isotp.h
@@ -155,14 +155,13 @@ struct can_isotp_ll_options {
/*
* Remark on CAN_ISOTP_DEFAULT_RECV_* values:
*
* We can strongly assume, that the Linux Kernel implementation of
* CAN_ISOTP is capable to run with BS=0, STmin=0 and WFTmax=0.
- * But as we like to be able to behave as a commonly available ECU,
- * these default settings can be changed via sockopts.
- * For that reason the STmin value is intentionally _not_ checked for
- * consistency and copied directly into the flow control (FC) frame.
+ * These default settings can be changed with the CAN_ISOTP_RECV_FC
+ * sockopt to behave like other ECUs. The reserved STmin values are
+ * rejected with -EINVAL.
*/
/* link layer default values => make use of Classical CAN frames */
#define CAN_ISOTP_DEFAULT_LL_MTU CAN_MTU
diff --git a/net/can/isotp.c b/net/can/isotp.c
index 992e8d016e9d..b4d032576b36 100644
--- a/net/can/isotp.c
+++ b/net/can/isotp.c
@@ -1768,13 +1768,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] 29+ messages in thread* [PATCH can-next v3 11/23] can: isotp: ignore CAN_ISOTP_CHK_PAD_DATA without CAN_ISOTP_RX_PADDING
2026-11-30 13:22 [PATCH can-next v3 00/23] can: memcg accounting, CAN_ISOTP fixes and cleanups Oliver Hartkopp
` (9 preceding siblings ...)
2026-11-30 13:22 ` [PATCH can-next v3 10/23] can: isotp: reject reserved STmin values in CAN_ISOTP_RECV_FC Oliver Hartkopp
@ 2026-11-30 13:22 ` Oliver Hartkopp
2026-12-02 3:48 ` netdev-bot+sashiko
2026-11-30 13:22 ` [PATCH can-next v3 12/23] can: isotp: drop frames without N_PCI Oliver Hartkopp
` (11 subsequent siblings)
22 siblings, 1 reply; 29+ messages in thread
From: Oliver Hartkopp @ 2026-11-30 13:22 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. iso15765-2.rst documents that CAN_ISOTP_CHK_PAD_DATA
is ignored when CAN_ISOTP_RX_PADDING is not specified.
Together with CAN_ISOTP_CHK_PAD_LEN the flag is ignored as documented and
only the optimized frame length is checked. But when
CAN_ISOTP_CHK_PAD_DATA is set without CAN_ISOTP_RX_PADDING and without
CAN_ISOTP_CHK_PAD_LEN, check_pad() does not ignore the flag but rejects
every received frame: SFs and the last CF of a PDU are dropped with
EBADMSG and every FC aborts the transmission with EBADMSG.
Ignore CAN_ISOTP_CHK_PAD_DATA without CAN_ISOTP_RX_PADDING in this case
as well, as documented. This only affects a misconfiguration that has
never been able to receive any PDU. Therefore the patch has no Fixes tag.
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 b4d032576b36..141ecc82cac7 100644
--- a/net/can/isotp.c
+++ b/net/can/isotp.c
@@ -423,12 +423,12 @@ static int check_pad(struct isotp_sock *so, struct canfd_frame *cf,
/* 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;
+ /* no rx padding content => ignore CAN_ISOTP_CHK_PAD_DATA */
+ return 0;
}
/* check datalength of correctly padded CAN frame */
if ((so->opt.flags & CAN_ISOTP_CHK_PAD_LEN) &&
cf->len != padlen(cf->len))
--
2.53.0
^ permalink raw reply related [flat|nested] 29+ messages in thread* Re: [PATCH can-next v3 11/23] can: isotp: ignore CAN_ISOTP_CHK_PAD_DATA without CAN_ISOTP_RX_PADDING
2026-11-30 13:22 ` [PATCH can-next v3 11/23] can: isotp: ignore CAN_ISOTP_CHK_PAD_DATA without CAN_ISOTP_RX_PADDING Oliver Hartkopp
@ 2026-12-02 3:48 ` netdev-bot+sashiko
0 siblings, 0 replies; 29+ messages in thread
From: netdev-bot+sashiko @ 2026-12-02 3:48 UTC (permalink / raw)
To: socketcan; +Cc: linux-can, mkl, 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 fixes a user-visible deviation from documented
behaviour but leaves out a Fixes: tag.
--
can: isotp: ignore CAN_ISOTP_CHK_PAD_DATA without CAN_ISOTP_RX_PADDING
When CAN_ISOTP_CHK_PAD_DATA is set without CAN_ISOTP_RX_PADDING and
without CAN_ISOTP_CHK_PAD_LEN, check_pad() used to return 1, which
rejected every received frame. This patch makes check_pad() return 0 in
that case, so the flag is ignored as iso15765-2.rst documents.
> Ignore CAN_ISOTP_CHK_PAD_DATA without CAN_ISOTP_RX_PADDING in this case
> as well, as documented. This only affects a misconfiguration that has
> never been able to receive any PDU. Therefore the patch has no Fixes tag.
[Severity: Low]
Is "misconfiguration" the right word for this flag combination? The
documentation treats it as a valid setup:
Documentation/networking/iso15765-2.rst:
* 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.
A user who follows the documentation could end up with this
configuration.
Before this patch, check_pad() returned 1 in that case. Each caller then
rejected the frame with EBADMSG:
isotp_rcv_sf() drops every Single Frame
isotp_rcv_cf() drops the last Consecutive Frame of every PDU
isotp_rcv_fc() aborts every transmission waiting for a Flow Control
The branch being changed has not changed since the protocol was
introduced:
/* no valid test against empty value => ignore frame */
return 1;
Should this carry a tag so that stable and the backport tooling can pick
it up?
Fixes: e057dd3fc20f ("can: add ISO 15765-2:2016 transport protocol")
The fact that this combination has never worked shows that nobody relies
on the old behaviour. That makes a backport low risk, but it doesn't seem
to be a reason to leave out the Fixes tag.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130-getsockopt-memcg-isotp-v3-0-21d72c15ad1d%40hartkopp.net
^ permalink raw reply [flat|nested] 29+ messages in thread
* [PATCH can-next v3 12/23] can: isotp: drop frames without N_PCI
2026-11-30 13:22 [PATCH can-next v3 00/23] can: memcg accounting, CAN_ISOTP fixes and cleanups Oliver Hartkopp
` (10 preceding siblings ...)
2026-11-30 13:22 ` [PATCH can-next v3 11/23] can: isotp: ignore CAN_ISOTP_CHK_PAD_DATA without CAN_ISOTP_RX_PADDING Oliver Hartkopp
@ 2026-11-30 13:22 ` Oliver Hartkopp
2026-11-30 13:22 ` [PATCH can-next v3 13/23] can: isotp: drop FF frames with invalid length extension Oliver Hartkopp
` (10 subsequent siblings)
22 siblings, 0 replies; 29+ messages in thread
From: Oliver Hartkopp @ 2026-11-30 13:22 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 the data bytes beyond CAN_DL, e.g. as SF, CF or FC.
As the data of the CAN frame structure is always present, the reads stay
within the skb. But the processed values are no content of the received
CAN frame, e.g. a frame with CAN_DL 0 was processed as SF with SF_DL 0
from the zero-filled data of the CAN drivers.
Drop these frames as they are no valid N_PDUs. The new check only
ensures that the N_PCI (and the AE) is contained in the CAN frame. The
content of the N_PCI is checked afterwards when the specific N_PDU type
is processed. As only invalid frames are affected, there is no Fixes
tag.
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 141ecc82cac7..1be88d33d609 100644
--- a/net/can/isotp.c
+++ b/net/can/isotp.c
@@ -773,10 +773,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] 29+ messages in thread* [PATCH can-next v3 13/23] can: isotp: drop FF frames with invalid length extension
2026-11-30 13:22 [PATCH can-next v3 00/23] can: memcg accounting, CAN_ISOTP fixes and cleanups Oliver Hartkopp
` (11 preceding siblings ...)
2026-11-30 13:22 ` [PATCH can-next v3 12/23] can: isotp: drop frames without N_PCI Oliver Hartkopp
@ 2026-11-30 13:22 ` Oliver Hartkopp
2026-11-30 13:22 ` [PATCH can-next v3 14/23] can: isotp: check the minimum FF_DL Oliver Hartkopp
` (9 subsequent siblings)
22 siblings, 0 replies; 29+ messages in thread
From: Oliver Hartkopp @ 2026-11-30 13:22 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.
So far these FFs were accepted and answered with a FC. Drop them without
sending a FC. Like any other received FF, such a FF terminates an ongoing
reception. As only FFs from a non-compliant sender are affected, there is
no Fixes tag.
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 1be88d33d609..a9fae8bad41f 100644
--- a/net/can/isotp.c
+++ b/net/can/isotp.c
@@ -605,10 +605,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] 29+ messages in thread* [PATCH can-next v3 14/23] can: isotp: check the minimum FF_DL
2026-11-30 13:22 [PATCH can-next v3 00/23] can: memcg accounting, CAN_ISOTP fixes and cleanups Oliver Hartkopp
` (12 preceding siblings ...)
2026-11-30 13:22 ` [PATCH can-next v3 13/23] can: isotp: drop FF frames with invalid length extension Oliver Hartkopp
@ 2026-11-30 13:22 ` Oliver Hartkopp
2026-12-02 3:48 ` netdev-bot+sashiko
2026-11-30 13:22 ` [PATCH can-next v3 15/23] can: isotp: check the data length of the last CF Oliver Hartkopp
` (8 subsequent siblings)
22 siblings, 1 reply; 29+ messages in thread
From: Oliver Hartkopp @ 2026-11-30 13:22 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 in isotp_rcv_ff() added a SF_DL escape offset for LL_DL > 8
on the wrong side and only rejected FF_DL < LL_DL - ae - off - ff_pci_sz.
So it did not even ensure that a CF is needed. It accepted FFs whose
FF_DL fits into the FF itself (e.g. FF_DL 6 for LL_DL 8, FF_DL 61 and 62
for LL_DL 64) and FFs whose FF_DL fits into a SF (e.g. FF_DL 7 for
LL_DL 8). In both cases the receiver sent a FC and waited for a CF that
a compliant sender never sends.
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.
As only FFs from a non-compliant sender are affected and the copied FF
data stays within the receive buffer, there is no Fixes tag.
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 a9fae8bad41f..d534f6f9aa21 100644
--- a/net/can/isotp.c
+++ b/net/can/isotp.c
@@ -577,12 +577,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);
@@ -611,14 +611,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] 29+ messages in thread* Re: [PATCH can-next v3 14/23] can: isotp: check the minimum FF_DL
2026-11-30 13:22 ` [PATCH can-next v3 14/23] can: isotp: check the minimum FF_DL Oliver Hartkopp
@ 2026-12-02 3:48 ` netdev-bot+sashiko
0 siblings, 0 replies; 29+ messages in thread
From: netdev-bot+sashiko @ 2026-12-02 3:48 UTC (permalink / raw)
To: socketcan; +Cc: linux-can, mkl, 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 gets the old receive behaviour wrong for one
of the two FF_DL cases it describes, and it does not mention an…
--
can: isotp: check the minimum FF_DL
This commit changes the FF_DL check in isotp_rcv_ff() so that a First
Frame is ignored when its FF_DL would fit into a Single Frame at the
sender's LL_DL, as ISO 15765-2 requires. FF_DL is now compared against
the maximum SF_DL, the same way isotp_sendmsg() does on the tx path.
> The rx check in isotp_rcv_ff() added a SF_DL escape offset for LL_DL > 8
> on the wrong side and only rejected FF_DL < LL_DL - ae - off - ff_pci_sz.
> So it did not even ensure that a CF is needed. It accepted FFs whose
> FF_DL fits into the FF itself (e.g. FF_DL 6 for LL_DL 8, FF_DL 61 and 62
> for LL_DL 64) and FFs whose FF_DL fits into a SF (e.g. FF_DL 7 for
> LL_DL 8). In both cases the receiver sent a FC and waited for a CF that
> a compliant sender never sends.
[Severity: Low]
Is "in both cases" accurate for the second case?
Take classic CAN (LL_DL 8) with FF_DL = 7 - ae. That is FF_DL 7 with
normal addressing, or FF_DL 6 with extended or mixed addressing. The FF
carries only 6 - ae payload bytes, so one more byte is still needed. A
lenient sender that segments such a PDU does send that CF.
The old check in isotp_rcv_ff() accepted this FF:
if (so->rx.len + ae + off + ff_pci_sz < so->rx.ll_dl)
return 1;
The 1-byte last CF then passed the short-CF check in isotp_rcv_cf(), and
the PDU was delivered to the socket:
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)
return 1;
}
With this patch, sf_max is 8 - SF_PCI_SZ4 - ae = 7 - ae, so the FF is now
ignored:
if (so->rx.len <= sf_max)
return 1;
rx.state stays ISOTP_IDLE. isotp_rcv_cf() then silently drops the CF that
follows:
if (READ_ONCE(so->rx.state) != ISOTP_WAIT_DATA)
return 0;
Ignoring these FFs is correct under ISO 15765-2, since FF_DL is below
FF_DLmin. But this case did not hang before the patch. After the patch,
Linux no longer receives 7 - ae byte PDUs from such senders, which it
received before.
The hang described in the message only applies to FF_DLs that fit
entirely into the FF. That is 6 - ae on LL_DL 8, and ll_dl - 3 - ae to
ll_dl - 2 - ae on LL_DL > 8. For LL_DL > 8, sf_max equals the 12-bit FF
payload capacity, so the case that used to work only exists on LL_DL 8.
This stays true at the end of the series. The later commit "can: isotp:
introduce CAN_ISOTP_MIN_TX_DL" only replaces CAN_MAX_DLEN with
CAN_ISOTP_MIN_TX_DL (both are 8) in this check.
Could the commit message describe the FF_DL = 7 - ae case on LL_DL 8 as a
deliberate tightening that changes interoperability, instead of a
transfer that used to hang?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130-getsockopt-memcg-isotp-v3-0-21d72c15ad1d%40hartkopp.net
^ permalink raw reply [flat|nested] 29+ messages in thread
* [PATCH can-next v3 15/23] can: isotp: check the data length of the last CF
2026-11-30 13:22 [PATCH can-next v3 00/23] can: memcg accounting, CAN_ISOTP fixes and cleanups Oliver Hartkopp
` (13 preceding siblings ...)
2026-11-30 13:22 ` [PATCH can-next v3 14/23] can: isotp: check the minimum FF_DL Oliver Hartkopp
@ 2026-11-30 13:22 ` Oliver Hartkopp
2026-11-30 13:22 ` [PATCH can-next v3 16/23] can: isotp: drop inline keyword, let the compiler decide Oliver Hartkopp
` (7 subsequent siblings)
22 siblings, 0 replies; 29+ messages in thread
From: Oliver Hartkopp @ 2026-11-30 13:22 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.
As only CFs from a non-compliant sender are affected and the copied CF
data stays within the receive buffer, there is no Fixes tag.
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 d534f6f9aa21..8246527f9466 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] 29+ messages in thread* [PATCH can-next v3 16/23] can: isotp: drop inline keyword, let the compiler decide
2026-11-30 13:22 [PATCH can-next v3 00/23] can: memcg accounting, CAN_ISOTP fixes and cleanups Oliver Hartkopp
` (14 preceding siblings ...)
2026-11-30 13:22 ` [PATCH can-next v3 15/23] can: isotp: check the data length of the last CF Oliver Hartkopp
@ 2026-11-30 13:22 ` Oliver Hartkopp
2026-11-30 13:22 ` [PATCH can-next v3 17/23] can: isotp: rename rx_lock as it has become state machine lock Oliver Hartkopp
` (6 subsequent siblings)
22 siblings, 0 replies; 29+ messages in thread
From: Oliver Hartkopp @ 2026-11-30 13:22 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 8246527f9466..d556f4152f07 100644
--- a/net/can/isotp.c
+++ b/net/can/isotp.c
@@ -246,11 +246,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] 29+ messages in thread* [PATCH can-next v3 17/23] can: isotp: rename rx_lock as it has become state machine lock
2026-11-30 13:22 [PATCH can-next v3 00/23] can: memcg accounting, CAN_ISOTP fixes and cleanups Oliver Hartkopp
` (15 preceding siblings ...)
2026-11-30 13:22 ` [PATCH can-next v3 16/23] can: isotp: drop inline keyword, let the compiler decide Oliver Hartkopp
@ 2026-11-30 13:22 ` Oliver Hartkopp
2026-11-30 13:22 ` [PATCH can-next v3 18/23] can: isotp: introduce isotp_invalid_canid() to verify proper CAN-IDs Oliver Hartkopp
` (5 subsequent siblings)
22 siblings, 0 replies; 29+ messages in thread
From: Oliver Hartkopp @ 2026-11-30 13:22 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.
Update the comment in isotp_rcv() which still describes the locking
as not needed in real world use cases.
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
---
net/can/isotp.c | 57 +++++++++++++++++++++++++++++----------------------------
1 file changed, 29 insertions(+), 28 deletions(-)
diff --git a/net/can/isotp.c b/net/can/isotp.c
index d556f4152f07..1d89dc7f6404 100644
--- a/net/can/isotp.c
+++ b/net/can/isotp.c
@@ -179,11 +179,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);
@@ -793,14 +793,15 @@ static void isotp_rcv(struct sk_buff *skb, void *data)
return;
n_pci_type = cf->data[ae] & 0xF0;
/* 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.
+ * CAN frame reception time: so->sm_lock serializes the rx path with
+ * the claim of a transfer in isotp_sendmsg(), with isotp_rcv_echo()
+ * and with the tx shutdown in isotp_release().
*/
- 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) ||
@@ -855,11 +856,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)
{
@@ -1007,14 +1008,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;
@@ -1022,11 +1023,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;
@@ -1061,17 +1062,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)
@@ -1156,19 +1157,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;
@@ -1193,11 +1194,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)) {
@@ -1329,26 +1330,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(ISOTP_TIMEOUT, 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;
@@ -1357,18 +1358,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);
@@ -1407,34 +1408,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;
}
@@ -1500,17 +1501,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);
@@ -2098,11 +2099,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] 29+ messages in thread* [PATCH can-next v3 18/23] can: isotp: introduce isotp_invalid_canid() to verify proper CAN-IDs
2026-11-30 13:22 [PATCH can-next v3 00/23] can: memcg accounting, CAN_ISOTP fixes and cleanups Oliver Hartkopp
` (16 preceding siblings ...)
2026-11-30 13:22 ` [PATCH can-next v3 17/23] can: isotp: rename rx_lock as it has become state machine lock Oliver Hartkopp
@ 2026-11-30 13:22 ` Oliver Hartkopp
2026-11-30 13:22 ` [PATCH can-next v3 19/23] can: isotp: rename variable for the required content length Oliver Hartkopp
` (4 subsequent siblings)
22 siblings, 0 replies; 29+ messages in thread
From: Oliver Hartkopp @ 2026-11-30 13:22 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 1d89dc7f6404..200534879f46 100644
--- a/net/can/isotp.c
+++ b/net/can/isotp.c
@@ -1568,10 +1568,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);
@@ -1586,31 +1603,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] 29+ messages in thread* [PATCH can-next v3 19/23] can: isotp: rename variable for the required content length
2026-11-30 13:22 [PATCH can-next v3 00/23] can: memcg accounting, CAN_ISOTP fixes and cleanups Oliver Hartkopp
` (17 preceding siblings ...)
2026-11-30 13:22 ` [PATCH can-next v3 18/23] can: isotp: introduce isotp_invalid_canid() to verify proper CAN-IDs Oliver Hartkopp
@ 2026-11-30 13:22 ` Oliver Hartkopp
2026-11-30 13:22 ` [PATCH can-next v3 20/23] can: isotp: rename checkpad functions returning bool values Oliver Hartkopp
` (3 subsequent siblings)
22 siblings, 0 replies; 29+ messages in thread
From: Oliver Hartkopp @ 2026-11-30 13:22 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 200534879f46..f629a30d54f1 100644
--- a/net/can/isotp.c
+++ b/net/can/isotp.c
@@ -864,17 +864,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) {
@@ -883,11 +883,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] 29+ messages in thread* [PATCH can-next v3 20/23] can: isotp: rename checkpad functions returning bool values
2026-11-30 13:22 [PATCH can-next v3 00/23] can: memcg accounting, CAN_ISOTP fixes and cleanups Oliver Hartkopp
` (18 preceding siblings ...)
2026-11-30 13:22 ` [PATCH can-next v3 19/23] can: isotp: rename variable for the required content length Oliver Hartkopp
@ 2026-11-30 13:22 ` Oliver Hartkopp
2026-11-30 13:22 ` [PATCH can-next v3 21/23] can: isotp: change return type of functions to void Oliver Hartkopp
` (2 subsequent siblings)
22 siblings, 0 replies; 29+ messages in thread
From: Oliver Hartkopp @ 2026-11-30 13:22 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 f629a30d54f1..483c21e94f2b 100644
--- a/net/can/isotp.c
+++ b/net/can/isotp.c
@@ -392,12 +392,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.
@@ -412,37 +412,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 rx padding content => ignore CAN_ISOTP_CHK_PAD_DATA */
- return 0;
+ return false;
}
/* 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)
@@ -463,11 +464,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);
@@ -554,11 +555,11 @@ static int isotp_rcv_sf(struct sock *sk, struct canfd_frame *cf, int pcilen,
if (!len || len > cf->len - pcilen)
return 1;
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;
@@ -724,11 +725,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] 29+ messages in thread* [PATCH can-next v3 21/23] can: isotp: change return type of functions to void
2026-11-30 13:22 [PATCH can-next v3 00/23] can: memcg accounting, CAN_ISOTP fixes and cleanups Oliver Hartkopp
` (19 preceding siblings ...)
2026-11-30 13:22 ` [PATCH can-next v3 20/23] can: isotp: rename checkpad functions returning bool values Oliver Hartkopp
@ 2026-11-30 13:22 ` Oliver Hartkopp
2026-11-30 13:22 ` [PATCH can-next v3 22/23] can: isotp: rename pointer in isotp_rcv() prototype Oliver Hartkopp
2026-11-30 13:22 ` [PATCH can-next v3 23/23] can: isotp: introduce CAN_ISOTP_MIN_TX_DL Oliver Hartkopp
22 siblings, 0 replies; 29+ messages in thread
From: Oliver Hartkopp @ 2026-11-30 13:22 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 | 67 ++++++++++++++++++++++++++-------------------------------
1 file changed, 31 insertions(+), 36 deletions(-)
diff --git a/net/can/isotp.c b/net/can/isotp.c
index 483c21e94f2b..848767077c24 100644
--- a/net/can/isotp.c
+++ b/net/can/isotp.c
@@ -283,37 +283,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);
@@ -354,11 +354,10 @@ static int isotp_send_fc(struct sock *sk, int ae, u8 flowstatus)
/* start rx timeout watchdog */
hrtimer_start(&so->rxtimer,
ktime_set(ISOTP_TIMEOUT, so->frame_txtime),
HRTIMER_MODE_REL_SOFT);
- return 0;
}
static void isotp_rcv_skb(struct sk_buff *skb, struct sock *sk)
{
struct sockaddr_can *addr = (struct sockaddr_can *)skb->cb;
@@ -444,27 +443,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' */
@@ -474,11 +473,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,47 +538,45 @@ 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;
}
-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;
hrtimer_cancel(&so->rxtimer);
WRITE_ONCE(so->rx.state, ISOTP_IDLE);
if (!len || len > cf->len - pcilen)
- return 1;
+ return;
if ((so->opt.flags & ISOTP_CHECK_PADDING) &&
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;
}
-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 sf_max;
int i;
int ff_pci_sz;
@@ -590,11 +587,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 */
so->rx.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)
- return 1;
+ return;
/* get the FF_DL */
so->rx.len = (cf->data[ae] & 0x0F) << 8;
so->rx.len += cf->data[ae + 1];
@@ -609,21 +606,21 @@ static int isotp_rcv_ff(struct sock *sk, struct canfd_frame *cf, int ae)
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;
+ return;
}
/* 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 <= sf_max)
- return 1;
+ return;
/* 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
@@ -639,11 +636,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++)
@@ -657,41 +654,40 @@ static int isotp_rcv_ff(struct sock *sk, struct canfd_frame *cf, int ae)
hrtimer_start(&so->rxtimer, ktime_set(ISOTP_TIMEOUT, 0),
HRTIMER_MODE_REL_SOFT);
/* send our first FC frame */
isotp_send_fc(sk, ae, ISOTP_FC_CTS);
- return 0;
}
-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) */
@@ -699,21 +695,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++) {
@@ -730,37 +726,36 @@ 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_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;
}
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] 29+ messages in thread* [PATCH can-next v3 22/23] can: isotp: rename pointer in isotp_rcv() prototype
2026-11-30 13:22 [PATCH can-next v3 00/23] can: memcg accounting, CAN_ISOTP fixes and cleanups Oliver Hartkopp
` (20 preceding siblings ...)
2026-11-30 13:22 ` [PATCH can-next v3 21/23] can: isotp: change return type of functions to void Oliver Hartkopp
@ 2026-11-30 13:22 ` Oliver Hartkopp
2026-11-30 13:22 ` [PATCH can-next v3 23/23] can: isotp: introduce CAN_ISOTP_MIN_TX_DL Oliver Hartkopp
22 siblings, 0 replies; 29+ messages in thread
From: Oliver Hartkopp @ 2026-11-30 13:22 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 848767077c24..25f37bb3587b 100644
--- a/net/can/isotp.c
+++ b/net/can/isotp.c
@@ -754,13 +754,13 @@ static void isotp_rcv_cf(struct sock *sk, struct canfd_frame *cf, int ae,
/* we reached the specified blocksize so->rxfc.bs */
isotp_send_fc(sk, ae, ISOTP_FC_CTS);
}
-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] 29+ messages in thread* [PATCH can-next v3 23/23] can: isotp: introduce CAN_ISOTP_MIN_TX_DL
2026-11-30 13:22 [PATCH can-next v3 00/23] can: memcg accounting, CAN_ISOTP fixes and cleanups Oliver Hartkopp
` (21 preceding siblings ...)
2026-11-30 13:22 ` [PATCH can-next v3 22/23] can: isotp: rename pointer in isotp_rcv() prototype Oliver Hartkopp
@ 2026-11-30 13:22 ` Oliver Hartkopp
22 siblings, 0 replies; 29+ messages in thread
From: Oliver Hartkopp @ 2026-11-30 13:22 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.
Use CAN_ISOTP_MIN_TX_DL where a TX_DL or LL_DL value is checked and keep
CAN_MAX_DLEN for the checks of the CAN_DL of a CAN frame.
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
---
include/uapi/linux/can/isotp.h | 6 +++++-
net/can/isotp.c | 6 +++---
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/include/uapi/linux/can/isotp.h b/include/uapi/linux/can/isotp.h
index 2970570e0b63..4c5d129cfdcb 100644
--- a/include/uapi/linux/can/isotp.h
+++ b/include/uapi/linux/can/isotp.h
@@ -160,14 +160,18 @@ struct can_isotp_ll_options {
* These default settings can be changed with the CAN_ISOTP_RECV_FC
* sockopt to behave like other ECUs. The reserved STmin values are
* rejected with -EINVAL.
*/
+/* minimum TX_DL value (link layer data length of a Classical CAN frame) */
+
+#define CAN_ISOTP_MIN_TX_DL CAN_MAX_DLEN
+
/* link layer default values => make use of Classical CAN frames */
#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 25f37bb3587b..58807dd16b6a 100644
--- a/net/can/isotp.c
+++ b/net/can/isotp.c
@@ -610,12 +610,12 @@ static void isotp_rcv_ff(struct sock *sk, struct canfd_frame *cf, int ae)
if (so->rx.len <= MAX_12BIT_PDU_SIZE)
return;
}
/* 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;
+ if (so->rx.ll_dl == CAN_ISOTP_MIN_TX_DL)
+ sf_max = CAN_ISOTP_MIN_TX_DL - SF_PCI_SZ4 - ae;
else
sf_max = so->rx.ll_dl - SF_PCI_SZ8 - ae;
if (so->rx.len <= sf_max)
return;
@@ -1220,11 +1220,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;
--
2.53.0
^ permalink raw reply related [flat|nested] 29+ messages in thread