fs/ntfs3: zero frame pages on read error
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.
--- fs/ntfs3/frecord.c | 2 ++ 1 file changed, 2 insertions(+)
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); }
Signature · 1 line
2.43.0
Konstantin Komarov
maintainerQuoted 26 lines · Weiming Shi
ni_read_frame()marks every frame page uptodate at the 'out:' label regardless of the return value. The pages come fromntfs_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")Reported-by Xiang Mei <[email protected]>Assisted-by Claude:claude-opus-4-8Signed-off-by Weiming Shi <[email protected]>--- fs/ntfs3/frecord.c | 2 ++ 1 file changed, 2 insertions(+)fs/ntfs3/frecord.c +0
-0
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