Skip to content

Commit 5d71899

Browse files
fsorensontrondmypd
authored andcommitted
sunrpc: Fix reserved port range calculation
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>
1 parent 34ae685 commit 5d71899

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

net/sunrpc/xprtsock.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1714,7 +1714,7 @@ static void xs_udp_timer(struct rpc_xprt *xprt, struct rpc_task *task)
17141714

17151715
static unsigned short xs_get_random_port(void)
17161716
{
1717-
unsigned short range = xprt_max_resvport - xprt_min_resvport;
1717+
unsigned short range = xprt_max_resvport - xprt_min_resvport + 1;
17181718
unsigned short rand = (unsigned short) prandom_u32() % range;
17191719
return rand + xprt_min_resvport;
17201720
}

0 commit comments

Comments
 (0)