mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Daniel Yang <danielyangkang@gmail.com>
To: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>,
	linux-kernel@vger.kernel.org (open list)
Cc: Daniel Yang <danielyangkang@gmail.com>,
	syzbot+0dd28f0c6293cc87d462@syzkaller.appspotmail.com
Subject: [PATCH] Fix BUG: KCSAN: data-race in xas_find_marked / xas_init_marks
Date: Mon, 28 Oct 2024 11:19:22 -0700	[thread overview]
Message-ID: <20241028181922.406204-1-danielyangkang@gmail.com> (raw)

The cause of the bug is a call to truncate_setsize() while
fat_file_fsync() is attempting to read. Although fat_setattr() acquires
&MSDOS_I(inode)->truncate_lock before calling truncate, fat_file_fsync()
doesn't acquire the read lock for truncate_lock. The function
__generic_file_fsync() called in fat_file_fsync() only acquires lock to
the inode itself, not the &MSDOS_I(inode) it is a member of. This leads
to the data race where fat_file_fsync is reading during truncation.

To fix: &MSDOS_I(inode)->truncate_lock is acquired for reading before
calling __generic_file_fsync().

Signed-off-by: Daniel Yang <danielyangkang@gmail.com>
Reported-by: syzbot+0dd28f0c6293cc87d462@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=0dd28f0c6293cc87d462
---
 fs/fat/file.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/fs/fat/file.c b/fs/fat/file.c
index e887e9ab7..5578b771a 100644
--- a/fs/fat/file.c
+++ b/fs/fat/file.c
@@ -188,7 +188,9 @@ int fat_file_fsync(struct file *filp, loff_t start, loff_t end, int datasync)
 	struct inode *inode = filp->f_mapping->host;
 	int err;
 
+	down_read(&MSDOS_I(inode)->truncate_lock);
 	err = __generic_file_fsync(filp, start, end, datasync);
+	up_read(&MSDOS_I(inode)->truncate_lock);
 	if (err)
 		return err;
 
-- 
2.39.2


             reply	other threads:[~2024-10-28 18:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-28 18:19 Daniel Yang [this message]
2024-10-29  3:29 ` OGAWA Hirofumi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241028181922.406204-1-danielyangkang@gmail.com \
    --to=danielyangkang@gmail.com \
    --cc=hirofumi@mail.parknet.co.jp \
    --cc=linux-kernel@vger.kernel.org \
    --cc=syzbot+0dd28f0c6293cc87d462@syzkaller.appspotmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®