mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] Fix BUG: KCSAN: data-race in xas_find_marked / xas_init_marks
@ 2024-10-28 18:19 Daniel Yang
  2024-10-29  3:29 ` OGAWA Hirofumi
  0 siblings, 1 reply; 2+ messages in thread
From: Daniel Yang @ 2024-10-28 18:19 UTC (permalink / raw)
  To: OGAWA Hirofumi, open list; +Cc: Daniel Yang, syzbot+0dd28f0c6293cc87d462

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Fix BUG: KCSAN: data-race in xas_find_marked / xas_init_marks
  2024-10-28 18:19 [PATCH] Fix BUG: KCSAN: data-race in xas_find_marked / xas_init_marks Daniel Yang
@ 2024-10-29  3:29 ` OGAWA Hirofumi
  0 siblings, 0 replies; 2+ messages in thread
From: OGAWA Hirofumi @ 2024-10-29  3:29 UTC (permalink / raw)
  To: Daniel Yang; +Cc: open list, syzbot+0dd28f0c6293cc87d462

Daniel Yang <danielyangkang@gmail.com> writes:

> 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().

If writepages really races with truncate, why normal writeback path
doesn't need truncate_lock? And this introduces the ABBA locking bug.

Thanks.

> 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;

-- 
OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-10-29  3:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-28 18:19 [PATCH] Fix BUG: KCSAN: data-race in xas_find_marked / xas_init_marks Daniel Yang
2024-10-29  3:29 ` OGAWA Hirofumi

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®