Skip to content

Commit 319050d

Browse files
committed
SUNRPC: Fix error handling in svc_setup_socket()
Dan points out that sock_alloc_file() releases @sock on error, but so do all of svc_setup_socket's callers, resulting in a double- release if sock_alloc_file() returns an error. Rather than allocating a struct file for all new sockets, allocate one only for sockets created during a TCP accept. For the moment, those are the only ones that will ever be used with RPC-with-TLS. Reported-by: Dan Carpenter <[email protected]> Fixes: ae0d777 ("SUNRPC: Ensure server-side sockets have a sock->file") Signed-off-by: Chuck Lever <[email protected]>
1 parent 29cd292 commit 319050d

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

net/sunrpc/svcsock.c

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,9 @@ static struct svc_xprt *svc_tcp_accept(struct svc_xprt *xprt)
895895
trace_svcsock_accept_err(xprt, serv->sv_name, err);
896896
return NULL;
897897
}
898+
if (IS_ERR(sock_alloc_file(newsock, O_NONBLOCK, NULL)))
899+
return NULL;
900+
898901
set_bit(XPT_CONN, &svsk->sk_xprt.xpt_flags);
899902

900903
err = kernel_getpeername(newsock, sin);
@@ -935,7 +938,7 @@ static struct svc_xprt *svc_tcp_accept(struct svc_xprt *xprt)
935938
return &newsvsk->sk_xprt;
936939

937940
failed:
938-
sock_release(newsock);
941+
sockfd_put(newsock);
939942
return NULL;
940943
}
941944

@@ -1430,7 +1433,6 @@ static struct svc_sock *svc_setup_socket(struct svc_serv *serv,
14301433
struct socket *sock,
14311434
int flags)
14321435
{
1433-
struct file *filp = NULL;
14341436
struct svc_sock *svsk;
14351437
struct sock *inet;
14361438
int pmap_register = !(flags & SVC_SOCK_ANONYMOUS);
@@ -1439,14 +1441,6 @@ static struct svc_sock *svc_setup_socket(struct svc_serv *serv,
14391441
if (!svsk)
14401442
return ERR_PTR(-ENOMEM);
14411443

1442-
if (!sock->file) {
1443-
filp = sock_alloc_file(sock, O_NONBLOCK, NULL);
1444-
if (IS_ERR(filp)) {
1445-
kfree(svsk);
1446-
return ERR_CAST(filp);
1447-
}
1448-
}
1449-
14501444
inet = sock->sk;
14511445

14521446
if (pmap_register) {
@@ -1456,8 +1450,6 @@ static struct svc_sock *svc_setup_socket(struct svc_serv *serv,
14561450
inet->sk_protocol,
14571451
ntohs(inet_sk(inet)->inet_sport));
14581452
if (err < 0) {
1459-
if (filp)
1460-
fput(filp);
14611453
kfree(svsk);
14621454
return ERR_PTR(err);
14631455
}

0 commit comments

Comments
 (0)