Skip to contentSkip to conversation

ntfs: Fix null pointer dereference

PATCH Applied Ethan Tidmore 3 participants 3 messages Feb 25 – Feb 26

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ntfs: Fix null pointer dereference

The variable ctx can be null and once confirmed to be null in its error path goes to label err_out. Once there it can be immediately dereferenced by the function ntfs_attr_put_search_ctx() which has no null pointer check.

Detected by Smatch:
fs/ntfs/ea.c:687 ntfs_new_attr_flags() error:
we previously assumed 'ctx' could be null (see line 577)

Add null pointer check before running ntfs_attr_put_search_ctx() in error path.

Fixes fc053f05ca282 ("ntfs: add reparse and ea operations")
---
 fs/ntfs/ea.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/ntfs/ea.c +2 -1
index 82ad9b61ec64..b2b0a9a043a9 100644
@@ -684,7 +684,8 @@ static int ntfs_new_attr_flags(struct ntfs_inode *ni, __le32 fattr)
 	a->flags = new_aflags;
 	mark_mft_record_dirty(ctx->ntfs_ino);
 err_out:
-	ntfs_attr_put_search_ctx(ctx);
+	if (ctx)
+		ntfs_attr_put_search_ctx(ctx);
 	unmap_mft_record(ni);
 	return err;
 }
Signature · 1 line
2.53.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Ethan Tidmore

The variable ctx can be null and once confirmed to be null in its error path goes to label err_out. Once there it can be immediately dereferenced by the function ntfs_attr_put_search_ctx() which has no null pointer check.

Detected by Smatch:
fs/ntfs/ea.c:687 ntfs_new_attr_flags() error:
we previously assumed 'ctx' could be null (see line 577)

Quoted 5 lines

Add null pointer check before running ntfs_attr_put_search_ctx() in error path.

Fixes fc053f05ca282 ("ntfs: add reparse and ea operations")

Looks good to me. Thanks for the patch.

Quoted 21 lines
---
 fs/ntfs/ea.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/ntfs/ea.c +2 -1
index 82ad9b61ec64..b2b0a9a043a9 100644
@@ -684,7 +684,8 @@ static int ntfs_new_attr_flags(struct ntfs_inode *ni, __le32 fattr)
 	a->flags = new_aflags;
 	mark_mft_record_dirty(ctx->ntfs_ino);
 err_out:
-	ntfs_attr_put_search_ctx(ctx);
+	if (ctx)
+		ntfs_attr_put_search_ctx(ctx);
 	unmap_mft_record(ni);
 	return err;
 }
Signature · 1 line
2.53.0
Signature · 2 lines
Thanks,
Hyunchul
maintainer Applied
#2 lore raw
In reply to Ethan Tidmore
Quoted 9 lines · Ethan Tidmore

The variable ctx can be null and once confirmed to be null in its error path goes to label err_out. Once there it can be immediately dereferenced by the function ntfs_attr_put_search_ctx() which has no null pointer check.

Detected by Smatch:
fs/ntfs/ea.c:687 ntfs_new_attr_flags() error:
we previously assumed 'ctx' could be null (see line 577)

Quoted 5 lines

Add null pointer check before running ntfs_attr_put_search_ctx() in error path.

Fixes fc053f05ca282 ("ntfs: add reparse and ea operations")

Applied it to #ntfs-next.
Thanks!