fs/jfs: fix potential integer overflow on shift of a int
Subsystems (2)
PATCH 1/1 fs/jfs: fix potential integer overflow on shift of a int
From: Colin Ian King <[email protected]>
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 using the BIT_ULL macro instead.
Addresses-Coverity: ("Uninitentional integer overflow")
--- fs/jfs/jfs_dmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/jfs/jfs_dmap.c +1 -1
@@ -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 =BIT_ULL (l2nb); }else {/* Trim any already allocated blocks */ jfs_error (bmp->db_ipbmap->i_sb,"-EIO\n" );
Signature · 1 line
2.29.2
Quoted 19 lines · Colin King
From: Colin Ian King <[email protected]>
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 using the
BIT_ULLmacro instead.Addresses-Coverity: ("Uninitentional integer overflow")
Fixes b40c2e665cd5 ("fs/jfs: TRIM support for JFS Filesystem")Signed-off-by Colin Ian King <[email protected]>--- fs/jfs/jfs_dmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/jfs/jfs_dmap.c +0
-0
fs/jfs/jfs_dmap.c s64 dbDiscardAG(struct inode *ip, int agno, s64 minlen) · line 1659
Quoted 5 lines
fs/jfs/jfs_dmap.c +1
-1@@ -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 =BIT_ULL (l2nb);
I'm not sure I like the use of this macro here. It seems to imply a bit flag of some sort. I think it would be clearer to use
nblocks = 1ULL << l2nb;
Maybe 1LL rather than 1ULL since nblocks is s64.
Quoted 4 lines
fs/jfs/jfs_dmap.c +0
-0}else {/* Trim any already allocated blocks */ jfs_error (bmp->db_ipbmap->i_sb,"-EIO\n" );