Commit 0f7f1fa5 authored by Oleksij Rempel's avatar Oleksij Rempel Committed by sanglipeng
Browse files

can: j1939: j1939_tp_tx_dat_new(): fix out-of-bounds memory access

stable inclusion
from stable-v5.10.178
commit 70caa596d158a5d84b117f722d58f3ea503a5ba9
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I8D927

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=70caa596d158a5d84b117f722d58f3ea503a5ba9



--------------------------------

commit b45193cb 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: 9d71dd0c ("can: add support of SAE J1939 protocol")
Reported-by: default avatarShuangpeng Bai <sjb7183@psu.edu>
Tested-by: default avatarShuangpeng Bai <sjb7183@psu.edu>
Signed-off-by: default avatarOleksij 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: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarsanglipeng <sanglipeng1@jd.com>
parent 4a804237
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment