Skip to content

Commit

Permalink
nfs: fix undefined behavior in nfs_block_bits()
Browse files Browse the repository at this point in the history
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: [email protected]
Signed-off-by: Sergey Shtylyov <[email protected]>
Reviewed-by: Benjamin Coddington <[email protected]>
Signed-off-by: Trond Myklebust <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
Sergey Shtylyov authored and gregkh committed Jun 16, 2024
1 parent 2062e3f commit 74ea538
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions fs/nfs/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -615,9 +615,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;
}
Expand Down

0 comments on commit 74ea538

Please sign in to comment.