]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
jfs: fix array-index-out-of-bounds in jfs_readdir
authorGhanshyam Agrawal <ghanshyam1898@gmail.com>
Tue, 1 Oct 2024 06:05:47 +0000 (11:35 +0530)
committerDave Kleikamp <dave.kleikamp@oracle.com>
Tue, 29 Oct 2024 22:03:41 +0000 (17:03 -0500)
The stbl might contain some invalid values. Added a check to
return error code in that case.

Reported-by: syzbot+0315f8fe99120601ba88@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=0315f8fe99120601ba88
Signed-off-by: Ghanshyam Agrawal <ghanshyam1898@gmail.com>
Signed-off-by: Dave Kleikamp <dave.kleikamp@oracle.com>
fs/jfs/jfs_dtree.c

index 69fd936fbdb37995a38c978f1bbb2f27d5df9112..8f85177f284b5a5aee2abc5734ef573aac957816 100644 (file)
@@ -2891,6 +2891,14 @@ int jfs_readdir(struct file *file, struct dir_context *ctx)
                stbl = DT_GETSTBL(p);
 
                for (i = index; i < p->header.nextindex; i++) {
+                       if (stbl[i] < 0 || stbl[i] > 127) {
+                               jfs_err("JFS: Invalid stbl[%d] = %d for inode %ld, block = %lld",
+                                       i, stbl[i], (long)ip->i_ino, (long long)bn);
+                               free_page(dirent_buf);
+                               DT_PUTPAGE(mp);
+                               return -EIO;
+                       }
+
                        d = (struct ldtentry *) & p->slot[stbl[i]];
 
                        if (((long) jfs_dirent + d->namlen + 1) >