diff mbox series

[v2,5/8] net: af_can: do not leave a dangling sk pointer in can_create()

Message ID 20241007213502.28183-6-ignat@cloudflare.com
State Superseded
Headers show
Series do not leave dangling sk pointers in pf->create functions | expand

Commit Message

Ignat Korchagin Oct. 7, 2024, 9:34 p.m. UTC
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>
---
 net/can/af_can.c | 1 +
 1 file changed, 1 insertion(+)
diff mbox series

Patch

diff --git a/net/can/af_can.c b/net/can/af_can.c
index 707576eeeb58..01f3fbb3b67d 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: