On Fri, Oct 30, 2026 at 4:45 PM Günther Noack [off-list ref] wrote:
The Landlock LSM lets processes define policies which are attached to
struct inode objects internally. As a consequence, if filesystems
forget these inodes and start using new inode objects for the same
files or directories later on, these policies do not work as intended
any more.
As it turns out, procfs has that property as well and can lose inode
identities over time, even though it does not happen immediately.
Right; basically, dentries can be dropped from caches while the
corresponding inodes still exist. In normal filesystems, dentry lookup
rediscovers already-existing inodes, but procfs calls new_inode() for
non-persistent dentries from several places without checking whether
an equivalent inode already exists, which works because procfs doesn't
really tie any state to inodes. new_inode() is called from these
places for non-persistent dentries:
- proc_pid_make_inode
- proc_get_inode
- proc_sys_make_inode
File systems that care about having something like a 1:1 relationship
between an inode and the object it refers to can instead use
mechanisms like path_from_stashed() or iget_locked().
In my understanding, this is not intended. Landlock has explicit
selftests to exercise that Landlock policies work in Procfs.
I think from the procfs perspective, it's currently an intentional
design choice that simplifies procfs implementation.
For reference, similar issues have been investigated also for hostfs
[1] and 9p [2]:
[1] https://lore.kernel.org/all/20230309165455.175131-2-mic@digikod.net/ (local)
[2] https://lore.kernel.org/all/cover.1756935780.git.m@maowtm.org/ (local)
Steps to reproduce
==================
Process A:
* Enter a Landlock domain where access to /proc/sys/kernel/random
(and files below it) is allowed.
* Repeatedly open and close the boot_id file from that same directory
At the same time, the dentry caches get freed up.
We can emulate this by writing to /proc/sys/vm/drop_caches from
another (root) process:
# echo 2 > /proc/sys/vm/drop_caches
Observed result: Process A fails because of a Landlock refusal opening
the boot_id file. When Landlock walks the path for the check, the
inodes have now a different identity than before and don't match, so
Landlock denies the operation.
Expected result: Dropping the caches should not affect Landlock's
behaviour.
At the bottom of this email, I am including the source code for a
program that does Process A -- you can run this to reproduce, and then
write into the drop_caches file from another process as root.
Solution...?
============
I don't have a fix for it yet.
I am open to suggestions. Is this feasible to change in procfs?
A landlock domain is supposed to be usable for a hierarchy of multiple
processes, and for that usecase, if all those processes want a working
/proc/self, landlock currently can't meaningfully restrict procfs
beyond what is done implicitly through ptrace access checks, right? I
think if there is a desire to have fine-grained landlock policies for
procfs, that would first require some design decisions on how procfs
peculiarities like per-process directories should be handled.
I imagine one option would be to add a mechanism that automatically
grants full access to {procfs mount}/$pid of all in-domain pids, and
then consider whether sysctls should have persistent dentries or
something like that?
—Günther
Reproducer program, for easier reproduction (don't forget to drop
caches in parallel):
[...]