Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

af_unix: Fix memleak of newsk in unix_stream_connect().

When prepare_peercred() fails in unix_stream_connect(),
unix_release_sock() is not called for newsk, and the memory
is leaked.

Let's move prepare_peercred() before unix_create1().

Fixes: fd0a109a0f6b ("net, pidfs: prepare for handing out pidfds for reaped sk->sk_peer_pid")
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
Link: https://patch.msgid.link/20260207232236.2557549-1-kuniyu@google.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>

authored by

Kuniyuki Iwashima and committed by
Paolo Abeni
6884028c e3998b6e

+3 -8
+3 -8
net/unix/af_unix.c
··· 1650 1650 1651 1651 timeo = sock_sndtimeo(sk, flags & O_NONBLOCK); 1652 1652 1653 - /* First of all allocate resources. 1654 - * If we will make it after state is locked, 1655 - * we will have to recheck all again in any case. 1656 - */ 1653 + err = prepare_peercred(&peercred); 1654 + if (err) 1655 + goto out; 1657 1656 1658 1657 /* create new sock for complete connection */ 1659 1658 newsk = unix_create1(net, NULL, 0, sock->type); ··· 1660 1661 err = PTR_ERR(newsk); 1661 1662 goto out; 1662 1663 } 1663 - 1664 - err = prepare_peercred(&peercred); 1665 - if (err) 1666 - goto out; 1667 1664 1668 1665 /* Allocate skb for sending to listening sock */ 1669 1666 skb = sock_wmalloc(newsk, 1, 0, GFP_KERNEL);