]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
nfs: fix undefined behavior in nfs_block_bits()
authorSergey Shtylyov <s.shtylyov@omp.ru>
Fri, 10 May 2024 20:24:04 +0000 (23:24 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 16 Jun 2024 11:32:36 +0000 (13:32 +0200)
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>
fs/nfs/internal.h

index 9a72abfb46abc0e5584cdebaba19fadcbe3624e7..566f1b11f62f706c9190d281289bef1bf7ff29a6 100644 (file)
@@ -660,9 +660,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;
        }