fs/ntfs3: do not mark frame pages uptodate on read error
Subsystems (2)
PATCH 1/1 fs/ntfs3: do not mark frame pages uptodate on read error
ni_read_frame() ends with a loop that marks every page of a compressed frame uptodate regardless of whether the read succeeded:
out:
for (i = 0; i < pages_per_frame; i++) {
pg = pages[i];
SetPageUptodate(pg);
}Non-critical frame pages come from __filemap_get_folio(FGP_CREAT) and are not zeroed. On an error path that reaches out: before frame_mem is written, these pages keep uninitialized page-allocator contents but are still marked uptodate. A later read() is then served from the page cache and returns that stale kernel memory to user space.
For an unprivileged user mounting a crafted NTFS image this is a repeatable kernel memory disclosure.
Mark the pages uptodate only on success; on error leave them !uptodate so the read path re-reads them or reports the error.
--- fs/ntfs3/frecord.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/ntfs3/frecord.c +2 -1
@@ -2467,7 +2467,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]; -SetPageUptodate (pg); +if (!err) +SetPageUptodate (pg); }return err;
Signature · 1 line
2.43.0
Konstantin Komarov
maintainerQuoted 33 lines · Weiming Shi
ni_read_frame()ends with a loop that marks every page of a compressed frame uptodate regardless of whether the read succeeded:out: for (i = 0; i < pages_per_frame; i++) { pg = pages[i]; SetPageUptodate(pg); }Non-critical frame pages come from
__filemap_get_folio(FGP_CREAT)and are not zeroed. On an error path that reaches out: beforeframe_memis written, these pages keep uninitialized page-allocator contents but are still marked uptodate. A laterread()is then served from the page cache and returns that stale kernel memory to user space.For an unprivileged user mounting a crafted NTFS image this is a repeatable kernel memory disclosure.
Mark the pages uptodate only on success; on error leave them !uptodate so the read path re-reads them or reports the error.
Fixes 4342306f0f0d ("fs/ntfs3: Add file operations and implementation")Reported-by Xiang Mei <[email protected]>Signed-off-by Weiming Shi <[email protected]>--- fs/ntfs3/frecord.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)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 2474
Quoted 9 lines
fs/ntfs3/frecord.c +2
-1@@ -2467,7 +2467,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]; -SetPageUptodate (pg); +if (!err) +SetPageUptodate (pg); }return err;
Hello,
Your patch was applied, thank you.
Regards,
Konstantin