Skip to content

Commit

Permalink
fs/ntfs3: Fix NULL dereference in ni_write_inode
Browse files Browse the repository at this point in the history
[ Upstream commit 8dae4f6 ]

Syzbot reports a NULL dereference in ni_write_inode.
When creating a new inode, if allocation fails in mi_init function
(called in mi_format_new function), mi->mrec is set to NULL.
In the error path of this inode creation, mi->mrec is later
dereferenced in ni_write_inode.

Add a NULL check to prevent NULL dereference.

Link: https://syzkaller.appspot.com/bug?extid=f45957555ed4a808cc7a
Reported-and-tested-by: [email protected]
Signed-off-by: Abdun Nihaal <[email protected]>
Signed-off-by: Konstantin Komarov <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
  • Loading branch information
nifey authored and gregkh committed May 24, 2023
1 parent f28d9e0 commit b1135fb
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions fs/ntfs3/frecord.c
Original file line number Diff line number Diff line change
Expand Up @@ -3258,6 +3258,9 @@ int ni_write_inode(struct inode *inode, int sync, const char *hint)
return 0;
}

if (!ni->mi.mrec)
goto out;

if (is_rec_inuse(ni->mi.mrec) &&
!(sbi->flags & NTFS_FLAGS_LOG_REPLAYING) && inode->i_nlink) {
bool modified = false;
Expand Down

0 comments on commit b1135fb

Please sign in to comment.