All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v16 0/5] can: j1939: make module more robust
@ 2026-12-04 16:03 Tetsuo Handa
  2026-12-04 16:03 ` [PATCH v16 1/5] can: j1939: fix possibility of UAF on j1939_priv upon module unload Tetsuo Handa
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: Tetsuo Handa @ 2026-12-04 16:03 UTC (permalink / raw)
  To: linux-can

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_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 4

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.



[PATCH v16 1/5] can: j1939: fix possibility of UAF on j1939_priv upon module unload
[PATCH v16 2/5] can: j1939: fix possibility of UAF on j1939_session upon module unload
[PATCH v16 3/5] can: j1939: fix possibility of UAF on j1939_ecu upon module unload
[PATCH v16 4/5] can: j1939: fix "struct j1939_ecu" refcount leak
[PATCH v16 5/5] can: j1939: fix possibility of list corruption in __j1939_ecu_release()
---
Changes since v15:
- Break "can: j1939: fix possibility of UAF" into 4 smaller patches.
- Updated "can: j1939: fix possibility of UAF" to use plain counter instead of module ref.
- Updated "can: j1939: fix "struct j1939_ecu" refcount leak" not to depend on
  "can: j1939: fix possibility of list corruption in __j1939_ecu_release()".
- Dropped "can: j1939: fix possibility of hard-lockup/deadlock in j1939_ecu_timer_cancel()"
  because 32ef7b4de77b ("can: j1939: avoid address-claim timer deadlock") was accepted.

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/bus.c        |   60 ++++++++++++++++++++++++++++++++++++++++++++----------------
 net/can/j1939/j1939-priv.h |    8 ++++++++
 net/can/j1939/main.c       |   53 ++++++++++++++++++++++++++++++++++++++++++++++-------
 net/can/j1939/transport.c  |   23 ++++++++++++++++++++---
 4 files changed, 118 insertions(+), 26 deletions(-)

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

end of thread, other threads:[~2026-12-04 16:34 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 16:03 [PATCH v16 0/5] can: j1939: make module more robust Tetsuo Handa
2026-12-04 16:03 ` [PATCH v16 1/5] can: j1939: fix possibility of UAF on j1939_priv upon module unload Tetsuo Handa
2026-12-04 16:34   ` sashiko-bot
2026-12-04 16:04 ` [PATCH v16 2/5] can: j1939: fix possibility of UAF on j1939_session " Tetsuo Handa
2026-12-04 16:29   ` sashiko-bot
2026-12-04 16:04 ` [PATCH v16 3/5] can: j1939: fix possibility of UAF on j1939_ecu " Tetsuo Handa
2026-12-04 16:04 ` [PATCH v16 4/5] can: j1939: fix "struct j1939_ecu" refcount leak Tetsuo Handa
2026-12-04 16:23   ` sashiko-bot
2026-12-04 16:05 ` [PATCH v16 5/5] can: j1939: fix possibility of list corruption in __j1939_ecu_release() Tetsuo Handa
2026-12-04 16:23   ` sashiko-bot

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.