All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net 0/3] pull-request: can 2026-12-01
@ 2026-12-01 14:46 Marc Kleine-Budde
  2026-12-01 14:46 ` [PATCH net 1/3] can: j1939: avoid address-claim timer deadlock Marc Kleine-Budde
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Marc Kleine-Budde @ 2026-12-01 14:46 UTC (permalink / raw)
  To: netdev; +Cc: davem, kuba, linux-can, kernel

Hello netdev-team,

this is a pull request of 3 patches for net/main.

All patches target the J1939 CAN protocol.

Felix Hoffmann's patch avoids address-claim timer deadlock.

A patch by Piyus Kedia fixes a potential NULL pointer deref.

The last patch is by Hui Peng and fixes the return value of the
setsockopt() callback.

regards,
Marc

===

The following changes since commit 656683f2e292a8ab28b1863a9a8aa0f9417b58a5:

  Merge branch 'net-skbuff-limit-pagecache-folio-refcount' (2026-11-30 22:26:30 -0500)

are available in the Git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can.git tags/linux-can-fixes-for-7.4-20261201

for you to fetch changes up to 4840da2019ad262ce30a050f7679cfbc48d5039d:

  Merge patch series "can: j1939: fixes for net" (2026-12-01 09:33:45 +0100)

----------------------------------------------------------------
linux-can-fixes-for-7.4-20261201

----------------------------------------------------------------
Felix Hoffmann (1):
      can: j1939: avoid address-claim timer deadlock

Hui Peng (1):
      can: j1939: return 0 instead of user value in j1939_sk_setsockopt_flag()

Marc Kleine-Budde (1):
      Merge patch series "can: j1939: fixes for net"

Piyus Kedia (1):
      can: j1939: do not pass a NULL skb to the socket layer

 net/can/j1939/bus.c        | 34 ++++++++++++++++++++++++++++++++--
 net/can/j1939/j1939-priv.h |  1 +
 net/can/j1939/socket.c     |  2 +-
 net/can/j1939/transport.c  | 14 +++++++++++---
 4 files changed, 45 insertions(+), 6 deletions(-)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH net 1/3] can: j1939: avoid address-claim timer deadlock
  2026-12-01 14:46 [PATCH net 0/3] pull-request: can 2026-12-01 Marc Kleine-Budde
@ 2026-12-01 14:46 ` Marc Kleine-Budde
  2026-12-01 14:53   ` netdev-bot+sinfo
  2026-12-02 11:40   ` patchwork-bot+netdevbpf
  2026-12-01 14:46 ` [PATCH net 2/3] can: j1939: do not pass a NULL skb to the socket layer Marc Kleine-Budde
  2026-12-01 14:46 ` [PATCH net 3/3] can: j1939: return 0 instead of user value in j1939_sk_setsockopt_flag() Marc Kleine-Budde
  2 siblings, 2 replies; 6+ messages in thread
From: Marc Kleine-Budde @ 2026-12-01 14:46 UTC (permalink / raw)
  To: netdev
  Cc: davem, kuba, linux-can, kernel, Felix Hoffmann, stable,
	Oleksij Rempel, Marc Kleine-Budde

From: Felix Hoffmann <f3lix.dev@gmx.de>

j1939_ac_process() holds priv->lock while synchronously canceling an
ECU's address-claim hrtimer. The timer callback takes the same lock. If the
callback starts on another CPU after the receive path takes the lock, the
callback waits for priv->lock while hrtimer_cancel() waits for the callback
to finish. This deadlocks both CPUs and makes the system unresponsive.

Replace the callback's blocking lock acquisition with write_trylock(). If
the lock is busy, move the expiry forward and restart the timer. This lets
a concurrent hrtimer_cancel() observe the callback finish and remove the
requeued timer. Without a cancellation, address mapping is retried shortly.

The failed write trylock does not necessarily mean that the address-claim
writer owns priv->lock. Receive processing also takes its read side for
other frames, and an active reader prevents write_trylock() from
succeeding. Document both the address-claim writer and receive-path readers
as possible sources of contention.

Name the 1 ms retry interval J1939_ECU_TIMER_RETRY_DELAY_MS instead of
using a literal in the callback. Track consecutive failures per ECU, reset
the counter when its timer starts, and emit a warning guarded by
net_ratelimit() on the fifth retry. Five is a pragmatic threshold for
detecting unusual delay; it is not specified by J1939.

The timer uses HRTIMER_MODE_REL_SOFT, so its callback runs from
HRTIMER_SOFTIRQ with bottom halves already disabled. write_trylock() does
not change bottom-half state and must therefore pair with write_unlock() on
success. The write_lock_bh()/write_unlock_bh() pair is unnecessary in this
context.

This patch was created with LLM assistance.

Fixes: 9d71dd0c7009 ("can: add support of SAE J1939 protocol")
Cc: stable@vger.kernel.org
Signed-off-by: Felix Hoffmann <f3lix.dev@gmx.de>
Acked-by: Oleksij Rempel <o.rempel@pengutronix.de>
Link: https://patch.msgid.link/20260803101503.21023-1-f3lix.dev@gmx.de
[mkl: convert Assisted-by: tag into prose]
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 net/can/j1939/bus.c        | 34 ++++++++++++++++++++++++++++++++--
 net/can/j1939/j1939-priv.h |  1 +
 2 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/net/can/j1939/bus.c b/net/can/j1939/bus.c
index cdc3c0a71937..eb9a3fd847f4 100644
--- a/net/can/j1939/bus.c
+++ b/net/can/j1939/bus.c
@@ -10,10 +10,19 @@
  * Since rtnetlink, no real bus is used.
  */
 
+#include <linux/net.h>
+
 #include <net/sock.h>
 
 #include "j1939-priv.h"
 
+#define J1939_ECU_TIMER_RETRY_DELAY_MS 1
+/*
+ * J1939 does not specify a lock-contention retry count. Five retries are a
+ * pragmatic threshold for warning about an unusual address-claim delay.
+ */
+#define J1939_ECU_TIMER_RETRY_WARN 5
+
 static void __j1939_ecu_release(struct kref *kref)
 {
 	struct j1939_ecu *ecu = container_of(kref, struct j1939_ecu, kref);
@@ -109,6 +118,8 @@ void j1939_ecu_unmap_all(struct j1939_priv *priv)
 
 void j1939_ecu_timer_start(struct j1939_ecu *ecu)
 {
+	ecu->ac_timer_retries = 0;
+
 	/* The ECU is held here and released in the
 	 * j1939_ecu_timer_handler() or j1939_ecu_timer_cancel().
 	 */
@@ -131,7 +142,26 @@ static enum hrtimer_restart j1939_ecu_timer_handler(struct hrtimer *hrtimer)
 		container_of(hrtimer, struct j1939_ecu, ac_timer);
 	struct j1939_priv *priv = ecu->priv;
 
-	write_lock_bh(&priv->lock);
+	/*
+	 * j1939_ac_process() cancels this timer while holding priv->lock.
+	 * Don't block here, otherwise the timer and receive paths can
+	 * deadlock waiting for each other on different CPUs. Retry shortly
+	 * if the lock is held by the address claim writer or by a reader on
+	 * the receive path.
+	 */
+	if (!write_trylock(&priv->lock)) {
+		ecu->ac_timer_retries++;
+		if (ecu->ac_timer_retries == J1939_ECU_TIMER_RETRY_WARN &&
+		    net_ratelimit())
+			netdev_warn(priv->ndev,
+				    "address claim timer retried %u times due to lock contention, name: 0x%016llx\n",
+				    ecu->ac_timer_retries, ecu->name);
+
+		hrtimer_forward_now(hrtimer,
+				    ms_to_ktime(J1939_ECU_TIMER_RETRY_DELAY_MS));
+		return HRTIMER_RESTART;
+	}
+
 	/* TODO: can we test if ecu->addr is unicast before starting
 	 * the timer?
 	 */
@@ -141,7 +171,7 @@ static enum hrtimer_restart j1939_ecu_timer_handler(struct hrtimer *hrtimer)
 	 * j1939_ecu_timer_start().
 	 */
 	j1939_ecu_put(ecu);
-	write_unlock_bh(&priv->lock);
+	write_unlock(&priv->lock);
 
 	return HRTIMER_NORESTART;
 }
diff --git a/net/can/j1939/j1939-priv.h b/net/can/j1939/j1939-priv.h
index cf26352d1d8c..5ed4f4b592e3 100644
--- a/net/can/j1939/j1939-priv.h
+++ b/net/can/j1939/j1939-priv.h
@@ -36,6 +36,7 @@ struct j1939_ecu {
 
 	/* indicates that this ecu successfully claimed @sa as its address */
 	struct hrtimer ac_timer;
+	unsigned int ac_timer_retries;
 	struct kref kref;
 	struct j1939_priv *priv;
 	netdevice_tracker priv_dev_tracker;

base-commit: 656683f2e292a8ab28b1863a9a8aa0f9417b58a5
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH net 2/3] can: j1939: do not pass a NULL skb to the socket layer
  2026-12-01 14:46 [PATCH net 0/3] pull-request: can 2026-12-01 Marc Kleine-Budde
  2026-12-01 14:46 ` [PATCH net 1/3] can: j1939: avoid address-claim timer deadlock Marc Kleine-Budde
@ 2026-12-01 14:46 ` Marc Kleine-Budde
  2026-12-01 14:46 ` [PATCH net 3/3] can: j1939: return 0 instead of user value in j1939_sk_setsockopt_flag() Marc Kleine-Budde
  2 siblings, 0 replies; 6+ messages in thread
From: Marc Kleine-Budde @ 2026-12-01 14:46 UTC (permalink / raw)
  To: netdev
  Cc: davem, kuba, linux-can, kernel, Piyus Kedia, Oleksij Rempel,
	stable, Kapil Vaswani, Marc Kleine-Budde

From: Piyus Kedia <piyus@iiitd.ac.in>

Check for a NULL skb in j1939_session_completed() and end the session
with EPROTO, so that sockets reading the error queue get an RX abort.
Print a rate-limited warning, because a peer can cause the missing skb.

A peer can send an ETP DPO at or beyond the end of the message.  When
the session completes after that, j1939_session_completed() finds no
skb and passes NULL to j1939_sk_recv(), which dereferences it.  The
dereference happens in the receive softirq, so it is fatal:

  BUG: KASAN: null-ptr-deref in j1939_sk_recv+0xd4/0x3c0
  Read of size 8 at addr 0000000000000018 by task repro/9528
   <IRQ>
   j1939_sk_recv+0xd4/0x3c0
   j1939_xtp_rx_eoma+0x207/0x300
   j1939_tp_recv+0x64c/0xa10
   j1939_can_recv+0x51a/0x640
   can_receive+0x19e/0x2a0
   __netif_receive_skb+0x120/0x270
   process_backlog+0x427/0xd50
   net_rx_action+0x3f7/0x870
   handle_softirqs+0x1e5/0x6a0
   </IRQ>
   netif_rx+0x89/0xa0
   can_send+0x71f/0x7e0
   raw_sendmsg+0x9ed/0xab0
  Kernel panic - not syncing: Fatal exception in interrupt

This is only a mitigation, and it leaves the transport protocol alone
on purpose.  The DPO is still not checked when it arrives, and no abort
frame is sent to the peer.  Those checks need further changes in the
session code, so they follow as their own patch once this one is in.

Found by AI-driven fuzzing built on top of syzkaller; the analysis was
then checked by hand against the code.  Measured on current net.git main
with KASAN and kasan_multi_shot=1, over one vcan pair, with the same
reproducer each time: without this patch the report above and the panic;
with it no report and no panic, and the new warning fires once per round
of the reproducer, so the path is still being reached and is now handled.

Fixes: 9d71dd0c7009 ("can: add support of SAE J1939 protocol")
Suggested-by: Oleksij Rempel <o.rempel@pengutronix.de>
Cc: stable@vger.kernel.org
Co-developed-by: Kapil Vaswani <kapil@presceralabs.ai>
Signed-off-by: Kapil Vaswani <kapil@presceralabs.ai>
Signed-off-by: Piyus Kedia <piyus@iiitd.ac.in>
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
Link: https://patch.msgid.link/20261201-ore-j1939-fixes-2026-11-30-v1-1-a40cb7bf9569@pengutronix.de
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 net/can/j1939/transport.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/net/can/j1939/transport.c b/net/can/j1939/transport.c
index 8fcfd13e5e6f..fa30273df326 100644
--- a/net/can/j1939/transport.c
+++ b/net/can/j1939/transport.c
@@ -1243,9 +1243,17 @@ static void j1939_session_completed(struct j1939_session *session)
 
 	if (!session->transmission) {
 		se_skb = j1939_session_skb_get(session);
-		/* distribute among j1939 receivers */
-		j1939_sk_recv(session->priv, se_skb);
-		consume_skb(se_skb);
+		if (!se_skb) {
+			if (net_ratelimit())
+				netdev_warn(session->priv->ndev,
+					    "%s: 0x%p: no skb found for completed session\n",
+					    __func__, session);
+			session->err = EPROTO;
+		} else {
+			/* distribute among j1939 receivers */
+			j1939_sk_recv(session->priv, se_skb);
+			consume_skb(se_skb);
+		}
 	}
 
 	j1939_session_deactivate_activate_next(session);
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH net 3/3] can: j1939: return 0 instead of user value in j1939_sk_setsockopt_flag()
  2026-12-01 14:46 [PATCH net 0/3] pull-request: can 2026-12-01 Marc Kleine-Budde
  2026-12-01 14:46 ` [PATCH net 1/3] can: j1939: avoid address-claim timer deadlock Marc Kleine-Budde
  2026-12-01 14:46 ` [PATCH net 2/3] can: j1939: do not pass a NULL skb to the socket layer Marc Kleine-Budde
@ 2026-12-01 14:46 ` Marc Kleine-Budde
  2 siblings, 0 replies; 6+ messages in thread
From: Marc Kleine-Budde @ 2026-12-01 14:46 UTC (permalink / raw)
  To: netdev
  Cc: davem, kuba, linux-can, kernel, Hui Peng, Oleksij Rempel,
	Simon Horman, Marc Kleine-Budde

From: Hui Peng <benquike@gmail.com>

In `j1939_sk_setsockopt_flag()`, after copying the integer option value
`tmp` from userspace and updating `jsk->state`, the function returns
`tmp` instead of `0`.

If a caller passes a negative integer (e.g., `-1`) to enable
`SO_J1939_BROADCAST` or `SO_J1939_PROMISC`, `if (tmp)` sets `jsk->state
|= flag` and then returns the negative value as an error code from
`setsockopt()`. If a caller passes a positive non-zero integer (e.g.,
`1`), `setsockopt()` violates POSIX by returning `1` instead of `0`.

Return `0` on success in `j1939_sk_setsockopt_flag()`.

The author prepared this patch with the help of an LLM.

Fixes: 9d71dd0c7009 ("can: add support of SAE J1939 protocol")
Signed-off-by: Hui Peng <benquike@gmail.com>
[o.rempel: replaced the Assisted-by tag with a sentence in the message]
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
Reviewed-by: Simon Horman <horms@kernel.org>
Acked-by: Oleksij Rempel <o.rempel@pengutronix.de>
Link: https://patch.msgid.link/20261201-ore-j1939-fixes-2026-11-30-v1-2-a40cb7bf9569@pengutronix.de
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 net/can/j1939/socket.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/can/j1939/socket.c b/net/can/j1939/socket.c
index 50a598ef5fd4..1d4af472de4a 100644
--- a/net/can/j1939/socket.c
+++ b/net/can/j1939/socket.c
@@ -688,7 +688,7 @@ static int j1939_sk_setsockopt_flag(struct j1939_sock *jsk, sockptr_t optval,
 	else
 		jsk->state &= ~flag;
 	release_sock(&jsk->sk);
-	return tmp;
+	return 0;
 }
 
 static int j1939_sk_setsockopt(struct socket *sock, int level, int optname,
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH net 1/3] can: j1939: avoid address-claim timer deadlock
  2026-12-01 14:46 ` [PATCH net 1/3] can: j1939: avoid address-claim timer deadlock Marc Kleine-Budde
@ 2026-12-01 14:53   ` netdev-bot+sinfo
  2026-12-02 11:40   ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 6+ messages in thread
From: netdev-bot+sinfo @ 2026-12-01 14:53 UTC (permalink / raw)
  To: Marc Kleine-Budde
  Cc: netdev, davem, kuba, linux-can, kernel, Felix Hoffmann, stable,
	Oleksij Rempel

Hi!

This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:

 - How the issue was discovered, e.g. hit in production, hit during
   development, syzbot report, manual code inspection, LLM or static
   analysis tool scan.

 - Whether the issue was actually triggered, or is only theoretical
   (e.g. found by LLM and not proven at runtime). If it was triggered
   please include the symptoms, like the stack trace or kernel messages.

Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.

*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
-- 
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net 1/3] can: j1939: avoid address-claim timer deadlock
  2026-12-01 14:46 ` [PATCH net 1/3] can: j1939: avoid address-claim timer deadlock Marc Kleine-Budde
  2026-12-01 14:53   ` netdev-bot+sinfo
@ 2026-12-02 11:40   ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-12-02 11:40 UTC (permalink / raw)
  To: Marc Kleine-Budde
  Cc: netdev, davem, kuba, linux-can, kernel, f3lix.dev, stable,
	o.rempel

Hello:

This series was applied to netdev/net.git (main)
by Marc Kleine-Budde <mkl@pengutronix.de>:

On Tue,  1 Dec 2026 15:46:10 +0100 you wrote:
> From: Felix Hoffmann <f3lix.dev@gmx.de>
> 
> j1939_ac_process() holds priv->lock while synchronously canceling an
> ECU's address-claim hrtimer. The timer callback takes the same lock. If the
> callback starts on another CPU after the receive path takes the lock, the
> callback waits for priv->lock while hrtimer_cancel() waits for the callback
> to finish. This deadlocks both CPUs and makes the system unresponsive.
> 
> [...]

Here is the summary with links:
  - [net,1/3] can: j1939: avoid address-claim timer deadlock
    https://git.kernel.org/netdev/net/c/32ef7b4de77b
  - [net,2/3] can: j1939: do not pass a NULL skb to the socket layer
    https://git.kernel.org/netdev/net/c/0495e9b28d47
  - [net,3/3] can: j1939: return 0 instead of user value in j1939_sk_setsockopt_flag()
    https://git.kernel.org/netdev/net/c/f8308e0e3715

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-12-02 11:40 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 14:46 [PATCH net 0/3] pull-request: can 2026-12-01 Marc Kleine-Budde
2026-12-01 14:46 ` [PATCH net 1/3] can: j1939: avoid address-claim timer deadlock Marc Kleine-Budde
2026-12-01 14:53   ` netdev-bot+sinfo
2026-12-02 11:40   ` patchwork-bot+netdevbpf
2026-12-01 14:46 ` [PATCH net 2/3] can: j1939: do not pass a NULL skb to the socket layer Marc Kleine-Budde
2026-12-01 14:46 ` [PATCH net 3/3] can: j1939: return 0 instead of user value in j1939_sk_setsockopt_flag() Marc Kleine-Budde

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.