Re: [PATCH] shmem: do not extend i_size when no data was copied

From: Jan Kara

Date: Mon Oct 26 2026 - 11:50:18 EST


On Mon 26-10-26 15:34:08, Kiryl Shutsemau wrote:
> On Sun, Oct 25, 2026 at 04:46:19PM +0000, Hungyu Lin wrote:
> > shmem_write_end() advances i_size to pos + copied even when copied is
> > zero. A buffered write past EOF can therefore extend a tmpfs file
> > without writing any data.
>
> + willy, jack, fsdevel.
>
> This doesn't seem to be tmpfs-specific, right? I see the same with ext4.
>
> simple_write_end() and generic_write_end() check pos + copied the same
> way, so filesystems that use them through generic_perform_write() are
> affected too.
>
> It makes me think maybe generic_perform_write() is the right place to
> fix it. Hm?

Well, that would be nice. But how'd you like to do that? i_size update is
the responsibility of ->write_end and we have to call ->write_end if copied
== 0 so that is undoes what ->write_begin has prepared.

Honza

--
Jan Kara <jack@xxxxxxxx>
SUSE Labs, CR