linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] SUNRPC: xprt: prevent shift-out-of-bounds
@ 2020-12-22  1:29 Randy Dunlap
  0 siblings, 0 replies; only message in thread
From: Randy Dunlap @ 2020-12-22  1:29 UTC (permalink / raw)
  To: linux-kernel
  Cc: Randy Dunlap, syzbot+ba2e91df8f74809417fa, J. Bruce Fields,
	Chuck Lever, linux-nfs, Trond Myklebust, Anna Schumaker

Prevent a UBSAN shift-out-of-bounds warning:

UBSAN: shift-out-of-bounds in net/sunrpc/xprt.c:658:14
shift exponent 536871232 is too large for 64-bit type 'long unsigned int'

If to_exponential is true and to_retries is >= BITS_PER_LONG,
this will cause an invalid shift value when calculating the
new majortimeo value.
In this case, when to_retries >= BITS_PER_LONG, cap (new local) retry
at BITS_PER_LONG - 1 and continue.

Fixes: da953063bdce ("SUNRPC: Start the first major timeout calculation at task creation")
Link: https://syzkaller.appspot.com/bug?extid=ba2e91df8f74809417fa
Signed-off-by: Randy Dunlap <rdunlap@infradead.org>
Reported-by: syzbot+ba2e91df8f74809417fa@syzkaller.appspotmail.com
Cc: "J. Bruce Fields" <bfields@fieldses.org>
Cc: Chuck Lever <chuck.lever@oracle.com>
Cc: linux-nfs@vger.kernel.org
Cc: Trond Myklebust <trond.myklebust@hammerspace.com>
Cc: Anna Schumaker <anna.schumaker@netapp.com>
---
a shortcut if desired: (also drop local 'retry' & change it back to
				'to->to_retries')
		if (to->to_retries >= BITS_PER_LONG)
			goto set_maxval;
...
set_maxval:
 		majortimeo = to->to_maxval;

 net/sunrpc/xprt.c |   12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

--- lnx-510.orig/net/sunrpc/xprt.c
+++ lnx-510/net/sunrpc/xprt.c
@@ -41,6 +41,7 @@
 #include <linux/module.h>
 
 #include <linux/types.h>
+#include <linux/bits.h>
 #include <linux/interrupt.h>
 #include <linux/workqueue.h>
 #include <linux/net.h>
@@ -593,10 +594,15 @@ static unsigned long xprt_calc_majortime
 	const struct rpc_timeout *to = req->rq_task->tk_client->cl_timeout;
 	unsigned long majortimeo = req->rq_timeout;
 
-	if (to->to_exponential)
-		majortimeo <<= to->to_retries;
-	else
+	if (to->to_exponential) {
+		unsigned int retry = to->to_retries;
+
+		if (retry >= BITS_PER_LONG)
+			retry = BITS_PER_LONG - 1;
+		majortimeo <<= retry;
+	} else {
 		majortimeo += to->to_increment * to->to_retries;
+	}
 	if (majortimeo > to->to_maxval || majortimeo == 0)
 		majortimeo = to->to_maxval;
 	return majortimeo;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-12-22  1:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-22  1:29 [PATCH] SUNRPC: xprt: prevent shift-out-of-bounds Randy Dunlap

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).