]> git.baikalelectronics.ru Git - kernel.git/commit
can: bcm: check for null sk before deferencing it via the call to sock_net
authorColin Ian King <colin.king@canonical.com>
Fri, 8 Sep 2017 15:02:35 +0000 (16:02 +0100)
committerMarc Kleine-Budde <mkl@pengutronix.de>
Thu, 19 Oct 2017 11:05:53 +0000 (13:05 +0200)
commit65d6a16aee10d97fba9126b123c3f0a27d31e05d
treeca5e5a25d5f15253d5ab5bdf23cfef4a9411e01e
parentc5e99b6fadcad94e418c17833ed4ef7ce5cf0bf5
can: bcm: check for null sk before deferencing it via the call to sock_net

The assignment of net via call sock_net will dereference sk. This
is performed before a sanity null check on sk, so there could be
a potential null dereference on the sock_net call if sk is null.
Fix this by assigning net after the sk null check. Also replace
the sk == NULL with the more usual !sk idiom.

Detected by CoverityScan CID#1431862 ("Dereference before null check")

Fixes: 8d977f8bd8aa ("can: network namespace support for CAN_BCM protocol")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Acked-by: Oliver Hartkopp <socketcan@hartkopp.net>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
net/can/bcm.c