Skip to content

Commit e7a1849

Browse files
RandDeebvijay-suman
authored andcommitted
fs/jfs: cast inactags to s64 to prevent potential overflow
[ Upstream commit 70ca3246ad201b53a9f09380b3f29d8bac320383 ] The expression "inactags << bmp->db_agl2size" in the function dbFinalizeBmap() is computed using int operands. Although the values (inactags and db_agl2size) are derived from filesystem parameters and are usually small, there is a theoretical risk that the shift could overflow a 32-bit int if extreme values occur. According to the C standard, shifting a signed 32-bit int can lead to undefined behavior if the result exceeds its range. In our case, an overflow could miscalculate free blocks, potentially leading to erroneous filesystem accounting. To ensure the arithmetic is performed in 64-bit space, we cast "inactags" to s64 before shifting. This defensive fix prevents any risk of overflow and complies with kernel coding best practices. Found by Linux Verification Center (linuxtesting.org) with SVACE. Signed-off-by: Rand Deeb <[email protected]> Signed-off-by: Dave Kleikamp <[email protected]> Signed-off-by: Sasha Levin <[email protected]> (cherry picked from commit 761e36cf8c86c4f28a739e9364dc354bbec41511) Signed-off-by: Vijayendra Suman <[email protected]>
1 parent a1fb6d7 commit e7a1849

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

fs/jfs/jfs_dmap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3732,8 +3732,8 @@ void dbFinalizeBmap(struct inode *ipbmap)
37323732
* system size is not a multiple of the group size).
37333733
*/
37343734
inactfree = (inactags && ag_rem) ?
3735-
((inactags - 1) << bmp->db_agl2size) + ag_rem
3736-
: inactags << bmp->db_agl2size;
3735+
(((s64)inactags - 1) << bmp->db_agl2size) + ag_rem
3736+
: ((s64)inactags << bmp->db_agl2size);
37373737

37383738
/* determine how many free blocks are in the active
37393739
* allocation groups plus the average number of free blocks

0 commit comments

Comments
 (0)