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

net/9p: Fix a potential socket leak in p9_socket_open

Both p9_fd_create_tcp() and p9_fd_create_unix() will call
p9_socket_open(). If the creation of p9_trans_fd fails,
p9_fd_create_tcp() and p9_fd_create_unix() will return an
error directly instead of releasing the cscoket, which will
result in a socket leak.

This patch adds sock_release() to fix the leak issue.

Fixes: 6b18662e239a ("9p connect fixes")
Signed-off-by: Wang Hai <wanghai38@huawei.com>
ACKed-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Wang Hai and committed by
David S. Miller
dcc14cfd b8f79dcc

+3 -1
+3 -1
net/9p/trans_fd.c
··· 860 860 struct file *file; 861 861 862 862 p = kzalloc(sizeof(struct p9_trans_fd), GFP_KERNEL); 863 - if (!p) 863 + if (!p) { 864 + sock_release(csocket); 864 865 return -ENOMEM; 866 + } 865 867 866 868 csocket->sk->sk_allocation = GFP_NOIO; 867 869 file = sock_alloc_file(csocket, 0, NULL);