Skip to content

Commit cf81307

Browse files
committed
net: inet: do not leave a dangling sk pointer in inet_create()
jira VULN-41185 cve CVE-2024-56601 commit-author Ignat Korchagin <ignat@cloudflare.com> commit 9365fa5 sock_init_data() attaches the allocated sk object to the provided sock object. If inet_create() fails later, the sk object is freed, but the sock object retains the dangling pointer, which may create use-after-free later. Clear the sk pointer in the sock object on error. Signed-off-by: Ignat Korchagin <ignat@cloudflare.com> Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com> Reviewed-by: Eric Dumazet <edumazet@google.com> Link: https://patch.msgid.link/20241014153808.51894-7-ignat@cloudflare.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> (cherry picked from commit 9365fa5) Signed-off-by: Anmol Jain <ajain@ciq.com>
1 parent bd7c69d commit cf81307

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

net/ipv4/af_inet.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -367,32 +367,30 @@ static int inet_create(struct net *net, struct socket *sock, int protocol,
367367
inet->inet_sport = htons(inet->inet_num);
368368
/* Add to protocol hash chains. */
369369
err = sk->sk_prot->hash(sk);
370-
if (err) {
371-
sk_common_release(sk);
372-
goto out;
373-
}
370+
if (err)
371+
goto out_sk_release;
374372
}
375373

376374
if (sk->sk_prot->init) {
377375
err = sk->sk_prot->init(sk);
378-
if (err) {
379-
sk_common_release(sk);
380-
goto out;
381-
}
376+
if (err)
377+
goto out_sk_release;
382378
}
383379

384380
if (!kern) {
385381
err = BPF_CGROUP_RUN_PROG_INET_SOCK(sk);
386-
if (err) {
387-
sk_common_release(sk);
388-
goto out;
389-
}
382+
if (err)
383+
goto out_sk_release;
390384
}
391385
out:
392386
return err;
393387
out_rcu_unlock:
394388
rcu_read_unlock();
395389
goto out;
390+
out_sk_release:
391+
sk_common_release(sk);
392+
sock->sk = NULL;
393+
goto out;
396394
}
397395

398396

0 commit comments

Comments
 (0)