Skip to content

Commit a54419e

Browse files
Sergey Shtylyovgregkh
authored andcommitted
nfs: fix undefined behavior in nfs_block_bits()
commit 3c0a2e0 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>
1 parent 728b663 commit a54419e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

fs/nfs/internal.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -695,9 +695,9 @@ unsigned long nfs_block_bits(unsigned long bsize, unsigned char *nrbitsp)
695695
if ((bsize & (bsize - 1)) || nrbitsp) {
696696
unsigned char nrbits;
697697

698-
for (nrbits = 31; nrbits && !(bsize & (1 << nrbits)); nrbits--)
698+
for (nrbits = 31; nrbits && !(bsize & (1UL << nrbits)); nrbits--)
699699
;
700-
bsize = 1 << nrbits;
700+
bsize = 1UL << nrbits;
701701
if (nrbitsp)
702702
*nrbitsp = nrbits;
703703
}

0 commit comments

Comments
 (0)