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 043AF27F4F3; Thu, 3 Apr 2025 19:08: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=1743707287; cv=none; b=RN5+tbvZp66KxJNAHjfUmyDDHLdlIXC4+ho8f/dFlZonaCNR5z7xkYgha9bSxMEEruRO+r6mFpH5vIb0zisUkaW8Q50bG9nBqLqmTkz6vt3cTmthaeRkmLtABU0rRGX5GhFP8PB4ktaEaNAn6QE25LBs5CU+0sKzHDY0ZTenIJY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743707287; c=relaxed/simple; bh=Yi6NBWvt1kWSbty3oBCwzar1OFqmjwSEF8xkY7+ToHw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=CDz34npWeIFWCN1dhAL1kUVYUmtlCA6RD2D8K0GWCH2ZqZJ559fOiJn10z62X/EXtFP6a9gtjSlUuHurAc4dd3/Zs+2zC1jZCc2NBnNtQPY5z0UlWNs3W+YzYPqy+4n0QSQRjEqqud+BTFgXjP2TdzgWou2zMYg77nZ+/PvjgJA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rPkpJ8l7; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="rPkpJ8l7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2C5CEC4CEE3; Thu, 3 Apr 2025 19:08:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743707286; bh=Yi6NBWvt1kWSbty3oBCwzar1OFqmjwSEF8xkY7+ToHw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rPkpJ8l7SYOHfabvOcfgeJ0R0AjzD7aCFwbDdA32qIlUW2M1dNvKD+lcvEQ8iuAqe LnX5fZXS5+YLDawS22IA/wKvwvcNI7V4/7fNSMffkUMvQZq3b30Rm2yMg6GZNljaDF N2kWSRlRlmAO9OWK+GokzxLmnbaPqxNvOaCERY3wfcKOCalHujLJstaUhtWk+1AHWu SqIdFlgfFzKPHrg2KCkP6/9vok5rj8KUjeN3N9whWNy6dmfrvUkaT3EZ0xIenGZTSY I99iVpgYooyTnZt6CY/013nkPBM5Ms1MzVGesJMxl+Eed1itGurZQqCBCu1goFWzRI xqTDPyU9pvJkA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Rand Deeb , Dave Kleikamp , Sasha Levin , shaggy@kernel.org, eadavis@qq.com, peili.dev@gmail.com, aha310510@gmail.com, ghanshyam1898@gmail.com, niharchaithanya@gmail.com, jfs-discussion@lists.sourceforge.net Subject: [PATCH AUTOSEL 6.6 08/26] fs/jfs: cast inactags to s64 to prevent potential overflow Date: Thu, 3 Apr 2025 15:07:27 -0400 Message-Id: <20250403190745.2677620-8-sashal@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250403190745.2677620-1-sashal@kernel.org> References: <20250403190745.2677620-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.6.85 Content-Transfer-Encoding: 8bit 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 f9009e4f9ffd8..f89f07c9580ea 100644 --- a/fs/jfs/jfs_dmap.c +++ b/fs/jfs/jfs_dmap.c @@ -3666,8 +3666,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