Skip to content

Commit c5d29d5

Browse files
committed
Merge: CVE-2024-56601: net: inet: do not leave a dangling sk pointer in inet_create()
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/6102 JIRA: https://issues.redhat.com/browse/RHEL-72304 CVE: CVE-2024-56601 ``` net: inet: do not leave a dangling sk pointer in inet_create() 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: CKI Backport Bot <cki-ci-bot+cki-gitlab-backport-bot@redhat.com> --- <small>Created 2025-01-07 03:12 UTC by backporter - [KWF FAQ](https://red.ht/kernel_workflow_doc) - [Slack #team-kernel-workflow](https://redhat-internal.slack.com/archives/C04LRUPMJQ5) - [Source](https://gitlab.com/cki-project/kernel-workflow/-/blob/main/webhook/utils/backporter.py) - [Documentation](https://gitlab.com/cki-project/kernel-workflow/-/blob/main/docs/README.backporter.md) - [Report an issue](https://gitlab.com/cki-project/kernel-workflow/-/issues/new?issue%5Btitle%5D=backporter%20webhook%20issue)</small> Approved-by: Hangbin Liu <haliu@redhat.com> Approved-by: Sabrina Dubroca <sdubroca@redhat.com> Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com> Merged-by: Rado Vrbovsky <rvrbovsk@redhat.com>
2 parents 1daea69 + 45fb024 commit c5d29d5

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
@@ -379,32 +379,30 @@ static int inet_create(struct net *net, struct socket *sock, int protocol,
379379
inet->inet_sport = htons(inet->inet_num);
380380
/* Add to protocol hash chains. */
381381
err = sk->sk_prot->hash(sk);
382-
if (err) {
383-
sk_common_release(sk);
384-
goto out;
385-
}
382+
if (err)
383+
goto out_sk_release;
386384
}
387385

388386
if (sk->sk_prot->init) {
389387
err = sk->sk_prot->init(sk);
390-
if (err) {
391-
sk_common_release(sk);
392-
goto out;
393-
}
388+
if (err)
389+
goto out_sk_release;
394390
}
395391

396392
if (!kern) {
397393
err = BPF_CGROUP_RUN_PROG_INET_SOCK(sk);
398-
if (err) {
399-
sk_common_release(sk);
400-
goto out;
401-
}
394+
if (err)
395+
goto out_sk_release;
402396
}
403397
out:
404398
return err;
405399
out_rcu_unlock:
406400
rcu_read_unlock();
407401
goto out;
402+
out_sk_release:
403+
sk_common_release(sk);
404+
sock->sk = NULL;
405+
goto out;
408406
}
409407

410408

0 commit comments

Comments
 (0)