All of lore.kernel.org
 help / color / mirror / Atom feed
From: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
To: Matheus Alves de Almeida <matheus.aalmeida@inf.ufrgs.br>
Cc: linux-fsdevel@vger.kernel.org,  linux-kernel@vger.kernel.org
Subject: Re: [PATCH] fat: hold truncate_lock in fat_write_failed()
Date: Sat, 24 Oct 2026 08:46:31 +0900	[thread overview]
Message-ID: <87ecdgq8tk.fsf@mail.parknet.co.jp> (raw)
In-Reply-To: <atvObRziUKEbNdUK@DESKTOP-PJTTJ93.localdomain>

Matheus Alves de Almeida <matheus.aalmeida@inf.ufrgs.br> writes:

> On Fri, Oct 23, 2026 at 04:34:34PM +0900, OGAWA Hirofumi wrote:
>>Matheus Alves de Almeida <matheus.aalmeida@inf.ufrgs.br> writes:
>>
>>> The current fat_write_failed() implementation calls into
>>> fat_truncate_blocks() without holding truncate_lock. Make it so it is
>>> held exclusive while truncating.
>>>
>>> Fixes: 459f6ed3b8c7 ("fat: convert to use the new truncate convention.")
>>> Signed-off-by: Matheus Alves de Almeida <matheus.aalmeida@inf.ufrgs.br>
>>> ---
>>>  fs/fat/inode.c | 2 ++
>>>  1 file changed, 2 insertions(+)
>>>
>>> diff --git a/fs/fat/inode.c b/fs/fat/inode.c
>>> index 141276fcf8db..2a16ed415631 100644
>>> --- a/fs/fat/inode.c
>>> +++ b/fs/fat/inode.c
>>> @@ -216,7 +216,9 @@ static void fat_write_failed(struct address_space *mapping, loff_t to)
>>>  
>>>  	if (to > inode->i_size) {
>>>  		truncate_pagecache(inode, inode->i_size);
>>> +		down_write(&MSDOS_I(inode)->truncate_lock);
>>>  		fat_truncate_blocks(inode, inode->i_size);
>>> +		up_write(&MSDOS_I(inode)->truncate_lock);
>>
>>Which race this prevent?
>>
>>Thanks.
>>
> fat_write_failed() can race with the users of fat_aops.bmap(). bmap()
> eventually reaches fat_get_cluster(), which assumes the file's cluster
> chain will not be truncated concurrently. fat_write_failed() currently
> truncates without holding truncate_lock.
>
> For comparison, fat_setattr() correctly holds truncate_lock during
> truncation:
>
> down_write(&MSDOS_I(inode)->truncate_lock);
> truncate_setsize(inode, attr->ia_size);
> fat_truncate_blocks(inode, attr->ia_size);
> up_write(&MSDOS_I(inode)->truncate_lock);

Hm, looks like true.
-- 
OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>

  reply	other threads:[~2026-10-23 23:46 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-21 16:21 [PATCH] fat: hold truncate_lock in fat_write_failed() Matheus Alves de Almeida
2026-10-23  7:34 ` OGAWA Hirofumi
2026-10-23 21:17   ` Matheus Alves de Almeida
2026-10-23 23:46     ` OGAWA Hirofumi [this message]
2026-10-24 19:26 ` OGAWA Hirofumi
2026-10-24 21:39 ` Pedro Falcato
2026-10-24 22:30   ` Matheus Alves de Almeida
2026-10-25  0:24 ` Andrew Morton
2026-10-25  0:52   ` Matheus Alves de Almeida
2026-10-25  3:57   ` 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=87ecdgq8tk.fsf@mail.parknet.co.jp \
    --to=hirofumi@mail.parknet.co.jp \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matheus.aalmeida@inf.ufrgs.br \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.