[PATCH] fs/ntfs3: dealing with situations where dir_search_u may return null

From: Edward Adam Davis
Date: Sun Jun 02 2024 - 05:57:10 EST


If hdr_find_e() fails to find an entry in the index buffer, dir_search_u() maybe
return NULL.
Therefore, it is necessary to add relevant judgment conditions in ntfs_lookup().

Reported-and-tested-by: syzbot+5d34cc6474499a5ff516@xxxxxxxxxxxxxxxxxxxxxxxxx
Signed-off-by: Edward Adam Davis <eadavis@xxxxxx>
---
fs/ntfs3/namei.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/ntfs3/namei.c b/fs/ntfs3/namei.c
index 084d19d78397..293c37171d97 100644
--- a/fs/ntfs3/namei.c
+++ b/fs/ntfs3/namei.c
@@ -93,7 +93,7 @@ static struct dentry *ntfs_lookup(struct inode *dir, struct dentry *dentry,
* If the MFT record of ntfs inode is not a base record, inode->i_op can be NULL.
* This causes null pointer dereference in d_splice_alias().
*/
- if (!IS_ERR_OR_NULL(inode) && !inode->i_op) {
+ if (IS_ERR_OR_NULL(inode) || !inode->i_op) {
iput(inode);
inode = ERR_PTR(-EINVAL);
}
--
2.43.0