Skip to contentSkip to conversation

fs/ntfs3: do not mark frame pages uptodate on read error

PATCH In review Weiming Shi 2 participants 2 messages Jul 12 – Oct 7

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

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.

Fixes 4342306f0f0d ("fs/ntfs3: Add file operations and implementation")
---
 fs/ntfs3/frecord.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/ntfs3/frecord.c +2 -1
index 2d2644d80017..862baafb80e3 100644
@@ -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
#1 lore raw
Quoted 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: 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.

Fixes 4342306f0f0d ("fs/ntfs3: Add file operations and implementation")
---
  fs/ntfs3/frecord.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
fs/ntfs3/frecord.c +0 -0
index 2d2644d80017..862baafb80e3 100644

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