From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 74AACC4332F for ; Tue, 7 Nov 2023 16:21:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235549AbjKGQVf (ORCPT ); Tue, 7 Nov 2023 11:21:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229959AbjKGQUy (ORCPT ); Tue, 7 Nov 2023 11:20:54 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91C05325E; Tue, 7 Nov 2023 07:54:02 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0C915C433C7; Tue, 7 Nov 2023 15:54:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1699372442; bh=ceHWTVGA9EM/EhI1jzMe9yw9hKsuwFG7Yh+OAwZf3QE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QNahZaIv81TlF69d6XNQya4t4jTkAfp438vzqR68S895/V/Pz4SvB/6+kyaHTulEJ /gloPF1/MriEwyi5703lg9La6mnMZyiQompHxHju9d0AkCdi7yQROuKOMeN9EG7LzB BMGetcBkOA23Z/5H0pDE7SNpwqmM7OeHuI8NCE5ac4uyxNzUdlRwbRzhWs59mB94Q9 3TPf+/Br/1LQLUXbm34MxRkhk0P02REjIWJKqDkia3uOlRO3xlIx+gmtppCEkalBvp f66JnHAK1TACRvyYUGQ9VviuelxyKQxyHVDHo/5v0PYrzVG7HG8S3md9dFHe7tDaln BXObsJoLVwspQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Manas Ghandat , syzbot+79d792676d8ac050949f@syzkaller.appspotmail.com, Dave Kleikamp , Sasha Levin , shaggy@kernel.org, jlayton@kernel.org, brauner@kernel.org, liushixin2@huawei.com, okanatov@gmail.com, jfs-discussion@lists.sourceforge.net Subject: [PATCH AUTOSEL 5.4 06/12] jfs: fix array-index-out-of-bounds in diAlloc Date: Tue, 7 Nov 2023 10:53:24 -0500 Message-ID: <20231107155343.3768464-6-sashal@kernel.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231107155343.3768464-1-sashal@kernel.org> References: <20231107155343.3768464-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 5.4.259 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Manas Ghandat [ Upstream commit 05d9ea1ceb62a55af6727a69269a4fd310edf483 ] Currently there is not check against the agno of the iag while allocating new inodes to avoid fragmentation problem. Added the check which is required. Reported-by: syzbot+79d792676d8ac050949f@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=79d792676d8ac050949f Signed-off-by: Manas Ghandat Signed-off-by: Dave Kleikamp Signed-off-by: Sasha Levin --- fs/jfs/jfs_imap.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fs/jfs/jfs_imap.c b/fs/jfs/jfs_imap.c index 67c67604b8c85..14f918a4831d3 100644 --- a/fs/jfs/jfs_imap.c +++ b/fs/jfs/jfs_imap.c @@ -1322,7 +1322,7 @@ diInitInode(struct inode *ip, int iagno, int ino, int extno, struct iag * iagp) int diAlloc(struct inode *pip, bool dir, struct inode *ip) { int rc, ino, iagno, addext, extno, bitno, sword; - int nwords, rem, i, agno; + int nwords, rem, i, agno, dn_numag; u32 mask, inosmap, extsmap; struct inode *ipimap; struct metapage *mp; @@ -1358,6 +1358,9 @@ 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) + return -EIO; if (atomic_read(&JFS_SBI(pip->i_sb)->bmap->db_active[agno])) { /* -- 2.42.0