Linux Security Modules development
 help / color / mirror / Atom feed
From: "Mickaël Salaün" <mic@digikod.net>
To: Jann Horn <jannh@google.com>, Christian Brauner <brauner@kernel.org>
Cc: "Günther Noack" <gnoack@google.com>,
	linux-security-module@vger.kernel.org,
	linux-fsdevel@vger.kernel.org, "Tingmao Wang" <m@maowtm.org>,
	"Justin Suess" <utilityemal77@gmail.com>
Subject: Re: landlock bug: procfs denials because inodes have unstable identity
Date: Thu, 5 Nov 2026 22:34:02 +0100	[thread overview]
Message-ID: <20261105.gai4OeWungae@digikod.net> (raw)
In-Reply-To: <CAG48ez2e607HNArcX_xA9UTv_u1tvThLwW2kDvnejHcx4A80KA@mail.gmail.com>

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@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.

Christian, what do you think would be possible?

> 
> > 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
> 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):
> [...]
> 

  reply	other threads:[~2026-11-05 21:34 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-30 15:45 landlock bug: procfs denials because inodes have unstable identity Günther Noack
2026-11-04 19:47 ` Jann Horn
2026-11-05 21:34   ` Mickaël Salaün [this message]
2026-11-11 11:50     ` Christian Brauner

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=20261105.gai4OeWungae@digikod.net \
    --to=mic@digikod.net \
    --cc=brauner@kernel.org \
    --cc=gnoack@google.com \
    --cc=jannh@google.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=m@maowtm.org \
    --cc=utilityemal77@gmail.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