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 CA21D1EC011; Wed, 6 Nov 2024 12:59:18 +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=1730897958; cv=none; b=C6Zwes51foNByAuKv1zxkRuSZRCLc7Gs2KJvmUq9T0fuCotPzJxCfQDiVXIRXY5In3hJYvKg3T5OdQxL7/NoSKCUvjYKi0kMbRuHmJIyO8cFMJbwpDK7YFhobJtvedCdNX/ykrqi+jPDpk93r8mHudeZJtYj95V7N52IjTfQR3s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730897958; c=relaxed/simple; bh=TE+FDz3vMlbC3dpGqlO9D3fMh0qXJJq1Eahe6qqj/ic=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TpBcvQqMoxzy7RbOqnBfH7/fj2J3JQdgLklD/pHTKPNikjHI885WfTLP9wREkiBY2Ncq2hzQ8arpp6EgwjRTRXoH4Z8LeZLr4IyDWiEkUjiT5U83cqW3Cef/COqp416h7JHdNT8Z2HdTjPEWfD7/ydWaodjxCkrywz9rC7GWUMo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=XliSq6lc; 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="XliSq6lc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4FE78C4CECD; Wed, 6 Nov 2024 12:59:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1730897958; bh=TE+FDz3vMlbC3dpGqlO9D3fMh0qXJJq1Eahe6qqj/ic=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XliSq6lc5QmovMFJzn4/n2qrNh/fGag4BoSJDspqNp08Js+0bLYNglFBgulSwMeiU Lj6qAa5A3HMOYbCq3PajRCNAPtjLHX4ryWgUdUz7VGlGnI1aTgvaNaPH/JIQgLSTxk cSs7vx5OMsN4FLVVFKXtJ+oYM6DEkxfNj/V1EtAc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Jeongjun Park , Dave Kleikamp , Sasha Levin Subject: [PATCH 5.4 077/462] jfs: fix out-of-bounds in dbNextAG() and diAlloc() Date: Wed, 6 Nov 2024 12:59:30 +0100 Message-ID: <20241106120333.409590902@linuxfoundation.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241106120331.497003148@linuxfoundation.org> References: <20241106120331.497003148@linuxfoundation.org> User-Agent: quilt/0.67 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: Jeongjun Park [ Upstream commit e63866a475562810500ea7f784099bfe341e761a ] In dbNextAG() , there is no check for the case where bmp->db_numag is greater or same than MAXAG due to a polluted image, which causes an out-of-bounds. Therefore, a bounds check should be added in dbMount(). And in dbNextAG(), a check for the case where agpref is greater than bmp->db_numag should be added, so an out-of-bounds exception should be prevented. Additionally, a check for the case where agno is greater or same than MAXAG should be added in diAlloc() to prevent out-of-bounds. Reported-by: Jeongjun Park Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Jeongjun Park Signed-off-by: Dave Kleikamp Signed-off-by: Sasha Levin --- fs/jfs/jfs_dmap.c | 4 ++-- fs/jfs/jfs_imap.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/jfs/jfs_dmap.c b/fs/jfs/jfs_dmap.c index deb54efb56013..fe0b5a91356c4 100644 --- a/fs/jfs/jfs_dmap.c +++ b/fs/jfs/jfs_dmap.c @@ -187,7 +187,7 @@ int dbMount(struct inode *ipbmap) } bmp->db_numag = le32_to_cpu(dbmp_le->dn_numag); - if (!bmp->db_numag) { + if (!bmp->db_numag || bmp->db_numag >= MAXAG) { err = -EINVAL; goto err_release_metapage; } @@ -652,7 +652,7 @@ int dbNextAG(struct inode *ipbmap) * average free space. */ for (i = 0 ; i < bmp->db_numag; i++, agpref++) { - if (agpref == bmp->db_numag) + if (agpref >= bmp->db_numag) agpref = 0; if (atomic_read(&bmp->db_active[agpref])) diff --git a/fs/jfs/jfs_imap.c b/fs/jfs/jfs_imap.c index 36ed756820648..da3a1c27d3498 100644 --- a/fs/jfs/jfs_imap.c +++ b/fs/jfs/jfs_imap.c @@ -1362,7 +1362,7 @@ int diAlloc(struct inode *pip, bool dir, struct inode *ip) /* get the ag number of this iag */ agno = BLKTOAG(JFS_IP(pip)->agstart, JFS_SBI(pip->i_sb)); dn_numag = JFS_SBI(pip->i_sb)->bmap->db_numag; - if (agno < 0 || agno > dn_numag) + if (agno < 0 || agno > dn_numag || agno >= MAXAG) return -EIO; if (atomic_read(&JFS_SBI(pip->i_sb)->bmap->db_active[agno])) { -- 2.43.0