Skip to contentSkip to conversation

fs/ntfs3: zero frame pages on read error

PATCH In review Weiming Shi 2 participants 2 messages Jun 25 – Sep 14 NTFS3 filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs/ntfs3: zero frame pages on read error

ni_read_frame() marks every frame page uptodate at the 'out:' label regardless of the return value. The pages come from ntfs_lock_new_page() and are not zeroed, and several error paths reach 'out:' before anything is written to them (e.g. a failed decompress_lznt()/decompress_lzx_xpress() on a corrupted chunk, or an allocation failure).

A page marked uptodate is served directly from the page cache, so a later read() of the file returns the uninitialized page contents to userspace. On a crafted compressed image this leaks kernel memory, including pointers.

Zero each page on the error path before marking it uptodate. The success path is unchanged.

Fixes 4342306f0f0d ("fs/ntfs3: Add file operations and implementation")
Assisted-by Claude:claude-opus-4-8
---
 fs/ntfs3/frecord.c | 2 ++
 1 file changed, 2 insertions(+)
fs/ntfs3/frecord.c +2 -0
index 2b49bc077558..ca3b46a2c9c5 100644
@@ -2469,6 +2469,8 @@ int ni_read_frame(struct ntfs_inode *ni, u64 frame_vbo, struct page **pages,
 out:
 	for (i = 0; i < pages_per_frame; i++) {
 		pg = pages[i];
+		if (err)
+			clear_highpage(pg);
 		SetPageUptodate(pg);
 	}
 
Signature · 1 line
2.43.0
#1 lore raw
Quoted 26 lines · Weiming Shi

ni_read_frame() marks every frame page uptodate at the 'out:' label regardless of the return value. The pages come from ntfs_lock_new_page() and are not zeroed, and several error paths reach 'out:' before anything is written to them (e.g. a failed decompress_lznt()/decompress_lzx_xpress() on a corrupted chunk, or an allocation failure).

A page marked uptodate is served directly from the page cache, so a later read() of the file returns the uninitialized page contents to userspace. On a crafted compressed image this leaks kernel memory, including pointers.

Zero each page on the error path before marking it uptodate. The success path is unchanged.

Fixes 4342306f0f0d ("fs/ntfs3: Add file operations and implementation")
Assisted-by Claude:claude-opus-4-8
---
  fs/ntfs3/frecord.c | 2 ++
  1 file changed, 2 insertions(+)
fs/ntfs3/frecord.c +0 -0
index 2b49bc077558..ca3b46a2c9c5 100644

fs/ntfs3/frecord.c int ni_read_frame(struct ntfs_inode *ni, u64 frame_vbo, struct page **pages, · line 2476

Quoted 8 lines
fs/ntfs3/frecord.c +2 -0
@@ -2469,6 +2469,8 @@ int ni_read_frame(struct ntfs_inode *ni, u64 frame_vbo, struct page **pages,
  out:
  	for (i = 0; i < pages_per_frame; i++) {
  		pg = pages[i];
+		if (err)
+			clear_highpage(pg);
  		SetPageUptodate(pg);
  	}
 

Hello,

Sorry for the delay.
The patch is applied, thank you.

Regards,
Konstantin