mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chi Zhiling <chizhiling@163.com>
To: Namjae Jeon <linkinjeon@kernel.org>
Cc: exfat@lists.linux.dev, linux-kernel@vger.kernel.org,
	Yuezhang.Mo@sony.com, dxdt@dev.snart.me, sj1557.seo@samsung.com,
	Chi Zhiling <chizhiling@kylinos.cn>
Subject: Re: [PATCH v2 3/7] exfat: validate cached iomaps during buffered writes
Date: Wed, 14 Oct 2026 15:07:13 +0800	[thread overview]
Message-ID: <17da8380-6087-4cf3-8850-336dcf76f919@163.com> (raw)
In-Reply-To: <CAKYAXd-NdwvD9OO+_5UC5yVLp1OYf3KUFvPe_LRUkNjd9vuxvQ@mail.gmail.com>

On 10/14/2026 9:19 AM, Namjae Jeon wrote:
>> +static bool exfat_iomap_valid(struct inode *inode, const struct iomap *iomap)
>> +{
>> +       struct folio *folio = iomap->private;
>> +       loff_t old_valid_size = iomap->validity_cookie;
>> +       loff_t valid_size = exfat_get_valid_size(EXFAT_I(inode));
>> +
>> +       if (valid_size == old_valid_size)
> exfat_write_iomap_begin() reads valid_size before
> __exfat_iomap_begin() records the validity cookie. concurrent mmap
> fault can advance valid_size between those reads, allowing the stale
> value to zero mmap data before iomap_valid() is called:
> 
> buffered write [0,128)                       mmap fault
> Reads valid_size = 256
>                                                Raises valid_size to 4096
>                                                Stores 'X' at offset 400
> Records cookie = 4096
> Zeroes [256,512), erasing 'X'
> iomap_valid() sees cookie = 4096 and accepts
> 
> The validation runs too late to prevent this data loss. Could we
> recheck or serialize valid_size before zeroing?

Sorry, I forgot to address this issue, even though I had it in mind:

https://lore.kernel.org/exfat/7250425f-8626-4e8d-ab5a-32d9d4588ba9@163.com/

This is because the valid_size read in exfat_write_iomap_begin() can 
become stale.

I spent quite a while looking into this today and realized that I had 
oversimplified the problem. Moving the zeroing logic from 
exfat_write_iomap_begin() to ->put_folio won't solve it, because the 
folio has already been marked uptodate before ->put_folio is called.

I'll fix this in the next version, and hopefully the fix won't require 
more extensive changes.

Thanks!

> 
> 
>> +               return true;
>> +
>> +       if (!folio)
>> +               return false;
>> +
>> +       /* Still valid for this folio. */
>> +       if (old_valid_size >= folio_next_pos(folio))
>> +               return true;
>> +
>> +       if (valid_size <= folio_pos(folio))
>> +               return true;
>> +
>> +       return false;
>> +}
>> +


  reply	other threads:[~2026-10-14  7:07 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-13  3:38 [PATCH v2 0/7] exfat: fix valid_size update races Chi Zhiling
2026-10-13  3:38 ` [PATCH v2 1/7] exfat: advance valid_size under the folio lock for buffered writes Chi Zhiling
2026-10-13  3:38 ` [PATCH v2 2/7] exfat: advance valid_size while zeroing new ranges Chi Zhiling
2026-10-13  3:38 ` [PATCH v2 3/7] exfat: validate cached iomaps during buffered writes Chi Zhiling
2026-10-14  1:19   ` Namjae Jeon
2026-10-14  7:07     ` Chi Zhiling [this message]
2026-10-13  3:38 ` [PATCH v2 4/7] exfat: drop i_rwsem from exfat_page_mkwrite Chi Zhiling
2026-10-14  1:19   ` Namjae Jeon
2026-10-14  8:11     ` Chi Zhiling
2026-10-13  3:38 ` [PATCH v2 5/7] exfat: do not re-zero the valid range in exfat_page_mkwrite Chi Zhiling
2026-10-13  3:38 ` [PATCH v2 6/7] exfat: complete direct writes synchronously when they update metadata Chi Zhiling
2026-10-13  3:38 ` [PATCH v2 7/7] exfat: publish i_size and valid_size on direct I/O completion Chi Zhiling
2026-10-13  4:04 ` [PATCH v2 0/7] exfat: fix valid_size update races Namjae Jeon
2026-10-13  6:02   ` Chi Zhiling

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=17da8380-6087-4cf3-8850-336dcf76f919@163.com \
    --to=chizhiling@163.com \
    --cc=Yuezhang.Mo@sony.com \
    --cc=chizhiling@kylinos.cn \
    --cc=dxdt@dev.snart.me \
    --cc=exfat@lists.linux.dev \
    --cc=linkinjeon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sj1557.seo@samsung.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®