landlock bug: procfs denials because inodes have unstable identity
Christian Brauner
brauner at kernel.org
Wed Nov 11 11:50:19 UTC 2026
On Thu, Nov 05, 2026 at 10:34:02PM +0100, Mickaël Salaün wrote:
> On Wed, Nov 04, 2026 at 08:47:14PM +0100, Jann Horn wrote:
> > On Fri, Oct 30, 2026 at 4:45 PM Günther Noack <gnoack at google.com> 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.
>
> I don't understand why it could help to have a weak mapping between
> inode and a path while the inode is still referenced.
It simplifies the implementation as Jann quite a bit.
> Christian, what do you think would be possible?
I think anything that request changes to how procfs lookup handles needs
to proof that a) it is a general improvement and b) that it doesn't
impact performance meaningfully.
Even if you make use of the 64-bit pidfd inode number in struct pid
you'd have to have a lookup data structure. And that will cost no matter
how you spin it and in general we're not very forthcoming when it comes
to degrading subsystem performance for special-purpose consumers.
> > > 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/
> > > [2] https://lore.kernel.org/all/cover.1756935780.git.m@maowtm.org/
> > >
> > >
> > > 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
Meh, there's 1775 sysctls on my system alone. Making them permanent
means they remain pinned and waste memory. kernfs avoids that because it
pins kernfs nodes which is 136 bytes. An inode is about 650 bytes. If
you pin all of then you're already wasting 1MB. Why do you want to make
Ram Altman unhappy?
> > something like that?
>
> I agree, it would be useful (and it has been requested) to properly handle
> procfs. I think the "scope" interface would make sense to access
> process/thread-related resources. Other kind of files/directory should
> use the current path_beneath mechanism, and I'm wondering if identifying
> these kind of files is already reliable (vs the process-related files).
>
> >
> > > —Günther
> > >
> > >
> > >
> > > Reproducer program, for easier reproduction (don't forget to drop
> > > caches in parallel):
> > [...]
> >
>
--
More information about the Linux-security-module-archive
mailing list