]> git.baikalelectronics.ru Git - kernel.git/commitdiff
fs/jfs: fix potential integer overflow on shift of a int
authorColin Ian King <colin.king@canonical.com>
Thu, 11 Feb 2021 13:01:08 +0000 (13:01 +0000)
committerDave Kleikamp <dave.kleikamp@oracle.com>
Thu, 11 Feb 2021 17:25:54 +0000 (11:25 -0600)
The left shift of int 32 bit integer constant 1 is evaluated using 32 bit
arithmetic and then assigned to a signed 64 bit integer. In the case where
l2nb is 32 or more this can lead to an overflow.  Avoid this by shifting
the value 1LL instead.

Addresses-Coverity: ("Uninitentional integer overflow")
Fixes: b40c2e665cd5 ("fs/jfs: TRIM support for JFS Filesystem")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Dave Kleikamp <dave.kleikamp@oracle.com>
fs/jfs/jfs_dmap.c

index 94b7c1cb5ceb33e5a9912e4e6cec812bea51f1d2..7aee156086198775e253440c85429af372389265 100644 (file)
@@ -1656,7 +1656,7 @@ s64 dbDiscardAG(struct inode *ip, int agno, s64 minlen)
                } else if (rc == -ENOSPC) {
                        /* search for next smaller log2 block */
                        l2nb = BLKSTOL2(nblocks) - 1;
-                       nblocks = 1 << l2nb;
+                       nblocks = 1LL << l2nb;
                } else {
                        /* Trim any already allocated blocks */
                        jfs_error(bmp->db_ipbmap->i_sb, "-EIO\n");