All of lore.kernel.org
 help / color / mirror / Atom feed
From: Liu Chao <liuc63@xiaopeng.com>
To: Robin van der Gracht <robin@protonic.nl>,
	Oleksij Rempel <o.rempel@pengutronix.de>,
	Oliver Hartkopp <socketcan@hartkopp.net>,
	Marc Kleine-Budde <mkl@pengutronix.de>
Cc: kernel@pengutronix.de, linux-can@vger.kernel.org,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org, Liu Chao <liuc63@xiaopeng.com>
Subject: [PATCH net v2 0/2] can: j1939: tighten TP receive-path checks
Date: Thu, 10 Sep 2026 01:31:02 +0800	[thread overview]
Message-ID: <20260909173105.158202-1-liuc63@xiaopeng.com> (raw)

j1939_xtp_rx_rts_session_new() allocates the receive buffer based on
the message size from RTS dat[1..2], but then overwrites pkt.total
with dat[3] even when they disagree.  A sender can set dat[3] smaller
so the session completes after fewer packets than the buffer was sized
for, delivering a short message to userspace.  With dat[3]=0 the
session just hangs until timeout.

eb96c5890792 ("can: j1939: transport: j1939_session_fresh_new():
initialize receive buffer") addressed a related symptom by zeroing the
receive buffer, but the root cause -- blindly trusting dat[3] -- is
still there.

Patch 1 aborts the session when dat[3] does not match.
Patch 2 adds a pkt.rx check in the EOMA handler for unicast receive
sessions (BAM completes via the final flag in j1939_xtp_rx_dat_one,
not through EOMA).

Note: The handling of sessions already in WAITING_ABORT in
j1939_session_cancel() is fragile in general -- the cts_one and
dat_one cancel paths carry the same hazard unguarded.  The pre-existing
AB-BA deadlock between active_session_list_lock and the rxtimer callback
is likewise not addressed; this series does not change the locking.
Both belong in separate patches.

v2:
  - keep the EOMA size-mismatch warning for transmitter sessions (was
    inadvertently suppressed in v1 by the !session->transmission guard)
  - guard out_session_cancel against J1939_SESSION_WAITING_ABORT state
  - add 'net' to subject prefix
  - use netdev_warn_once for the new warnings to limit log spam from
    malicious frames
  - fix format specifiers: %u for unsigned, %d for int
  - drop redundant dat[3] == 0 check (a zero count already fails the
    != pkt.total test, since pkt.total >= 2 for TP)
  - patch 1: explain why neither direction of mismatch works today

  The first two items address the sashiko-bot review of patch 2:
  https://lore.kernel.org/all/20260908145715.D70BD1F00A3D@smtp.kernel.org/

v1: https://lore.kernel.org/all/20260907145640.1106170-1-liuc63@xiaopeng.com/

Liu Chao (2):
  can: j1939: reject TP RTS with wrong packet count
  can: j1939: check received packet count before completing session

 net/can/j1939/transport.c | 41 +++++++++++++++++++++++++++++++++------
 1 file changed, 35 insertions(+), 6 deletions(-)

-- 
2.50.1


             reply	other threads:[~2026-09-09 17:31 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-09 17:31 Liu Chao [this message]
2026-09-09 17:31 ` [PATCH net v2 1/2] can: j1939: reject TP RTS with wrong packet count Liu Chao
2026-09-09 17:31 ` [PATCH net v2 2/2] can: j1939: check received packet count before completing session Liu Chao
2026-09-10 17:37   ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260909173105.158202-1-liuc63@xiaopeng.com \
    --to=liuc63@xiaopeng.com \
    --cc=kernel@pengutronix.de \
    --cc=linux-can@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mkl@pengutronix.de \
    --cc=netdev@vger.kernel.org \
    --cc=o.rempel@pengutronix.de \
    --cc=robin@protonic.nl \
    --cc=socketcan@hartkopp.net \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.