[PATCH v2 0/2] f2fs: zero preallocated blocks of pinned files for unprivileged users

From: Hungyu Lin

Date: Fri Dec 04 2026 - 21:21:31 EST


fallocate() on a pinned file hands out blocks without zeroing them, and
any user can pin a file, so any user can read back data of files that
other users have deleted. v1 required CAP_SYS_ADMIN for fallocate() on a
pinned file. This version zeroes the blocks for callers without
CAP_SYS_ADMIN instead, so that they can still preallocate.

Patch 1 keeps the pinned log from switching to SSR while checkpoint is
disabled. It is a fix on its own, and patch 2 needs it: the blocks are
zeroed one section at a time before they are allocated, which relies on
the pinned log staying in its section.

Patch 2 zeroes the free blocks of the pinning section.
f2fs_secure_erase() is not used, as it works on blocks which are already
mapped to the file. The blocks are zeroed on the device, so an encrypted
pinned file reads them back as the decryption of zeroes.

Changes since v1:
- Zero the blocks for callers without CAP_SYS_ADMIN instead of refusing
fallocate(), as suggested by Chao Yu. They are zeroed before the
allocation rather than after it, so that a concurrent read cannot see
the old data and the blocks which the file already had are kept.
- Add patch 1.

v1: https://lore.kernel.org/all/20261108075357.43331-1-dennylin0707@xxxxxxxxx/

Hungyu Lin (2):
f2fs: fix to avoid pinfile fragment on checkpoint=disable mode
f2fs: zero preallocated blocks of pinned files for unprivileged users

fs/f2fs/f2fs.h | 1 +
fs/f2fs/file.c | 3 +++
fs/f2fs/segment.c | 40 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 44 insertions(+)


base-commit: 029b14ff22f28fddba992d58a216d30bda45586a
--
2.43.0