]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
net: af_can: do not leave a dangling sk pointer in can_create()
authorIgnat Korchagin <ignat@cloudflare.com>
Mon, 14 Oct 2024 15:38:03 +0000 (16:38 +0100)
committerJakub Kicinski <kuba@kernel.org>
Wed, 16 Oct 2024 01:43:08 +0000 (18:43 -0700)
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>
net/can/af_can.c

index 707576eeeb5823adc646025d2751f13a2ef40e80..01f3fbb3b67dc687a82661395c5f99e325c54120 100644 (file)
@@ -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: