From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7799621ABC1; Tue, 29 Apr 2025 17:43:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745948586; cv=none; b=PRwoJW1gsOC2eeoYbHBn6uzoq6vG7Rs2Oo836R9o2tHNUTo+GE2aYTyEEHmrYoKze5qLy5O21iL1eCu1hafhg5Fjd2p/I+B2eUpnag/Jjg2v8ONVnOOg/WVZ5GQVDoddlIuaj39AITcCX/PC6+OVxKI81S4GPixKqrbL4jY8Gps= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745948586; c=relaxed/simple; bh=OI9w6600pwjxT8eopC2aDdDRVxuIRE2BmIU/4uoiCcQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=teWT4ccZc2kjdy05j6kaVvN1owRz98HOTW0xjBen4PXMUywYCHMYQ0nCPVebCbVBhaOMaEQM8Fu4WdJCSj9nyDfOw5/DwHDzR/XKSEfN31DL0fFF2hJgkPOLs5wTsGb70obYIW+JLwbzkSyq4bcvxWcYzDifx5jC+DyOeZRcOs0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=MKnkXNgv; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="MKnkXNgv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EBC19C4CEE3; Tue, 29 Apr 2025 17:43:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1745948586; bh=OI9w6600pwjxT8eopC2aDdDRVxuIRE2BmIU/4uoiCcQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MKnkXNgvJ/IhfY6HIoIyYL9f/iAHO8fu2BQb/wVI60yXspjv1q9BbENBPthmomT8t DG/XmEETNMZY3PF0oSYArab1/sdYQd649lzjSFNOA9dZe+y+MjPQBYpsU3oQlHRBq1 /lMLhiFkSYasw9J5DH19cNrCTbEi29+itR1dYX2o= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Rand Deeb , Dave Kleikamp , Sasha Levin Subject: [PATCH 5.15 025/373] fs/jfs: cast inactags to s64 to prevent potential overflow Date: Tue, 29 Apr 2025 18:38:22 +0200 Message-ID: <20250429161124.166926490@linuxfoundation.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250429161123.119104857@linuxfoundation.org> References: <20250429161123.119104857@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Rand Deeb [ 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 Signed-off-by: Dave Kleikamp Signed-off-by: Sasha Levin --- fs/jfs/jfs_dmap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/jfs/jfs_dmap.c b/fs/jfs/jfs_dmap.c index e6cbe4c982c58..38319be806e10 100644 --- a/fs/jfs/jfs_dmap.c +++ b/fs/jfs/jfs_dmap.c @@ -3732,8 +3732,8 @@ void dbFinalizeBmap(struct inode *ipbmap) * system size is not a multiple of the group size). */ inactfree = (inactags && ag_rem) ? - ((inactags - 1) << bmp->db_agl2size) + ag_rem - : inactags << bmp->db_agl2size; + (((s64)inactags - 1) << bmp->db_agl2size) + ag_rem + : ((s64)inactags << bmp->db_agl2size); /* determine how many free blocks are in the active * allocation groups plus the average number of free blocks -- 2.39.5