From: "Günther Noack" <gnoack3000@gmail.com>
To: "Mickaël Salaün" <mic@digikod.net>
Cc: "Günther Noack" <gnoack@google.com>,
"Christian Brauner" <brauner@kernel.org>,
linux-security-module@vger.kernel.org,
"Paul Moore" <paul@paul-moore.com>,
"Amir Goldstein" <amir73il@gmail.com>,
"Miklos Szeredi" <miklos@szeredi.hu>,
"Serge Hallyn" <serge@hallyn.com>,
"Stephen Smalley" <stephen.smalley.work@gmail.com>
Subject: Re: [PATCH v4 4/5] selftests/landlock: Test whiteout object behaviour in OverlayFS renames
Date: Wed, 12 Aug 2026 22:18:22 +0200 [thread overview]
Message-ID: <20260812.ed47cbfa7bb0@gnoack.org> (raw)
In-Reply-To: <20260731.IeC9Eih4chie@digikod.net>
On Fri, Jul 31, 2026 at 03:43:24PM +0200, Mickaël Salaün wrote:
> On Fri, Jul 24, 2026 at 06:10:03PM +0200, Günther Noack wrote:
> > Even though OverlayFS uses vfs_rename() with RENAME_WHITEOUT, and even
> > though RENAME_WHITEOUT requires LANDLOCK_ACCESS_FS_MAKE_REG, a process that
> > renames non-regular files in an OverlayFS can do so without having the
> > LANDLOCK_ACCESS_FS_MAKE_REG right in that location.
> >
> > This works, and is supposed to work, because OverlayFS uses the credentials
> > determined at mount time for the internal vfs_rename() operation. -- The
>
> This "--" doesn't seem useful.
Reworded this and removed the "--"
(The paragraph was previously slightly misleading - vfs_rename() is
used by OverlayFS, but does not actually call into the Landlock rename
hook, so the credentials at the time of OverlayFS mount do not matter
for the in-kernel OverlayFS. So the old paragraph was a bit
misleading, but the larger point still applies - the operations done
by OverlayFS on the underlying upper and lower file systems are not
subject to the Landlock policy of the userspace process that triggered
the operation through an operation on the unified OverlayFS file
system.)
>
> > rename happens with the credentials of the user who mounted the OverlayFS.
> >
> > Signed-off-by: Günther Noack <gnoack@google.com>
> > ---
> > tools/testing/selftests/landlock/fs_test.c | 39 ++++++++++++++++++++++
> > 1 file changed, 39 insertions(+)
> >
> > diff --git a/tools/testing/selftests/landlock/fs_test.c b/tools/testing/selftests/landlock/fs_test.c
> > index fe5faeca83eb..73770dbb0592 100644
> > --- a/tools/testing/selftests/landlock/fs_test.c
> > +++ b/tools/testing/selftests/landlock/fs_test.c
> > @@ -6972,6 +6972,45 @@ TEST_F_FORK(layout2_overlay, same_content_different_file)
> > }
> > }
> >
> > +TEST_F_FORK(layout2_overlay, rename_in_overlay_without_make_reg)
> > +{
> > + struct stat st;
> > + const char *merge_fl1_renamed = MERGE_DATA "/fl1_renamed";
> > +
> > + if (self->skip_test)
> > + SKIP(return, "overlayfs is not supported (test)");
> > +
> > + /*
> > + * In this test, merge_fl1 is a FIFO file. MAKE_REG is restricted, but
> > + * MAKE_FIFO is allowed. Despite MAKE_REG being restricted, the rename
> > + * on the OverlayFS works and creates a whiteout file in the underlying
> > + * upper file system.
> > + */
> > + ASSERT_EQ(0, unlink(merge_fl1));
>
> merge_fl1 just became a whiteout with this unlink, so I think the test
> is wrong because it doesn't check RENAME_WHITEOUT against the lower file.
OK, changed to this approach:
* Creating a FIFO at lower/data/pl1 as part of the fixture
(For well-defined behaviour, this needs to happen before mounting
the OverlayFS, according to Documentation/filesystems/overlayfs.rst,
section "Changes to underlying filesystems")
Now, as usual:
* Do a rename from merge_pl1 to merge_pl1_renamed. Because the
original FIFO came from the lower layer, and modifications through
OverlayFS take effect on the upper layer, this creates the whiteout
in the upper layer to hide the FIFO in the lower layer.
I also started using is_whiteout() and is_missing() helpers to avoid
the repeated stat() dance - it reads a bit closer to the test's intent
that way.
> > + ASSERT_EQ(0, mknod(merge_fl1, S_IFIFO, 0));
>
> The mode should be 0600.
Done.
> > + enforce_fs(_metadata, LANDLOCK_ACCESS_FS_MAKE_REG, NULL);
> > +
> > + /*
> > + * Execute a regular file rename within OverlayFS.
>
> merge_fl1 is a fifo.
Done.
> > + * merge_fl1 originates from lower layer, so this triggers a copy-up
> > + * and creation of a whiteout in the upper layer.
> > + */
> > + EXPECT_EQ(0, rename(merge_fl1, merge_fl1_renamed));
> > +
> > + /* Check that the rename worked. */
> > + EXPECT_EQ(0, stat(merge_fl1_renamed, &st));
> > + EXPECT_EQ(-1, stat(merge_fl1, &st));
> > + EXPECT_EQ(ENOENT, errno);
> > +
> > + /*
> > + * Check that the whiteout object on the underlying "upper" filesystem
> > + * exists after the rename. This is OK because it was done with the
> > + * credentials of the OverlayFS.
> > + */
> > + EXPECT_EQ(0, stat(UPPER_DATA "/fl1", &st));
> > + EXPECT_TRUE(S_ISCHR(st.st_mode));
> > + EXPECT_EQ(0, st.st_rdev);
> > +}
> >
> > FIXTURE(layout3_fs)
> > {
> > --
> > 2.55.0.229.g6434b31f56-goog
> >
> >
next prev parent reply other threads:[~2026-08-12 20:18 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-24 16:09 [PATCH v4 0/5] landlock: Restrict whiteout object creation Günther Noack
2026-07-24 16:10 ` [PATCH v4 1/5] selftests/landlock: Use an actual chardev for MAKE_CHAR audit test Günther Noack
2026-07-24 16:10 ` [PATCH v4 2/5] landlock: Require LANDLOCK_ACCESS_FS_MAKE_REG for whiteout creation Günther Noack
2026-07-31 11:07 ` Mickaël Salaün
2026-07-31 13:13 ` Günther Noack
2026-07-31 14:21 ` Günther Noack
2026-07-31 15:14 ` Mickaël Salaün
2026-07-31 13:13 ` Mickaël Salaün
2026-07-31 14:05 ` Günther Noack
2026-07-24 16:10 ` [PATCH v4 3/5] selftests/landlock: Add tests for whiteout object creation Günther Noack
2026-07-31 13:22 ` Mickaël Salaün
2026-07-31 14:18 ` Günther Noack
2026-07-24 16:10 ` [PATCH v4 4/5] selftests/landlock: Test whiteout object behaviour in OverlayFS renames Günther Noack
2026-07-31 13:43 ` Mickaël Salaün
2026-08-12 20:18 ` Günther Noack [this message]
2026-07-24 16:10 ` [PATCH v4 5/5] landlock: Link the erratum documentation for whiteout objects Günther Noack
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=20260812.ed47cbfa7bb0@gnoack.org \
--to=gnoack3000@gmail.com \
--cc=amir73il@gmail.com \
--cc=brauner@kernel.org \
--cc=gnoack@google.com \
--cc=linux-security-module@vger.kernel.org \
--cc=mic@digikod.net \
--cc=miklos@szeredi.hu \
--cc=paul@paul-moore.com \
--cc=serge@hallyn.com \
--cc=stephen.smalley.work@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