Skip to content

Commit 3457a5c

Browse files
gnoackl0kod
authored andcommitted
landlock: Document fallocate(2) as another truncation corner case
Reinforce the already stated policy that LANDLOCK_ACCESS_FS_TRUNCATE should always go hand in hand with LANDLOCK_ACCESS_FS_WRITE_FILE, as their meanings and enforcement overlap in counterintuitive ways. On many common file systems, fallocate(2) offers a way to shorten files as long as the file is opened for writing, side-stepping the LANDLOCK_ACCESS_FS_TRUNCATE right. Assisted-by: Gemini-CLI:gemini-3.1 Signed-off-by: Günther Noack <gnoack@google.com> Link: https://lore.kernel.org/r/20260401150911.1038072-1-gnoack@google.com Signed-off-by: Mickaël Salaün <mic@digikod.net>
1 parent d1b2ab2 commit 3457a5c

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

Documentation/userspace-api/landlock.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,8 @@ Truncating files
383383

384384
The operations covered by ``LANDLOCK_ACCESS_FS_WRITE_FILE`` and
385385
``LANDLOCK_ACCESS_FS_TRUNCATE`` both change the contents of a file and sometimes
386-
overlap in non-intuitive ways. It is recommended to always specify both of
387-
these together.
386+
overlap in non-intuitive ways. It is strongly recommended to always specify
387+
both of these together (either granting both, or granting none).
388388

389389
A particularly surprising example is :manpage:`creat(2)`. The name suggests
390390
that this system call requires the rights to create and write files. However,
@@ -396,6 +396,10 @@ It should also be noted that truncating files does not require the
396396
system call, this can also be done through :manpage:`open(2)` with the flags
397397
``O_RDONLY | O_TRUNC``.
398398

399+
At the same time, on some filesystems, :manpage:`fallocate(2)` offers a way to
400+
shorten file contents with ``FALLOC_FL_COLLAPSE_RANGE`` when the file is opened
401+
for writing, sidestepping the ``LANDLOCK_ACCESS_FS_TRUNCATE`` right.
402+
399403
The truncate right is associated with the opened file (see below).
400404

401405
Rights associated with file descriptors

0 commit comments

Comments
 (0)