Skip to content

Commit 43bcedd

Browse files
J. Bruce Fieldsgregkh
authored andcommitted
svcrpc: fix UDP on servers with lots of threads
commit b7e5034 upstream. James Pearson found that an NFS server stopped responding to UDP requests if started with more than 1017 threads. sv_max_mesg is about 2^20, so that is probably where the calculation performed by svc_sock_setbufsize(svsk->sk_sock, (serv->sv_nrthreads+3) * serv->sv_max_mesg, (serv->sv_nrthreads+3) * serv->sv_max_mesg); starts to overflow an int. Reported-by: James Pearson <jcpearson@gmail.com> Tested-by: James Pearson <jcpearson@gmail.com> Cc: stable@vger.kernel.org Signed-off-by: J. Bruce Fields <bfields@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 4af185f commit 43bcedd

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

‎net/sunrpc/svcsock.c‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -381,12 +381,16 @@ static int svc_partial_recvfrom(struct svc_rqst *rqstp,
381381
/*
382382
* Set socket snd and rcv buffer lengths
383383
*/
384-
static void svc_sock_setbufsize(struct socket *sock, unsigned int snd,
385-
unsigned int rcv)
384+
static void svc_sock_setbufsize(struct svc_sock *svsk, unsigned int nreqs)
386385
{
386+
unsigned int max_mesg = svsk->sk_xprt.xpt_server->sv_max_mesg;
387+
struct socket *sock = svsk->sk_sock;
388+
389+
nreqs = min(nreqs, INT_MAX / 2 / max_mesg);
390+
387391
lock_sock(sock->sk);
388-
sock->sk->sk_sndbuf = snd * 2;
389-
sock->sk->sk_rcvbuf = rcv * 2;
392+
sock->sk->sk_sndbuf = nreqs * max_mesg * 2;
393+
sock->sk->sk_rcvbuf = nreqs * max_mesg * 2;
390394
sock->sk->sk_write_space(sock->sk);
391395
release_sock(sock->sk);
392396
}
@@ -548,9 +552,7 @@ static int svc_udp_recvfrom(struct svc_rqst *rqstp)
548552
* provides an upper bound on the number of threads
549553
* which will access the socket.
550554
*/
551-
svc_sock_setbufsize(svsk->sk_sock,
552-
(serv->sv_nrthreads+3) * serv->sv_max_mesg,
553-
(serv->sv_nrthreads+3) * serv->sv_max_mesg);
555+
svc_sock_setbufsize(svsk, serv->sv_nrthreads + 3);
554556

555557
clear_bit(XPT_DATA, &svsk->sk_xprt.xpt_flags);
556558
skb = NULL;
@@ -718,9 +720,7 @@ static void svc_udp_init(struct svc_sock *svsk, struct svc_serv *serv)
718720
* receive and respond to one request.
719721
* svc_udp_recvfrom will re-adjust if necessary
720722
*/
721-
svc_sock_setbufsize(svsk->sk_sock,
722-
3 * svsk->sk_xprt.xpt_server->sv_max_mesg,
723-
3 * svsk->sk_xprt.xpt_server->sv_max_mesg);
723+
svc_sock_setbufsize(svsk, 3);
724724

725725
/* data might have come in before data_ready set up */
726726
set_bit(XPT_DATA, &svsk->sk_xprt.xpt_flags);

0 commit comments

Comments
 (0)