Re:Re: [PATCH 3/6] ntfs: read initialized_size under size_lock in the iomap paths

From: dd

Date: Thu Nov 26 2026 - 04:35:16 EST






At 2026-11-26 16:45:50, "Hyunchul Lee" <hyc.lee@xxxxxxxxx> wrote:
>> if (!(flags & IOMAP_ZERO) &&
>> - iomap->type == IOMAP_MAPPED &&
>> - iomap->offset < ni->initialized_size &&
>> - iomap->offset + iomap->length > ni->initialized_size) {
>> - iomap->length = round_up(ni->initialized_size, 1 << inode->i_blkbits) -
>> - iomap->offset;
>> + iomap->type == IOMAP_MAPPED) {
>> + loff_t initialized_size;
>> +
>> + read_lock_irqsave(&ni->size_lock, irqflags);
>> + initialized_size = ni->initialized_size;
>> + read_unlock_irqrestore(&ni->size_lock, irqflags);
>
>Is it safe to read the size again instead of reusing the first one?

No. The type of the mapping was decided against the first snapshot,
and a concurrent extension in between could clamp a MAPPED extent to a
boundary the type decision never saw. v2 reuses the first snapshot
for the length adjustment.

>And the size_lock is missing in ntfs_iomap_read_end_io.
You are right, that is a miss: it runs in the bio completion path and holds no
other lock, and on 32-bit the unlocked read can tear. v2 takes the
size_lock there as well, in the same patch.
Thanks for the review.

>
>--
>Thanks,
>Hyunchul