Skip to content

Commit 2ffb830

Browse files
committed
net: inet: do not leave a dangling sk pointer in inet_create()
jira VULN-41186 cve CVE-2024-56601 commit-author Ignat Korchagin <[email protected]> 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 <[email protected]> Reviewed-by: Kuniyuki Iwashima <[email protected]> Reviewed-by: Eric Dumazet <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]> (cherry picked from commit 9365fa5) Signed-off-by: Anmol Jain <[email protected]>
1 parent 468fcf3 commit 2ffb830

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
@@ -375,32 +375,30 @@ static int inet_create(struct net *net, struct socket *sock, int protocol,
375375
inet->inet_sport = htons(inet->inet_num);
376376
/* Add to protocol hash chains. */
377377
err = sk->sk_prot->hash(sk);
378-
if (err) {
379-
sk_common_release(sk);
380-
goto out;
381-
}
378+
if (err)
379+
goto out_sk_release;
382380
}
383381

384382
if (sk->sk_prot->init) {
385383
err = sk->sk_prot->init(sk);
386-
if (err) {
387-
sk_common_release(sk);
388-
goto out;
389-
}
384+
if (err)
385+
goto out_sk_release;
390386
}
391387

392388
if (!kern) {
393389
err = BPF_CGROUP_RUN_PROG_INET_SOCK(sk);
394-
if (err) {
395-
sk_common_release(sk);
396-
goto out;
397-
}
390+
if (err)
391+
goto out_sk_release;
398392
}
399393
out:
400394
return err;
401395
out_rcu_unlock:
402396
rcu_read_unlock();
403397
goto out;
398+
out_sk_release:
399+
sk_common_release(sk);
400+
sock->sk = NULL;
401+
goto out;
404402
}
405403

406404

0 commit comments

Comments
 (0)