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 86034248878; Tue, 29 Apr 2025 16:45:46 +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=1745945147; cv=none; b=oypu5vTDDiJ2p6zR5zo89w8R6jdYl51HTufNVN8LrigNHcuFv3uOC4S0MLcaVj65kObPoy1lM5CJHTfZpQYmCgPNg4SVAwZWf8B9kcHZU0pmdDrHZnbkdiuZSQnkzjXri85n1MKHT57Z6ZzRLc/s/GWCHkCW+h4oRoTwMoXqWz0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745945147; c=relaxed/simple; bh=0WsluXa3StjMi7eCab1jZMxFSS4C5AJ2MmrBjZpGjEU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=M2d2Yt0QntmZT8K7wEBNYbWf5CUR4Qzr3L/9oOJbEcPFTlon5kZyTuuV9kKlvfLmB6k6RtsfOcngYkHFq/7XppGk7knen+qIOOoCehYrr1TOGiA/i0dUXo6gUjBKj56HVK4XL4k87SZ8UIooMJUBtbGM7I7y+TmN/F/54tLYc3g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=ClecQigH; 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="ClecQigH" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9F851C4CEE3; Tue, 29 Apr 2025 16:45:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1745945146; bh=0WsluXa3StjMi7eCab1jZMxFSS4C5AJ2MmrBjZpGjEU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ClecQigHraEfYHhaAOruYW8WP62BCl6s0ZRt3VnWnM3biXpDpYgFIsSa2TgE/62Jd cW2X6F2hVXg4kGgRm4LioEOl6Mhwuh3pJCzf+xPI5MoXZIfd6jvScemH8ZqG86ZwuS 4RNUPuKDhWiksaaIbT3hz8+1TR74FBa0XkJpVuqQ= 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.4 017/179] fs/jfs: cast inactags to s64 to prevent potential overflow Date: Tue, 29 Apr 2025 18:39:18 +0200 Message-ID: <20250429161050.107646042@linuxfoundation.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250429161049.383278312@linuxfoundation.org> References: <20250429161049.383278312@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.4-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 812945c8e3840..3bc304d4886e6 100644 --- a/fs/jfs/jfs_dmap.c +++ b/fs/jfs/jfs_dmap.c @@ -3728,8 +3728,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