From: "Günther Noack" <gnoack@google.com>
To: "Mickaël Salaün" <mic@digikod.net>
Cc: 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 3/5] selftests/landlock: Add tests for whiteout object creation
Date: Fri, 31 Jul 2026 16:18:25 +0200 [thread overview]
Message-ID: <amyusSlNoIHj2cEF@google.com> (raw)
In-Reply-To: <20260731.ichi2taiQuuc@digikod.net>
On Fri, Jul 31, 2026 at 03:22:40PM +0200, Mickaël Salaün wrote:
> On Fri, Jul 24, 2026 at 06:10:02PM +0200, Günther Noack wrote:
> > Add a test to check that whiteout object creation is guarded by
> > LANDLOCK_ACCESS_FS_MAKE_REG, in the cases where these are created from
> > userspace:
> >
> > * Conventional creation with mknod()
> > * Linking or renaming an existing whiteout object
> > * renameat2() with RENAME_WHITEOUT,
> > which creates a new whiteout object in the source location
> >
> > Signed-off-by: Günther Noack <gnoack@google.com>
> > ---
> > tools/testing/selftests/landlock/fs_test.c | 22 ++++++++++++++++++++++
> > 1 file changed, 22 insertions(+)
> >
> > diff --git a/tools/testing/selftests/landlock/fs_test.c b/tools/testing/selftests/landlock/fs_test.c
> > index e82b56a74c5f..fe5faeca83eb 100644
> > --- a/tools/testing/selftests/landlock/fs_test.c
> > +++ b/tools/testing/selftests/landlock/fs_test.c
> > @@ -2247,6 +2247,19 @@ TEST_F_FORK(layout1, rename_file)
> > RENAME_EXCHANGE));
> > }
> >
> > +TEST_F_FORK(layout1, rename_whiteout_denied)
> > +{
> > + enforce_fs(_metadata, LANDLOCK_ACCESS_FS_MAKE_REG, NULL);
> > +
> > + /*
> > + * Try to rename a file with RENAME_WHITEOUT.
> > + * file1_s3d3 is in dir_s3d2 (tmpfs), so it supports RENAME_WHITEOUT.
> > + */
> > + EXPECT_EQ(-1, renameat2(AT_FDCWD, file1_s3d3, AT_FDCWD,
> > + TMP_DIR "/s3d1/s3d2/s3d3/f2", RENAME_WHITEOUT));
> > + EXPECT_EQ(EACCES, errno);
> > +}
>
> rename_whiteout_denied could not fail. It moves a regular file, whose
> own creation already requires MAKE_REG, and a same-directory rename
> merges both parent directories' requirements, so its EACCES came from
> the moved file and not from the whiteout: it passes unchanged with the
> whiteout checks removed from fs.c . Moving a named pipe with MAKE_FIFO
> granted leaves MAKE_REG required for the whiteout alone.
Good catch -- renaming a FIFO makes this test more useful. Fixed (and double
checked by breaking the implementation, to see that it gets caught).
> Four cases are then unexercised, each covering something a bug could
> have broken silently:
>
> - allowing RENAME_WHITEOUT where MAKE_REG is granted, since a check that
> denied unconditionally would have passed the denial test;
>
> - reparenting, since a same-directory rename merges both parents and so
> cannot show that the whiteout is charged to the source directory;
>
> - the audit record, since the denial now reports fs.make_reg where it
> used to report fs.make_char, and nothing pinned which;
>
> - RENAME_EXCHANGE of an existing whiteout, the only operation needing
> that right in the source directory, and the case that shows the
> reclassification covers moving a whiteout and not only creating one.
(Note to self, I still need to look into these)
- needs a rename_whiteout_allowed or similar check
- by testing reparenting, the test can check in which of the two directories
MAKE_REG is allowed
- updated audit test for whiteouts
- rename_exchange case -- maybe double check whether this should be tested
in test_make_file() in a generic way?
> > +
> > TEST_F_FORK(layout1, rename_dir)
> > {
> > const struct rule rules[] = {
> > @@ -3270,6 +3283,14 @@ TEST_F_FORK(layout1, make_char)
> > makedev(1, 3));
> > }
> >
> > +TEST_F_FORK(layout1, make_whiteout)
> > +{
> > + /* Creates a whiteout object (creation guarded by MAKE_REG). */
> > + set_cap(_metadata, CAP_MKNOD);
>
> CAP_MKNOD was never needed for whiteout.
Done.
—Günther
next prev parent reply other threads:[~2026-07-31 14:18 UTC|newest]
Thread overview: 15+ 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 [this message]
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-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=amyusSlNoIHj2cEF@google.com \
--to=gnoack@google.com \
--cc=amir73il@gmail.com \
--cc=brauner@kernel.org \
--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