]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
sunrpc: Fix reserved port range calculation
authorFrank Sorenson <sorenson@redhat.com>
Fri, 8 Jul 2016 21:35:23 +0000 (16:35 -0500)
committerTrond Myklebust <trond.myklebust@primarydata.com>
Tue, 19 Jul 2016 20:23:26 +0000 (16:23 -0400)
The range calculation for choosing the random reserved port will panic
with divide-by-zero when min_resvport == max_resvport, a range of one
port, not zero.

Fix the reserved port range calculation by adding one to the difference.

Signed-off-by: Frank Sorenson <sorenson@redhat.com>
Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
net/sunrpc/xprtsock.c

index 7e2b2fa189c340e7f0968aead6f878879e8a9a72..1adda71f4e3a24172954b650fa4c7a6d697f8609 100644 (file)
@@ -1714,7 +1714,7 @@ static void xs_udp_timer(struct rpc_xprt *xprt, struct rpc_task *task)
 
 static unsigned short xs_get_random_port(void)
 {
-       unsigned short range = xprt_max_resvport - xprt_min_resvport;
+       unsigned short range = xprt_max_resvport - xprt_min_resvport + 1;
        unsigned short rand = (unsigned short) prandom_u32() % range;
        return rand + xprt_min_resvport;
 }