Skip to contentSkip to conversation

net: sunrpc: xprt.c: fix shift-out-of-bounds in xprt_calc_majortimeo

PATCH In review Kurt Manucredo 2 participants 2 messages Apr 19, 2021

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: sunrpc: xprt.c: fix shift-out-of-bounds in xprt_calc_majortimeo

Fix shift-out-of-bounds in xprt_calc_majortimeo().

UBSAN: shift-out-of-bounds in net/sunrpc/xprt.c:658:14

shift exponent 536871232 is too large for 64-bit type 'long u

---
 net/sunrpc/xprt.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
net/sunrpc/xprt.c +4 -1
index 691ccf8049a4..07128ac3d51d 100644
@@ -655,7 +655,10 @@ static unsigned long xprt_calc_majortimeo(struct rpc_rqst *req)
 	unsigned long majortimeo = req->rq_timeout;
 
 	if (to->to_exponential)
-		majortimeo <<= to->to_retries;
+		if (to->to_retries >= sizeof(majortimeo) * 8)
+			majortimeo = to->to_maxval;
+		else
+			majortimeo <<= to->to_retries;
 	else
 		majortimeo += to->to_increment * to->to_retries;
 	if (majortimeo > to->to_maxval || majortimeo == 0)
Signature · 1 line
2.30.2
#1 lore raw
Quoted 20 lines · Kurt Manucredo

Fix shift-out-of-bounds in xprt_calc_majortimeo().

UBSAN: shift-out-of-bounds in net/sunrpc/xprt.c:658:14

shift exponent 536871232 is too large for 64-bit type 'long u

---
 net/sunrpc/xprt.c | 5 ++++-

 1 file changed, 4 insertions(+), 1 deletion(-)
net/sunrpc/xprt.c +0 -0
index 691ccf8049a4..07128ac3d51d 100644
@@ -655,7 +655,10 @@ static unsigned long xprt_calc_majortimeo(struct
 rpc_rqst *req)
         unsigned long majortimeo = req->rq_timeout;


        if (to->to_exponential)

Quoted 8 lines

-               majortimeo <<= to->to_retries;
+               if (to->to_retries >= sizeof(majortimeo) * 8) +                       majortimeo = to->to_maxval;
+               else
+                       majortimeo <<= to->to_retries; else
                majortimeo += to->to_increment * to->to_retries; if (majortimeo > to->to_maxval || majortimeo == 0)

I've already stated on the mailing list that I'm not accepting any changes to xprt_calc_majortimeo() for this problem. There is a fix to the NFS mount code that addresses this bounds issue, and that commit is already being tested in linux-next.

Signature · 3 lines
Trond Myklebust
Linux NFS client maintainer, Hammerspace
[email protected]