From: Ignat Korchagin Date: Mon, 14 Oct 2024 15:38:03 +0000 (+0100) Subject: net: af_can: do not leave a dangling sk pointer in can_create() X-Git-Tag: v6.13-rc1~135^2~306^2~5 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=811a7ca7320c062e15d0f5b171fe6ad8592d1434;p=thirdparty%2Fkernel%2Flinux.git net: af_can: do not leave a dangling sk pointer in can_create() 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 Reviewed-by: Vincent Mailhol Reviewed-by: Kuniyuki Iwashima Reviewed-by: Marc Kleine-Budde Link: https://patch.msgid.link/20241014153808.51894-5-ignat@cloudflare.com Signed-off-by: Jakub Kicinski --- diff --git a/net/can/af_can.c b/net/can/af_can.c index 707576eeeb582..01f3fbb3b67dc 100644 --- a/net/can/af_can.c +++ b/net/can/af_can.c @@ -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: