public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Juntong Deng <juntong.deng@outlook.com>,
	syzbot+38e876a8aa44b7115c76@syzkaller.appspotmail.com,
	Dave Kleikamp <dave.kleikamp@oracle.com>,
	Sasha Levin <sashal@kernel.org>,
	shaggy@kernel.org, yogi.kernel@gmail.com, ghandatmanas@gmail.com,
	liushixin2@huawei.com, code@siddh.me, wonguk.lee1023@gmail.com,
	andrew.kanner@gmail.com, jfs-discussion@lists.sourceforge.net
Subject: [PATCH AUTOSEL 5.4 04/12] fs/jfs: Add validity check for db_maxag and db_agpref
Date: Tue,  7 Nov 2023 10:53:22 -0500	[thread overview]
Message-ID: <20231107155343.3768464-4-sashal@kernel.org> (raw)
In-Reply-To: <20231107155343.3768464-1-sashal@kernel.org>

From: Juntong Deng <juntong.deng@outlook.com>

[ Upstream commit 64933ab7b04881c6c18b21ff206c12278341c72e ]

Both db_maxag and db_agpref are used as the index of the
db_agfree array, but there is currently no validity check for
db_maxag and db_agpref, which can lead to errors.

The following is related bug reported by Syzbot:

UBSAN: array-index-out-of-bounds in fs/jfs/jfs_dmap.c:639:20
index 7936 is out of range for type 'atomic_t[128]'

Add checking that the values of db_maxag and db_agpref are valid
indexes for the db_agfree array.

Reported-by: syzbot+38e876a8aa44b7115c76@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=38e876a8aa44b7115c76
Signed-off-by: Juntong Deng <juntong.deng@outlook.com>
Signed-off-by: Dave Kleikamp <dave.kleikamp@oracle.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 fs/jfs/jfs_dmap.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/fs/jfs/jfs_dmap.c b/fs/jfs/jfs_dmap.c
index 495a1c6e5fd46..b23b219b20aab 100644
--- a/fs/jfs/jfs_dmap.c
+++ b/fs/jfs/jfs_dmap.c
@@ -195,6 +195,12 @@ int dbMount(struct inode *ipbmap)
 	bmp->db_maxlevel = le32_to_cpu(dbmp_le->dn_maxlevel);
 	bmp->db_maxag = le32_to_cpu(dbmp_le->dn_maxag);
 	bmp->db_agpref = le32_to_cpu(dbmp_le->dn_agpref);
+	if (bmp->db_maxag >= MAXAG || bmp->db_maxag < 0 ||
+		bmp->db_agpref >= MAXAG || bmp->db_agpref < 0) {
+		err = -EINVAL;
+		goto err_release_metapage;
+	}
+
 	bmp->db_aglevel = le32_to_cpu(dbmp_le->dn_aglevel);
 	bmp->db_agheight = le32_to_cpu(dbmp_le->dn_agheight);
 	bmp->db_agwidth = le32_to_cpu(dbmp_le->dn_agwidth);
-- 
2.42.0


  parent reply	other threads:[~2023-11-07 16:03 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-07 15:53 [PATCH AUTOSEL 5.4 01/12] crypto: pcrypt - Fix hungtask for PADATA_RESET Sasha Levin
2023-11-07 15:53 ` [PATCH AUTOSEL 5.4 02/12] RDMA/hfi1: Use FIELD_GET() to extract Link Width Sasha Levin
2023-11-07 15:53 ` [PATCH AUTOSEL 5.4 03/12] fs/jfs: Add check for negative db_l2nbperpage Sasha Levin
2023-11-07 15:53 ` Sasha Levin [this message]
2023-11-07 15:53 ` [PATCH AUTOSEL 5.4 05/12] jfs: fix array-index-out-of-bounds in dbFindLeaf Sasha Levin
2023-11-07 15:53 ` [PATCH AUTOSEL 5.4 06/12] jfs: fix array-index-out-of-bounds in diAlloc Sasha Levin
2023-11-07 15:53 ` [PATCH AUTOSEL 5.4 07/12] ARM: 9320/1: fix stack depot IRQ stack filter Sasha Levin
2023-11-07 15:53 ` [PATCH AUTOSEL 5.4 08/12] ALSA: hda: Fix possible null-ptr-deref when assigning a stream Sasha Levin
2023-11-07 15:53 ` [PATCH AUTOSEL 5.4 09/12] PCI: tegra194: Use FIELD_GET()/FIELD_PREP() with Link Width fields Sasha Levin
2023-11-07 15:53 ` [PATCH AUTOSEL 5.4 10/12] atm: iphase: Do PCI error checks on own line Sasha Levin
2023-11-07 15:53 ` [PATCH AUTOSEL 5.4 11/12] scsi: libfc: Fix potential NULL pointer dereference in fc_lport_ptp_setup() Sasha Levin
2023-11-07 15:53 ` [PATCH AUTOSEL 5.4 12/12] HID: Add quirk for Dell Pro Wireless Keyboard and Mouse KM5221W Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231107155343.3768464-4-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=andrew.kanner@gmail.com \
    --cc=code@siddh.me \
    --cc=dave.kleikamp@oracle.com \
    --cc=ghandatmanas@gmail.com \
    --cc=jfs-discussion@lists.sourceforge.net \
    --cc=juntong.deng@outlook.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=liushixin2@huawei.com \
    --cc=shaggy@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=syzbot+38e876a8aa44b7115c76@syzkaller.appspotmail.com \
    --cc=wonguk.lee1023@gmail.com \
    --cc=yogi.kernel@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox