Skip to content

Commit

Permalink
can: bcm: check for null sk before deferencing it via the call to soc…
Browse files Browse the repository at this point in the history
…k_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: 384317e ("can: network namespace support for CAN_BCM protocol")
Signed-off-by: Colin Ian King <[email protected]>
Acked-by: Oliver Hartkopp <[email protected]>
Signed-off-by: Marc Kleine-Budde <[email protected]>
  • Loading branch information
Colin Ian King authored and marckleinebudde committed Oct 19, 2017
1 parent fb5b91d commit 62c0464
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions net/can/bcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1493,13 +1493,14 @@ static int bcm_init(struct sock *sk)
static int bcm_release(struct socket *sock)
{
struct sock *sk = sock->sk;
struct net *net = sock_net(sk);
struct net *net;
struct bcm_sock *bo;
struct bcm_op *op, *next;

if (sk == NULL)
if (!sk)
return 0;

net = sock_net(sk);
bo = bcm_sk(sk);

/* remove bcm_ops, timer, rx_unregister(), etc. */
Expand Down

0 comments on commit 62c0464

Please sign in to comment.