Skip to content

Commit e052d05

Browse files
oleremmarckleinebudde
authored andcommitted
can: j1939: transport: j1939_xtp_rx_dat_one(): compare own packets to detect corruptions
Since the stack relays on receiving own packets, it was overwriting own transmit buffer from received packets. At least theoretically, the received echo buffer can be corrupt or changed and the session partner can request to resend previous data. In this case we will re-send bad data. With this patch we will stop to overwrite own TX buffer and use it for sanity checking. Signed-off-by: Oleksij Rempel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Marc Kleine-Budde <[email protected]>
1 parent 840835c commit e052d05

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

net/can/j1939/transport.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1792,7 +1792,20 @@ static void j1939_xtp_rx_dat_one(struct j1939_session *session,
17921792
}
17931793

17941794
tpdat = se_skb->data;
1795-
memcpy(&tpdat[offset], &dat[1], nbytes);
1795+
if (!session->transmission) {
1796+
memcpy(&tpdat[offset], &dat[1], nbytes);
1797+
} else {
1798+
int err;
1799+
1800+
err = memcmp(&tpdat[offset], &dat[1], nbytes);
1801+
if (err)
1802+
netdev_err_once(priv->ndev,
1803+
"%s: 0x%p: Data of RX-looped back packet (%*ph) doesn't match TX data (%*ph)!\n",
1804+
__func__, session,
1805+
nbytes, &dat[1],
1806+
nbytes, &tpdat[offset]);
1807+
}
1808+
17961809
if (packet == session->pkt.rx)
17971810
session->pkt.rx++;
17981811

0 commit comments

Comments
 (0)