From: Kiryl Shutsemau <kas@kernel.org>
To: Jan Kara <jack@suse.cz>
Cc: Hungyu Lin <dennylin0707@gmail.com>,
willy@infradead.org, hughd@google.com,
baolin.wang@linux.alibaba.com, akpm@linux-foundation.org,
dave.hansen@linux.intel.com, linux-fsdevel@vger.kernel.org,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH] shmem: do not extend i_size when no data was copied
Date: Mon, 26 Oct 2026 18:18:39 +0000 [thread overview]
Message-ID: <at-XtWBQg3jv3H8Z@thinkstation> (raw)
In-Reply-To: <xmp7ni65vbinfj4j2baisrhp6xzro3asbepuq7xp3mvx6maptn@r4dnoj63uw4t>
On Mon, Oct 26, 2026 at 04:48:58PM +0100, Jan Kara wrote:
> 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.
Hm.
A zero-length copy only moves i_size if the write starts beyond EOF.
So we can bring the prefault back just for that case, before
->write_begin():
if (unlikely(pos > i_size_read(mapping->host)) &&
fault_in_iov_iter_readable(i, bytes) == bytes) {
status = -EFAULT;
break;
}
Overwrites and appends keep skipping the prefault. It is racy against
a concurrent munmap(), as it was before 665575cff098, but that is
userspace racing with itself.
The per-filesystem alternative is a 'copied &&' in every ->write_end.
And generic_write_end() cannot take it as is: generic_cont_expand_simple()
relies on a zero-length ->write_end() extending i_size. So we need some
replacement.
--
Kiryl Shutsemau / Kirill A. Shutemov
prev parent reply other threads:[~2026-10-26 18:18 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-25 16:46 Hungyu Lin
2026-10-26 15:34 ` Kiryl Shutsemau
2026-10-26 15:48 ` Jan Kara
2026-10-26 18:18 ` Kiryl Shutsemau [this message]
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=at-XtWBQg3jv3H8Z@thinkstation \
--to=kas@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=dave.hansen@linux.intel.com \
--cc=dennylin0707@gmail.com \
--cc=hughd@google.com \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=stable@vger.kernel.org \
--cc=willy@infradead.org \
/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®