Skip to content

Commit

Permalink
can: j1939: j1939_sk_setsockopt(): prevent allocation of j1939 filter…
Browse files Browse the repository at this point in the history
… for optlen == 0

[ Upstream commit aaf473d ]

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: 9d71dd0 ("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>
  • Loading branch information
Norbert Slusarek authored and gregkh committed Jul 14, 2021
1 parent 2d58a38 commit 0dac8b0
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion net/can/j1939/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ static int j1939_sk_setsockopt(struct socket *sock, int level, int optname,

switch (optname) {
case SO_J1939_FILTER:
if (!sockptr_is_null(optval)) {
if (!sockptr_is_null(optval) && optlen != 0) {
struct j1939_filter *f;
int c;

Expand Down

0 comments on commit 0dac8b0

Please sign in to comment.