Skip to contentSkip to conversation

can: j1939: reject a CTS that names more packets than the message has

PATCH In review Chaosheng Qu 1 participant 1 message Nov 11

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v8 4/4 can: j1939: reject a CTS that names more packets than the message has

j1939_xtp_rx_cts_one() rejects a zero packet number and a window above pkt.block, but not a packet number above pkt.total. It then stores "pkt - 1" in pkt.tx_acked, and the transmitter reports that value back in an ETP.CM_DPO.

That value is what j1939_xtp_rx_dpo_one() now bounds, so an oversized CTS is currently caught one step later and reported as a bad EDPO offset. Reject it where it originates instead, with the abort code that describes
it: J1939_XTP_ABORT_ECTS_TOO_BIG, "ECTS requested packets exceeds message size".

---
 net/can/j1939/transport.c | 9 +++++++++
 1 file changed, 9 insertions(+)
net/can/j1939/transport.c +9 -0
index 124054668650..49ddf6c8f22d 100644
@@ -1512,6 +1512,15 @@ j1939_xtp_rx_cts_one(struct j1939_session *session, struct sk_buff *skb)
 		goto out_session_cancel;
 	else if (dat[1] > session->pkt.block /* 0xff for etp */)
 		goto out_session_cancel;
+	else if (pkt > session->pkt.total) {
+		/* The responder asks for more packets than the message has.
+		 * pkt - 1 becomes pkt.tx_acked below, and the transmitter
+		 * reports that value in an ETP.CM_DPO, where it would name a
+		 * packet past the end of the message.
+		 */
+		err = J1939_XTP_ABORT_ECTS_TOO_BIG;
+		goto out_session_cancel;
+	}
 
 	/* set packet counters only when not CTS(0) */
 	session->pkt.tx_acked = pkt - 1;
Signature · 1 line
2.43.0