Re: [PATCH] buffer: avoid extending i_size after failed writes
From: Kiryl Shutsemau
Date: Tue Nov 03 2026 - 07:57:40 EST
On Tue, Nov 03, 2026 at 07:22:34AM +0000, Hungyu Lin wrote:
> generic_write_end() updates i_size to pos + copied even when a nonempty
> write copied no data. Since prefaulting moved to the slow write path, a
> pwrite() past EOF from an unreadable buffer can fail with EFAULT after
> extending the file to the write offset.
>
> For example, on ext2, a one-byte pwrite() at offset 4096 into an empty
> file fails with EFAULT but leaves a 4096-byte file.
>
> Require copied data before extending i_size for a nonempty write. Keep
> zero-length write_end() calls working, since generic_cont_expand_simple()
> uses them for expanding truncate operations.
>
> Also call pagecache_isize_extended() only when i_size changed. Otherwise,
> blocking the size update would leave its endpoint beyond EOF and trigger
> its warning.
>
> Fixes: 665575cff098 ("filemap: move prefaulting out of hot write path")
> Reported-by: Kiryl Shutsemau <kas@xxxxxxxxxx>
> Link: https://lore.kernel.org/linux-mm/at9xXRhD2xZhszEj@thinkstation/
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Hungyu Lin <dennylin0707@xxxxxxxxx>
Jan is okay with what I proposed here:
https://lore.kernel.org/all/at-XtWBQg3jv3H8Z@thinkstation
Do you want to give it a try instead? Or want me to submit a proper patch?
--
Kiryl Shutsemau / Kirill A. Shutemov