linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: sunrpc: xprt.c: fix shift-out-of-bounds in xprt_calc_majortimeo
@ 2021-04-19 16:36 Kurt Manucredo
  2021-04-19 16:58 ` Trond Myklebust
  0 siblings, 1 reply; 2+ messages in thread
From: Kurt Manucredo @ 2021-04-19 16:36 UTC (permalink / raw)
  To: trond.myklebust, anna.schumaker, bfields, chuck.lever, davem,
	kuba, skhan
  Cc: Kurt Manucredo, linux-nfs, netdev, linux-kernel,
	linux-kernel-mentees, syzbot+ba2e91df8f74809417fa, gregkh

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

Reported-by: syzbot+ba2e91df8f74809417fa@syzkaller.appspotmail.com
Signed-off-by: Kurt Manucredo <fuzzybritches0@gmail.com>
---
 net/sunrpc/xprt.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/net/sunrpc/xprt.c b/net/sunrpc/xprt.c
index 691ccf8049a4..07128ac3d51d 100644
--- a/net/sunrpc/xprt.c
+++ b/net/sunrpc/xprt.c
@@ -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)
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] net: sunrpc: xprt.c: fix shift-out-of-bounds in xprt_calc_majortimeo
  2021-04-19 16:36 [PATCH] net: sunrpc: xprt.c: fix shift-out-of-bounds in xprt_calc_majortimeo Kurt Manucredo
@ 2021-04-19 16:58 ` Trond Myklebust
  0 siblings, 0 replies; 2+ messages in thread
From: Trond Myklebust @ 2021-04-19 16:58 UTC (permalink / raw)
  To: bfields, fuzzybritches0, skhan, anna.schumaker, davem, chuck.lever, kuba
  Cc: linux-kernel-mentees, linux-nfs, gregkh, netdev, linux-kernel,
	syzbot+ba2e91df8f74809417fa

On Mon, 2021-04-19 at 16:36 +0000, Kurt Manucredo wrote:
> 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
> 
> Reported-by: syzbot+ba2e91df8f74809417fa@syzkaller.appspotmail.com
> Signed-off-by: Kurt Manucredo <fuzzybritches0@gmail.com>
> ---
>  net/sunrpc/xprt.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/net/sunrpc/xprt.c b/net/sunrpc/xprt.c
> index 691ccf8049a4..07128ac3d51d 100644
> --- a/net/sunrpc/xprt.c
> +++ b/net/sunrpc/xprt.c
> @@ -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)

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.

-- 
Trond Myklebust
Linux NFS client maintainer, Hammerspace
trond.myklebust@hammerspace.com



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-04-19 16:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-19 16:36 [PATCH] net: sunrpc: xprt.c: fix shift-out-of-bounds in xprt_calc_majortimeo Kurt Manucredo
2021-04-19 16:58 ` Trond Myklebust

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).