1 From b7e5034cbecf5a65b7bfdc2b20a8378039577706 Mon Sep 17 00:00:00 2001
2 From: "J. Bruce Fields" <bfields@redhat.com>
3 Date: Wed, 20 Feb 2019 12:54:50 -0500
4 Subject: svcrpc: fix UDP on servers with lots of threads
6 From: J. Bruce Fields <bfields@redhat.com>
8 commit b7e5034cbecf5a65b7bfdc2b20a8378039577706 upstream.
10 James Pearson found that an NFS server stopped responding to UDP
11 requests if started with more than 1017 threads.
13 sv_max_mesg is about 2^20, so that is probably where the calculation
16 svc_sock_setbufsize(svsk->sk_sock,
17 (serv->sv_nrthreads+3) * serv->sv_max_mesg,
18 (serv->sv_nrthreads+3) * serv->sv_max_mesg);
20 starts to overflow an int.
22 Reported-by: James Pearson <jcpearson@gmail.com>
23 Tested-by: James Pearson <jcpearson@gmail.com>
24 Cc: stable@vger.kernel.org
25 Signed-off-by: J. Bruce Fields <bfields@redhat.com>
26 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
29 net/sunrpc/svcsock.c | 20 ++++++++++----------
30 1 file changed, 10 insertions(+), 10 deletions(-)
32 --- a/net/sunrpc/svcsock.c
33 +++ b/net/sunrpc/svcsock.c
34 @@ -349,12 +349,16 @@ static ssize_t svc_recvfrom(struct svc_r
36 * Set socket snd and rcv buffer lengths
38 -static void svc_sock_setbufsize(struct socket *sock, unsigned int snd,
40 +static void svc_sock_setbufsize(struct svc_sock *svsk, unsigned int nreqs)
42 + unsigned int max_mesg = svsk->sk_xprt.xpt_server->sv_max_mesg;
43 + struct socket *sock = svsk->sk_sock;
45 + nreqs = min(nreqs, INT_MAX / 2 / max_mesg);
48 - sock->sk->sk_sndbuf = snd * 2;
49 - sock->sk->sk_rcvbuf = rcv * 2;
50 + sock->sk->sk_sndbuf = nreqs * max_mesg * 2;
51 + sock->sk->sk_rcvbuf = nreqs * max_mesg * 2;
52 sock->sk->sk_write_space(sock->sk);
53 release_sock(sock->sk);
55 @@ -516,9 +520,7 @@ static int svc_udp_recvfrom(struct svc_r
56 * provides an upper bound on the number of threads
57 * which will access the socket.
59 - svc_sock_setbufsize(svsk->sk_sock,
60 - (serv->sv_nrthreads+3) * serv->sv_max_mesg,
61 - (serv->sv_nrthreads+3) * serv->sv_max_mesg);
62 + svc_sock_setbufsize(svsk, serv->sv_nrthreads + 3);
64 clear_bit(XPT_DATA, &svsk->sk_xprt.xpt_flags);
66 @@ -681,9 +683,7 @@ static void svc_udp_init(struct svc_sock
67 * receive and respond to one request.
68 * svc_udp_recvfrom will re-adjust if necessary
70 - svc_sock_setbufsize(svsk->sk_sock,
71 - 3 * svsk->sk_xprt.xpt_server->sv_max_mesg,
72 - 3 * svsk->sk_xprt.xpt_server->sv_max_mesg);
73 + svc_sock_setbufsize(svsk, 3);
75 /* data might have come in before data_ready set up */
76 set_bit(XPT_DATA, &svsk->sk_xprt.xpt_flags);