mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@infradead.org>
To: Jan Prusakowski <jprusakowski@google.com>
Cc: Jaegeuk Kim <jaegeuk@kernel.org>, Chao Yu <chao@kernel.org>,
	linux-f2fs-devel@lists.sourceforge.net,
	linux-kernel@vger.kernel.org, Eric Biggers <ebiggers@google.com>,
	Yonggil Song <yonggil.song@samsung.com>,
	Hans Holmberg <hans.holmberg@wdc.com>
Subject: Re: [PATCH RESEND 5/9] f2fs: truncate blocks allocated past EOF by a failed direct write
Date: Fri, 20 Nov 2026 08:07:50 -0800	[thread overview]
Message-ID: <awBwVtp4y_bYK7fn@infradead.org> (raw)
In-Reply-To: <20261112143355.2923939-6-jprusakowski@google.com>

On Thu, Nov 12, 2026 at 02:33:51PM +0000, Jan Prusakowski wrote:
> When a direct write extends a file, f2fs_map_blocks() allocates the
> blocks past EOF and maps them into the dnode before the bio is
> submitted. If the write then fails, i_size is not updated, but the
> blocks stay mapped past EOF with whatever the disk contained before.
> A later extending write or truncate can make them visible.
> 
> f2fs_preallocate_blocks() already handles this for blocks it
> preallocates with F2FS_GET_BLOCK_PRE_DIO: it marks the inode with
> file_need_truncate() and f2fs_file_write_iter() truncates everything
> past i_size after a short write. But the preallocation is skipped in
> LFS mode and when the user buffer can't be faulted in, and then the
> blocks are allocated by F2FS_GET_BLOCK_DIO from f2fs_iomap_begin() and
> nothing truncates them.
> 
> Mark the inode with file_need_truncate() also when F2FS_GET_BLOCK_DIO
> allocates a block past EOF, and truncate after the write if the flag is
> set and the file is shorter than intended. Skip KEEP_SIZE files, where
> the truncation would also drop the blocks reserved by fallocate().

None of this fixes the issue in case the system crashes between these
ѕteps.  f2fs really needs to grow unwritten extent support or find some
other way to not add the mapping until I/O completion, otherwise this
remains broken and exploitable.

  reply	other threads:[~2026-11-20 16:07 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-12 14:33 [PATCH RESEND 0/9] f2fs: fix stale data exposure on failed O_DIRECT writes Jan Prusakowski
2026-11-12 14:33 ` [PATCH RESEND 1/9] f2fs: compress: avoid sleeping in atomic context in f2fs_decompress_cluster() Jan Prusakowski
2026-11-12 14:33 ` [PATCH RESEND 2/9] f2fs: compress: abort on read error in prepare_compress_overwrite() Jan Prusakowski
2026-11-12 14:33 ` [PATCH RESEND 3/9] f2fs: keep old block address when out-of-place write fails to allocate Jan Prusakowski
2026-11-12 14:33 ` [PATCH RESEND 4/9] f2fs: propagate errors from buffered fallback of O_DIRECT writes Jan Prusakowski
2026-11-12 14:33 ` [PATCH RESEND 5/9] f2fs: truncate blocks allocated past EOF by a failed direct write Jan Prusakowski
2026-11-20 16:07   ` Christoph Hellwig [this message]
2026-11-12 14:33 ` [PATCH RESEND 6/9] f2fs: roll back failed block updates of O_DIRECT buffered fallback Jan Prusakowski
2026-11-12 14:33 ` [PATCH RESEND 7/9] f2fs: roll back failed block updates of direct writes Jan Prusakowski
2026-11-12 14:33 ` [PATCH RESEND 8/9] f2fs: compress: fix cleanup when a cluster write fails to be submitted Jan Prusakowski
2026-11-12 14:33 ` [PATCH RESEND 9/9] f2fs: compress: roll back failed cluster writes of O_DIRECT buffered fallback Jan Prusakowski

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=awBwVtp4y_bYK7fn@infradead.org \
    --to=hch@infradead.org \
    --cc=chao@kernel.org \
    --cc=ebiggers@google.com \
    --cc=hans.holmberg@wdc.com \
    --cc=jaegeuk@kernel.org \
    --cc=jprusakowski@google.com \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=yonggil.song@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®