Linux CAN drivers development
 help / color / mirror / Atom feed
* [PATCH v15 0/3] can: j1939: make module more robust
@ 2026-11-17 15:56 Tetsuo Handa
  2026-11-17 15:56 ` [PATCH v15 1/3] can: j1939: fix possibility of UAF Tetsuo Handa
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Tetsuo Handa @ 2026-11-17 15:56 UTC (permalink / raw)
  To: linux-can, Marc Kleine-Budde, Oleksij Rempel,
	Robin van der Gracht, kernel, Oliver Hartkopp

This series is intended to address the following problems.

# Problem 1

Since module refcount is currently associated with lifecycle of j1939
sockets, we need to make sure that all resources associated with socket
("struct j1939_priv", "struct j1939_ecu", "struct j1939_session") are
synchronously destructed before socket is destructed. Otherwise,
j1939_module_exit() can complete and memory for this module is unmapped
and cause UAF.

# Problem 2

This module takes a refcount upon arming a hrtimer and drops that refcount
when the hrtimer is fired or canceled, but nothing guarantees that the
callback is no longer running when the last refcount is dropped. We need
to make sure that hrtimer callbacks are no longer running before calling
kfree(). But we can't use hrtimer_cancel() from atomic context.

# Problem 3

Since j1939_ac_recv() and j1939_ac_fixup() are calling j1939_ecu_put()
without priv->lock held for write, list corruption might happen if the
last user called j1939_ecu_put() without priv->lock held for write. But
requiring all j1939_ecu_put() callers to hold priv->lock for write might
be a difficult change.

# Problem 4

Since

  j1939_ecu_get(ecu);
  priv->ents[ecu->addr] = ecu;

in j1939_ecu_map_locked() from j1939_ecu_timer_handler() can succeed
even after

  priv->ents[ecu->addr] = NULL;
  j1939_ecu_put(ecu);

in j1939_ecu_unmap_locked() from j1939_ecu_unmap_all() from
__j1939_rx_release() from j1939_netdev_stop() has completed.

# Problem 5

Since j1939_ecu_timer_cancel() is calling hrtimer_cancel() with priv->lock
held for write while j1939_ecu_timer_handler() takes priv->lock, a hard-
lockup (if CONFIG_PREEMPT_RT=n && CONFIG_SMP=y) or a deadlock between
priv->lock and cpu_base->softirq_expiry_lock (if CONFIG_PREEMPT_RT=y) will
happen when hrtimer_cancel() calls hrtimer_cancel_wait_running().


[PATCH v15 1/3] can: j1939: fix possibility of UAF
[PATCH v15 2/3] can: j1939: fix "struct j1939_ecu" refcount leak
[PATCH v15 3/3] can: j1939: fix possibility of hard-lockup/deadlock in j1939_ecu_timer_cancel()
---
Changes since v14:
- Reorganized series, based on review comments by netdev-bot+sashiko in v14.
- Re-added "can: j1939: fix possibility of hard-lockup/deadlock in j1939_ecu_timer_cancel()"
  using a different approach.

Changes since v13:
- Dropped "can: j1939: fix possibility of hard-lockup/deadlock in j1939_ecu_timer_cancel()" for now.
  Although sashiko will mention that this problem is not addressed, this problem is too complicated
  to handle within this series.
- Added "can: j1939: defer j1939_session_destroy() to WQ context", per findings by sashiko in v13.

Changes since v12:
- Added a cover letter and split the series into 6 logical patches (1 patch per problem).
- Deferred __j1939_priv_release() to WQ context to simplify "struct j1939_ecu" refcount leak fix
- Fixed findings by sashiko in v12.

 net/can/j1939/address-claim.c |    4 +++
 net/can/j1939/bus.c           |   81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------
 net/can/j1939/j1939-priv.h    |   11 ++++++++++
 net/can/j1939/main.c          |   48 ++++++++++++++++++++++++++++++++++++++++-------
 net/can/j1939/transport.c     |   23 +++++++++++++++++++---
 5 files changed, 137 insertions(+), 30 deletions(-)

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

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

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-17 15:56 [PATCH v15 0/3] can: j1939: make module more robust Tetsuo Handa
2026-11-17 15:56 ` [PATCH v15 1/3] can: j1939: fix possibility of UAF Tetsuo Handa
2026-11-17 15:57 ` [PATCH v15 2/3] can: j1939: fix "struct j1939_ecu" refcount leak Tetsuo Handa
2026-11-27 11:12   ` Dmitry Antipov
2026-11-17 15:57 ` [PATCH v15 3/3] can: j1939: fix possibility of hard-lockup/deadlock in j1939_ecu_timer_cancel() Tetsuo Handa
2026-11-20 11:35 ` [PATCH v15 0/3] can: j1939: make module more robust Tetsuo Handa
2026-11-27  8:32   ` Oleksij Rempel
2026-11-27 12:01     ` Tetsuo Handa

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox