summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergey Shtylyov <s.shtylyov@omp.ru>2024-05-10 23:24:04 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2024-06-16 13:28:52 +0200
commit2997e2fb1cbd1446dbfd39de9be70b3e58815fdf (patch)
tree89bac69226b5e9175ef6642624a024db7bc49e9f
parent7c72af16abf2ec7520407098360bbba312289e05 (diff)
downloadlinux-stable-2997e2fb1cbd1446dbfd39de9be70b3e58815fdf.tar.gz
linux-stable-2997e2fb1cbd1446dbfd39de9be70b3e58815fdf.tar.bz2
linux-stable-2997e2fb1cbd1446dbfd39de9be70b3e58815fdf.zip
nfs: fix undefined behavior in nfs_block_bits()
commit 3c0a2e0b0ae661457c8505fecc7be5501aa7a715 upstream. Shifting *signed int* typed constant 1 left by 31 bits causes undefined behavior. Specify the correct *unsigned long* type by using 1UL instead. Found by Linux Verification Center (linuxtesting.org) with the Svace static analysis tool. Cc: stable@vger.kernel.org Signed-off-by: Sergey Shtylyov <s.shtylyov@omp.ru> Reviewed-by: Benjamin Coddington <bcodding@redhat.com> Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--fs/nfs/internal.h4
1 files changed, 2 insertions, 2 deletions
diff --git a/fs/nfs/internal.h b/fs/nfs/internal.h
index fb28750da761..e8b692d41b26 100644
--- a/fs/nfs/internal.h
+++ b/fs/nfs/internal.h
@@ -609,9 +609,9 @@ unsigned long nfs_block_bits(unsigned long bsize, unsigned char *nrbitsp)
if ((bsize & (bsize - 1)) || nrbitsp) {
unsigned char nrbits;
- for (nrbits = 31; nrbits && !(bsize & (1 << nrbits)); nrbits--)
+ for (nrbits = 31; nrbits && !(bsize & (1UL << nrbits)); nrbits--)
;
- bsize = 1 << nrbits;
+ bsize = 1UL << nrbits;
if (nrbitsp)
*nrbitsp = nrbits;
}