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 97063221DA7; Tue, 29 Apr 2025 17:10:48 +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=1745946648; cv=none; b=dfTMOmm7lTmH4wGziUkxSAovBORXB2g+qNzA5CqFYXm2Bp19lJGHZiAhyXGh1cexBYvK7H59qcCZaHLl+R6+i1MUHYlhGGEaa2RpLcjjLC9WAnAv8Do1yLWJrvGUQ3liG04hX4bDClfBFUAYY0fDHgecpt+Jxo94xJoAXYZHdnc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745946648; c=relaxed/simple; bh=6lq6DFhDkqw9hztk9RpVeYQowBsWwERxmkK3wagrktE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GzZpfunWU86v3lRZj35I4zrNxOjLhqHJZbnLXBjEviHK5t0EYNVA1NLdKh2LgG1GHasyKo181xZu2LpdJjBq3og8hMAmlSqe5S6zEpWKTJ4nTfmvDBUNdsZxVajPYlwFJTQFzp2Sfu7X1es75B1fOdIX0fA9w2PwvVWWChY4/JM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=ylYF3z/q; 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="ylYF3z/q" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0BBF6C4CEE3; Tue, 29 Apr 2025 17:10:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1745946648; bh=6lq6DFhDkqw9hztk9RpVeYQowBsWwERxmkK3wagrktE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ylYF3z/qgFFBzwcKGN4ix/ZZqLkkek89pGG4TV4bwBgQ4QU5rigROdFOICXltTkfr 4tOv+okf46muYl47dQp/41V5XRoOCqKWbGZItt1FJRZ3W3FReiPIV+BloO7ztaJtr8 lNy/e8Cyccb2t0NInbrLbgcdziXFykxB46xuV1To= 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.10 023/286] fs/jfs: Prevent integer overflow in AG size calculation Date: Tue, 29 Apr 2025 18:38:47 +0200 Message-ID: <20250429161108.806582784@linuxfoundation.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250429161107.848008295@linuxfoundation.org> References: <20250429161107.848008295@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.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Rand Deeb [ Upstream commit 7fcbf789629cdb9fbf4e2172ce31136cfed11e5e ] The JFS filesystem calculates allocation group (AG) size using 1 << l2agsize in dbExtendFS(). When l2agsize exceeds 31 (possible with >2TB aggregates on 32-bit systems), this 32-bit shift operation causes undefined behavior and improper AG sizing. On 32-bit architectures: - Left-shifting 1 by 32+ bits results in 0 due to integer overflow - This creates invalid AG sizes (0 or garbage values) in sbi->bmap->db_agsize - Subsequent block allocations would reference invalid AG structures - Could lead to: - Filesystem corruption during extend operations - Kernel crashes due to invalid memory accesses - Security vulnerabilities via malformed on-disk structures Fix by casting to s64 before shifting: bmp->db_agsize = (s64)1 << l2agsize; This ensures 64-bit arithmetic even on 32-bit architectures. The cast matches the data type of db_agsize (s64) and follows similar patterns in JFS block calculation code. 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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/jfs/jfs_dmap.c b/fs/jfs/jfs_dmap.c index 389dafd23d15e..3cc10f9bf9f8b 100644 --- a/fs/jfs/jfs_dmap.c +++ b/fs/jfs/jfs_dmap.c @@ -3465,7 +3465,7 @@ int dbExtendFS(struct inode *ipbmap, s64 blkno, s64 nblocks) oldl2agsize = bmp->db_agl2size; bmp->db_agl2size = l2agsize; - bmp->db_agsize = 1 << l2agsize; + bmp->db_agsize = (s64)1 << l2agsize; /* compute new number of AG */ agno = bmp->db_numag; -- 2.39.5