linux-stable/net/can/j1939
Oleksij Rempel 4c3fb22a6e can: j1939: j1939_tp_tx_dat_new(): fix out-of-bounds memory access
commit b45193cb4d upstream.

In the j1939_tp_tx_dat_new() function, an out-of-bounds memory access
could occur during the memcpy() operation if the size of skb->cb is
larger than the size of struct j1939_sk_buff_cb. This is because the
memcpy() operation uses the size of skb->cb, leading to a read beyond
the struct j1939_sk_buff_cb.

Updated the memcpy() operation to use the size of struct
j1939_sk_buff_cb instead of the size of skb->cb. This ensures that the
memcpy() operation only reads the memory within the bounds of struct
j1939_sk_buff_cb, preventing out-of-bounds memory access.

Additionally, add a BUILD_BUG_ON() to check that the size of skb->cb
is greater than or equal to the size of struct j1939_sk_buff_cb. This
ensures that the skb->cb buffer is large enough to hold the
j1939_sk_buff_cb structure.

Fixes: 9d71dd0c70 ("can: add support of SAE J1939 protocol")
Reported-by: Shuangpeng Bai <sjb7183@psu.edu>
Tested-by: Shuangpeng Bai <sjb7183@psu.edu>
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
Link: https://groups.google.com/g/syzkaller/c/G_LL-C3plRs/m/-8xCi6dCAgAJ
Link: https://lore.kernel.org/all/20230404073128.3173900-1-o.rempel@pengutronix.de
Cc: stable@vger.kernel.org
[mkl: rephrase commit message]
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-04-13 16:55:33 +02:00
..
address-claim.c can: j1939: do not wait 250 ms if the same addr was already claimed 2023-02-14 19:11:42 +01:00
bus.c
j1939-priv.h can: j1939: j1939_xtp_rx_rts_session_new(): abort TP less than 9 bytes 2021-10-17 14:12:57 +02:00
Kconfig
main.c can: j1939: j1939_send_one(): fix missing CAN header initialization 2022-11-07 14:00:27 +01:00
Makefile
socket.c can: j1939: j1939_sk_queue_activate_next_locked(): replace WARN_ON_ONCE with netdev_warn_once() 2022-08-09 09:05:06 +02:00
transport.c can: j1939: j1939_tp_tx_dat_new(): fix out-of-bounds memory access 2023-04-13 16:55:33 +02:00