Skip to content

Commit b64aae3

Browse files
committed
nfs: fix undefined behavior in nfs_block_bits()
JIRA: https://issues.redhat.com/browse/RHEL-53004 commit 3c0a2e0 Author: Sergey Shtylyov <s.shtylyov@omp.ru> Date: Fri May 10 23:24:04 2024 +0300 nfs: fix undefined behavior in nfs_block_bits() 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: Benjamin Coddington <bcodding@redhat.com>
1 parent 0dd741b commit b64aae3

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
@@ -710,9 +710,9 @@ unsigned long nfs_block_bits(unsigned long bsize, unsigned char *nrbitsp)
710710
if ((bsize & (bsize - 1)) || nrbitsp) {
711711
unsigned char nrbits;
712712

713-
for (nrbits = 31; nrbits && !(bsize & (1 << nrbits)); nrbits--)
713+
for (nrbits = 31; nrbits && !(bsize & (1UL << nrbits)); nrbits--)
714714
;
715-
bsize = 1 << nrbits;
715+
bsize = 1UL << nrbits;
716716
if (nrbitsp)
717717
*nrbitsp = nrbits;
718718
}

0 commit comments

Comments
 (0)