From: Nihar Chaithanya Date: Tue, 8 Oct 2024 20:21:38 +0000 (+0530) Subject: jfs: add a check to prevent array-index-out-of-bounds in dbAdjTree X-Git-Tag: v5.15.174~64 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a3d408870bc19b794646871bc4c3a5daa66f91c5;p=thirdparty%2Fkernel%2Fstable.git jfs: add a check to prevent array-index-out-of-bounds in dbAdjTree [ Upstream commit a174706ba4dad895c40b1d2277bade16dfacdcd9 ] When the value of lp is 0 at the beginning of the for loop, it will become negative in the next assignment and we should bail out. Reported-by: syzbot+412dea214d8baa3f7483@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=412dea214d8baa3f7483 Tested-by: syzbot+412dea214d8baa3f7483@syzkaller.appspotmail.com Signed-off-by: Nihar Chaithanya Signed-off-by: Dave Kleikamp Signed-off-by: Sasha Levin --- diff --git a/fs/jfs/jfs_dmap.c b/fs/jfs/jfs_dmap.c index 7486c79a5058b..e6cbe4c982c58 100644 --- a/fs/jfs/jfs_dmap.c +++ b/fs/jfs/jfs_dmap.c @@ -2957,6 +2957,9 @@ static void dbAdjTree(dmtree_t *tp, int leafno, int newval, bool is_ctl) /* bubble the new value up the tree as required. */ for (k = 0; k < le32_to_cpu(tp->dmt_height); k++) { + if (lp == 0) + break; + /* get the index of the first leaf of the 4 leaf * group containing the specified leaf (leafno). */