Skip to content

Commit

Permalink
net: af_can: do not leave a dangling sk pointer in can_create()
Browse files Browse the repository at this point in the history
On error can_create() frees the allocated sk object, but sock_init_data()
has already attached it to the provided sock object. This will leave a
dangling sk pointer in the sock object and may cause use-after-free later.

Signed-off-by: Ignat Korchagin <ignat@cloudflare.com>
Reviewed-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Reviewed-by: Marc Kleine-Budde <mkl@pengutronix.de>
Link: https://patch.msgid.link/20241014153808.51894-5-ignat@cloudflare.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Ignat Korchagin authored and Jakub Kicinski committed Oct 16, 2024
1 parent 3945c79 commit 811a7ca
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions net/can/af_can.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ static int can_create(struct net *net, struct socket *sock, int protocol,
/* release sk on errors */
sock_orphan(sk);
sock_put(sk);
sock->sk = NULL;
}

errout:
Expand Down

0 comments on commit 811a7ca

Please sign in to comment.