* [PATCH] ntfs3: fix uninit memory after failed mi_read in mi_format_new
@ 2025-09-25 20:36 Raphael Pinsonneault-Thibeault
2025-09-28 15:17 ` David Hunter
2025-09-28 15:25 ` David Hunter
0 siblings, 2 replies; 3+ messages in thread
From: Raphael Pinsonneault-Thibeault @ 2025-09-25 20:36 UTC (permalink / raw)
To: almaz.alexandrovich
Cc: Raphael Pinsonneault-Thibeault, ntfs3, linux-kernel, skhan,
david.hunter.linux, syzbot+7a2ba6b7b66340cff225
attr_insert_range() called from ntfs_fallocate() has 2 different
code paths that trigger mi_read() (which calls ntfs_read_bh).
If the first mi_read() -> ntfs_read_bh() fails with an IO error, it
leaves an uninitialized buffer in the buffer cache.
The second mi_read() -> ntfs_read_bh() then uses that buffer,
where we get KMSAN warning "uninit-value in ntfs_read_bh".
The fix is to check if mi_read failed in mi_format_new.
Reported-by: syzbot+7a2ba6b7b66340cff225@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=7a2ba6b7b66340cff225
Tested-by: syzbot+7a2ba6b7b66340cff225@syzkaller.appspotmail.com
Fixes: 4342306f0f0d5 ("fs/ntfs3: Add file operations and implementation")
Signed-off-by: Raphael Pinsonneault-Thibeault <rpthibeault@gmail.com>
---
fs/ntfs3/record.c | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)
diff --git a/fs/ntfs3/record.c b/fs/ntfs3/record.c
index 714c7ecedca8..98d2e5517077 100644
--- a/fs/ntfs3/record.c
+++ b/fs/ntfs3/record.c
@@ -431,13 +431,18 @@ int mi_format_new(struct mft_inode *mi, struct ntfs_sb_info *sbi, CLST rno,
seq = rno;
} else if (rno >= sbi->mft.used) {
;
- } else if (mi_read(mi, is_mft)) {
- ;
- } else if (rec->rhdr.sign == NTFS_FILE_SIGNATURE) {
- /* Record is reused. Update its sequence number. */
- seq = le16_to_cpu(rec->seq) + 1;
- if (!seq)
- seq = 1;
+ } else {
+ err = mi_read(mi, is_mft);
+ if (err) {
+ return err;
+ }
+
+ if (rec->rhdr.sign == NTFS_FILE_SIGNATURE) {
+ /* Record is reused. Update its sequence number. */
+ seq = le16_to_cpu(rec->seq) + 1;
+ if (!seq)
+ seq = 1;
+ }
}
memcpy(rec, sbi->new_rec, sbi->record_size);
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] ntfs3: fix uninit memory after failed mi_read in mi_format_new
2025-09-25 20:36 [PATCH] ntfs3: fix uninit memory after failed mi_read in mi_format_new Raphael Pinsonneault-Thibeault
@ 2025-09-28 15:17 ` David Hunter
2025-09-28 15:25 ` David Hunter
1 sibling, 0 replies; 3+ messages in thread
From: David Hunter @ 2025-09-28 15:17 UTC (permalink / raw)
To: Raphael Pinsonneault-Thibeault, almaz.alexandrovich
Cc: ntfs3, linux-kernel, skhan, syzbot+7a2ba6b7b66340cff225
On 9/25/25 16:36, Raphael Pinsonneault-Thibeault wrote:
> attr_insert_range() called from ntfs_fallocate() has 2 different
> code paths that trigger mi_read() (which calls ntfs_read_bh).
> If the first mi_read() -> ntfs_read_bh() fails with an IO error, it
> leaves an uninitialized buffer in the buffer cache.
> The second mi_read() -> ntfs_read_bh() then uses that buffer,
> where we get KMSAN warning "uninit-value in ntfs_read_bh".
>
> The fix is to check if mi_read failed in mi_format_new.
>
Did you do any testing for this patch?
David Hunter
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] ntfs3: fix uninit memory after failed mi_read in mi_format_new
2025-09-25 20:36 [PATCH] ntfs3: fix uninit memory after failed mi_read in mi_format_new Raphael Pinsonneault-Thibeault
2025-09-28 15:17 ` David Hunter
@ 2025-09-28 15:25 ` David Hunter
1 sibling, 0 replies; 3+ messages in thread
From: David Hunter @ 2025-09-28 15:25 UTC (permalink / raw)
To: Raphael Pinsonneault-Thibeault, almaz.alexandrovich
Cc: ntfs3, linux-kernel, skhan, syzbot+7a2ba6b7b66340cff225
On 9/25/25 16:36, Raphael Pinsonneault-Thibeault wrote:
> - } else if (mi_read(mi, is_mft)) {
> - ;
> - } else if (rec->rhdr.sign == NTFS_FILE_SIGNATURE) {
> - /* Record is reused. Update its sequence number. */
> - seq = le16_to_cpu(rec->seq) + 1;
> - if (!seq)
> - seq = 1;
> + } else {
> + err = mi_read(mi, is_mft);
> + if (err) {
> + return err;
> + }
> +
> + if (rec->rhdr.sign == NTFS_FILE_SIGNATURE) {
> + /* Record is reused. Update its sequence number. */
> + seq = le16_to_cpu(rec->seq) + 1;
> + if (!seq)
> + seq = 1;
> + }
How was this tested?
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-09-28 15:25 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-25 20:36 [PATCH] ntfs3: fix uninit memory after failed mi_read in mi_format_new Raphael Pinsonneault-Thibeault
2025-09-28 15:17 ` David Hunter
2025-09-28 15:25 ` David Hunter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox