can: j1939: j1939_sk_setsockopt(): prevent allocation of j1939 filter for optlen...
authorNorbert Slusarek <nslusarek@gmx.net>
Sun, 20 Jun 2021 12:38:42 +0000 (14:38 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 14 Jul 2021 14:56:27 +0000 (16:56 +0200)
commit0dac8b0ad01676845078face9af8e62c724209ae
treedb1fb7345eb97b31612c016a12a3479bdea45927
parent2d58a38275d274b299714fb2ddef4b426e84aa49
can: j1939: j1939_sk_setsockopt(): prevent allocation of j1939 filter for optlen == 0

[ Upstream commit aaf473d0100f64abc88560e2bea905805bcf2a8e ]

If optval != NULL and optlen == 0 are specified for SO_J1939_FILTER in
j1939_sk_setsockopt(), memdup_sockptr() will return ZERO_PTR for 0
size allocation. The new filter will be mistakenly assigned ZERO_PTR.
This patch checks for optlen != 0 and filter will be assigned NULL in
case of optlen == 0.

Fixes: 9d71dd0c7009 ("can: add support of SAE J1939 protocol")
Link: https://lore.kernel.org/r/20210620123842.117975-1-nslusarek@gmx.net
Signed-off-by: Norbert Slusarek <nslusarek@gmx.net>
Acked-by: Oleksij Rempel <o.rempel@pengutronix.de>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
net/can/j1939/socket.c