mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
To: Matthias Goergens <matthias.goergens@gmail.com>
Cc: linux-kernel@vger.kernel.org,
	syzbot+018e6f695ad9bccb182a@syzkaller.appspotmail.com,
	syzkaller-bugs@googlegroups.com
Subject: Re: [PATCH] fat: serialize primary and mirror updates
Date: Sat, 31 Oct 2026 13:20:51 +0900	[thread overview]
Message-ID: <87tsm25wm4.fsf@mail.parknet.co.jp> (raw)
In-Reply-To: <20261031033232.2490931-1-matthias.goergens@gmail.com>

Matthias Goergens <matthias.goergens@gmail.com> writes:

> __fat_alloc_clusters() drops fat_lock before syncing and mirroring
> modified buffer heads. Another allocation can change the primary FAT
> while an earlier allocation is copying it to the mirror.
>
> fat_ent_write() also updates and mirrors without fat_lock. Take the lock
> in both paths, preserving the existing post-unlock error cleanup.
>
> The test detector reproduced a primary-FAT write during a mirror copy.
> Three exact-current trials completed with no FAT conflicts and matching
> mirrors.

What is the real issue?

> Link: https://syzkaller.appspot.com/bug?extid=018e6f695ad9bccb182a
> ---
>  fs/fat/fatent.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/fs/fat/fatent.c b/fs/fat/fatent.c
> index 2d10a815a579..5f2779c7f947 100644
> --- a/fs/fat/fatent.c
> +++ b/fs/fat/fatent.c
> @@ -419,6 +419,7 @@ int fat_ent_write(struct inode *inode, struct fat_entry *fatent,
>  	const struct fatent_operations *ops = MSDOS_SB(sb)->fatent_ops;
>  	int err;
>  
> +	lock_fat(MSDOS_SB(sb));
>  	ops->ent_put(fatent, new);
>  	if (wait) {
>  		err = fat_sync_bhs(fatent->bhs, fatent->nr_bhs);
> @@ -429,7 +430,7 @@ int fat_ent_write(struct inode *inode, struct fat_entry *fatent,
>  			 * would not have value to write again on I/O
>  			 * error.
>  			 */
> -			return err;
> +			goto out_unlock;
>  		}
>  	}
>  
> @@ -440,6 +441,8 @@ int fat_ent_write(struct inode *inode, struct fat_entry *fatent,
>  		if (wait)
>  			fat_sync_bhs(fatent->bhs, fatent->nr_bhs);
>  	}
> +out_unlock:
> +	unlock_fat(MSDOS_SB(sb));
>  	return err;
>  }
>  
> @@ -582,7 +585,6 @@ static int __fat_alloc_clusters(struct inode *inode, int *cluster, int nr_cluste
>  	err = -ENOSPC;
>  
>  out:
> -	unlock_fat(sbi);
>  	mark_fsinfo_dirty(sb);
>  	fatent_brelse(&fatent);
>  	if (!err) {
> @@ -591,6 +593,7 @@ static int __fat_alloc_clusters(struct inode *inode, int *cluster, int nr_cluste
>  		if (!err)
>  			err = fat_mirror_bhs(sb, bhs, nr_bhs);
>  	}
> +	unlock_fat(sbi);
>  	for (i = 0; i < nr_bhs; i++)
>  		brelse(bhs[i]);
>  
>
> base-commit: d89e1d186ec9271bf78e62771779e9fc03bf0fc3

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

      reply	other threads:[~2026-10-31  4:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-31  3:32 Matthias Goergens
2026-10-31  4:20 ` OGAWA Hirofumi [this message]

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=87tsm25wm4.fsf@mail.parknet.co.jp \
    --to=hirofumi@mail.parknet.co.jp \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matthias.goergens@gmail.com \
    --cc=syzbot+018e6f695ad9bccb182a@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.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®