* landlock bug: procfs denials because inodes have unstable identity
@ 2026-10-30 15:45 Günther Noack
2026-11-04 19:47 ` Jann Horn
0 siblings, 1 reply; 4+ messages in thread
From: Günther Noack @ 2026-10-30 15:45 UTC (permalink / raw)
To: Mickaël Salaün
Cc: linux-security-module, linux-fsdevel, Tingmao Wang, Justin Suess
Hello!
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.
In my understanding, this is not intended. Landlock has explicit
selftests to exercise that Landlock policies work in Procfs.
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?
—Günther
Reproducer program, for easier reproduction (don't forget to drop
caches in parallel):
---landlock_uuid.c
#define _GNU_SOURCE
#include <err.h>
#include <fcntl.h>
#include <linux/landlock.h>
#include <stddef.h>
#include <sys/prctl.h>
#include <sys/syscall.h>
#include <unistd.h>
static int landlock_create_ruleset(struct landlock_ruleset_attr *attr,
size_t size, __u32 flags)
{
return syscall(__NR_landlock_create_ruleset, attr, size, flags);
}
static int landlock_add_rule(int ruleset_fd, enum landlock_rule_type rule_type,
void *rule_attr, __u32 flags)
{
return syscall(__NR_landlock_add_rule, ruleset_fd, rule_type,
rule_attr, flags);
}
static int landlock_restrict_self(int ruleset_fd, __u32 flags)
{
return syscall(__NR_landlock_restrict_self, ruleset_fd, flags);
}
int main(void)
{
struct landlock_ruleset_attr ruleset_attr = {
.handled_access_fs =
LANDLOCK_ACCESS_FS_EXECUTE |
LANDLOCK_ACCESS_FS_WRITE_FILE |
LANDLOCK_ACCESS_FS_READ_FILE |
LANDLOCK_ACCESS_FS_READ_DIR |
LANDLOCK_ACCESS_FS_REMOVE_DIR |
LANDLOCK_ACCESS_FS_REMOVE_FILE |
LANDLOCK_ACCESS_FS_MAKE_CHAR |
LANDLOCK_ACCESS_FS_MAKE_DIR |
LANDLOCK_ACCESS_FS_MAKE_REG |
LANDLOCK_ACCESS_FS_MAKE_SOCK |
LANDLOCK_ACCESS_FS_MAKE_FIFO |
LANDLOCK_ACCESS_FS_MAKE_BLOCK |
LANDLOCK_ACCESS_FS_MAKE_SYM |
LANDLOCK_ACCESS_FS_REFER |
LANDLOCK_ACCESS_FS_TRUNCATE |
LANDLOCK_ACCESS_FS_IOCTL_DEV |
LANDLOCK_ACCESS_FS_RESOLVE_UNIX,
};
/*
* Backwards compatibility checks omitted for brevity.
* Assuming Linux 7.3 here. :)
*/
int ruleset_fd = landlock_create_ruleset(&ruleset_attr,
sizeof(ruleset_attr), 0);
if (ruleset_fd < 0)
err(1, "landlock_create_ruleset");
int parent_fd = open("/proc/sys/kernel/random", O_PATH | O_CLOEXEC);
if (parent_fd < 0)
err(1, "open(/proc/sys/kernel/random)");
struct landlock_path_beneath_attr path_beneath = {
.allowed_access = LANDLOCK_ACCESS_FS_READ_FILE,
.parent_fd = parent_fd,
};
if (landlock_add_rule(ruleset_fd, LANDLOCK_RULE_PATH_BENEATH,
&path_beneath, 0) < 0)
err(1, "landlock_add_rule");
close(parent_fd);
if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) < 0)
err(1, "prctl(PR_SET_NO_NEW_PRIVS)");
if (landlock_restrict_self(ruleset_fd, 0) < 0)
err(1, "landlock_restrict_self");
close(ruleset_fd);
/* Print out the boot_id file once a second. */
for (;;) {
int fd = open("/proc/sys/kernel/random/boot_id", O_RDONLY);
if (fd < 0)
err(1, "open(/proc/sys/kernel/random/boot_id)");
char buf[64];
ssize_t n;
while ((n = read(fd, buf, sizeof(buf))) > 0) {
if (write(STDOUT_FILENO, buf, n) < 0)
err(1, "write");
}
if (n < 0)
err(1, "read");
close(fd);
sleep(1);
}
return 0;
}
---
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: landlock bug: procfs denials because inodes have unstable identity
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
0 siblings, 1 reply; 4+ messages in thread
From: Jann Horn @ 2026-11-04 19:47 UTC (permalink / raw)
To: Günther Noack
Cc: Mickaël Salaün, linux-security-module, linux-fsdevel,
Tingmao Wang, Justin Suess
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.
> 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?
> —Günther
>
>
>
> Reproducer program, for easier reproduction (don't forget to drop
> caches in parallel):
[...]
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: landlock bug: procfs denials because inodes have unstable identity
2026-11-04 19:47 ` Jann Horn
@ 2026-11-05 21:34 ` Mickaël Salaün
2026-11-11 11:50 ` Christian Brauner
0 siblings, 1 reply; 4+ messages in thread
From: Mickaël Salaün @ 2026-11-05 21:34 UTC (permalink / raw)
To: Jann Horn, Christian Brauner
Cc: Günther Noack, linux-security-module, linux-fsdevel,
Tingmao Wang, Justin Suess
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):
> [...]
>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: landlock bug: procfs denials because inodes have unstable identity
2026-11-05 21:34 ` Mickaël Salaün
@ 2026-11-11 11:50 ` Christian Brauner
0 siblings, 0 replies; 4+ messages in thread
From: Christian Brauner @ 2026-11-11 11:50 UTC (permalink / raw)
To: Mickaël Salaün
Cc: Jann Horn, Günther Noack, linux-security-module,
linux-fsdevel, Tingmao Wang, Justin Suess
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@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):
> > [...]
> >
>
--
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-11 11:50 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2026-11-11 11:50 ` Christian Brauner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox