Skip to content

Commit

Permalink
can: j1939: transport: j1939_xtp_rx_dat_one(): compare own packets to…
Browse files Browse the repository at this point in the history
… 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]>
  • Loading branch information
olerem authored and marckleinebudde committed Aug 14, 2020
1 parent 840835c commit e052d05
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion net/can/j1939/transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -1792,7 +1792,20 @@ static void j1939_xtp_rx_dat_one(struct j1939_session *session,
}

tpdat = se_skb->data;
memcpy(&tpdat[offset], &dat[1], nbytes);
if (!session->transmission) {
memcpy(&tpdat[offset], &dat[1], nbytes);
} else {
int err;

err = memcmp(&tpdat[offset], &dat[1], nbytes);
if (err)
netdev_err_once(priv->ndev,
"%s: 0x%p: Data of RX-looped back packet (%*ph) doesn't match TX data (%*ph)!\n",
__func__, session,
nbytes, &dat[1],
nbytes, &tpdat[offset]);
}

if (packet == session->pkt.rx)
session->pkt.rx++;

Expand Down

0 comments on commit e052d05

Please sign in to comment.