bcachefs: Fix a null ptr deref in check_xattr()
authorKent Overstreet <kent.overstreet@linux.dev>
Thu, 20 Jul 2023 23:30:53 +0000 (19:30 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:10:08 +0000 (17:10 -0400)
We were attempting to initialize inode hash info when no inodes were
found.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/fsck.c

index 022af0270692fe563555e72e0ceff424af21f501..5338765b3e68ed1b3f44415f59e5550881a71d58 100644 (file)
@@ -1662,7 +1662,7 @@ static int check_dirent(struct btree_trans *trans, struct btree_iter *iter,
        if (ret < 0)
                goto err;
 
-       if (dir->first_this_inode)
+       if (dir->first_this_inode && dir->inodes.nr)
                *hash_info = bch2_hash_info_init(c, &dir->inodes.data[0].inode);
        dir->first_this_inode = false;
 
@@ -1839,7 +1839,7 @@ static int check_xattr(struct btree_trans *trans, struct btree_iter *iter,
        if (ret)
                return ret;
 
-       if (inode->first_this_inode)
+       if (inode->first_this_inode && inode->inodes.nr)
                *hash_info = bch2_hash_info_init(c, &inode->inodes.data[0].inode);
        inode->first_this_inode = false;