From: "Mickaël Salaün" <mic@digikod.net>
To: "Günther Noack" <gnoack@google.com>
Cc: Ada Smith <adasmithgt@gmail.com>,
Hungyu Lin <dennylin0707@gmail.com>,
James Morris <jmorris@namei.org>,
Josef Bacik <josef@toxicpanda.com>,
Paul Moore <paul@paul-moore.com>,
Serge Hallyn <serge@hallyn.com>,
Serge Hallyn <sergeh@kernel.org>,
kernel-team@cloudflare.com, linux-kernel@vger.kernel.org,
linux-security-module@vger.kernel.org
Subject: Re: [PATCH v2 3/6] landlock: Mediate CAP_SETPCAP for inheritable capabilities
Date: Wed, 18 Nov 2026 18:01:22 +0100 [thread overview]
Message-ID: <20261118.noo1uNoh7vey@digikod.net> (raw)
In-Reply-To: <avx1r36MHsxhAzSf@google.com>
On Tue, Nov 17, 2026 at 04:41:35PM +0100, Günther Noack wrote:
> On Tue, Nov 17, 2026 at 11:11:53AM +0100, Mickaël Salaün wrote:
> > A process in a domain that denies CAP_SETPCAP could still add
> > capabilities outside of its permitted set to its inheritable set with
> > capset(2), if it held CAP_SETPCAP. cap_capset() checks CAP_SETPCAP with
> > cap_capable() in cap_inh_is_capped(), so the check never reaches
> > hook_capable(). Through file inheritable capabilities, such a set can
> > grant new permitted capabilities on execve() when no_new_privs is not
> > set, which is possible for a domain enforced by a task holding
> > CAP_SYS_ADMIN.
> >
> > Add a Landlock capset hook that checks CAP_SETPCAP against the domain
> > under the same condition as cap_capset(). As with the mmap_addr hook,
> > LSMs implement their own policy in this hook: SELinux checks capset with
> > its own permission.
> >
> > Cc: Günther Noack <gnoack@google.com>
> > Cc: Paul Moore <paul@paul-moore.com>
> > Cc: Serge Hallyn <serge@hallyn.com>
> > Acked-by: Serge Hallyn (AMD) <sergeh@kernel.org>
> > Fixes: 97c8386f1d74 ("landlock: Enforce capability restrictions")
> > Signed-off-by: Mickaël Salaün <mic@digikod.net>
> > ---
> >
> > Changes since v1:
> > https://patch.msgid.link/20261110202436.2408244-4-mic@digikod.net
> > - Add Serge Hallyn's Acked-by.
> > ---
> > security/landlock/cap.c | 30 ++++++++++++++++++++++++++++++
> > 1 file changed, 30 insertions(+)
> >
> > diff --git a/security/landlock/cap.c b/security/landlock/cap.c
> > index 10e1ca772b9c..c89e8d76db8c 100644
> > --- a/security/landlock/cap.c
> > +++ b/security/landlock/cap.c
> > @@ -91,6 +91,35 @@ static int hook_capable(const struct cred *cred, struct user_namespace *ns,
> > return check_cap(cred, cap, opts);
> > }
> >
> > +/**
> > + * hook_capset - Restrict inheritable capability changes
> > + *
> > + * @new: New credentials (unused).
> > + * @old: Current credentials.
> > + * @effective: New effective set (unused).
> > + * @inheritable: New inheritable set.
> > + * @permitted: New permitted set (unused).
> > + *
> > + * cap_capset() requires CAP_SETPCAP to add inheritable capabilities that are
> > + * not in the old permitted set, but calls cap_capable() directly, which skips
> > + * hook_capable().
>
> It has taken me a bit of time to wrap my head around this one.
>
> cap_capset() starts with:
>
> if (cap_inh_is_capped() &&
> !cap_issubset(*inheritable,
> cap_combine(old->cap_inheritable,
> old->cap_permitted)))
> /* incapable of using this inheritable set */
> return -EPERM;
>
> where cap_inh_is_capped() returns true if it does *not* have CAP_SETPCAP.
>
> So when this Landlock hooks gets called, cap_capset() has already
> checked that we either have CAP_SETPCAP or inheritable ⊆
> (old->inheritable ⋃ old->permitted). So the Landlock hook can check
> for the cap_issubset(...) condition to see whether CAP_SETPCAP had to
> be "used".
>
> Maybe it would be easier to phrase it like that?
>
>
> (A more specific nit about this comment, "calls cap_capable()
> *directly*" has confused me a bit, since cap_capset() calls
> cap_capable() only *indirectly* through cap_inh_is_capped(). Maybe
> "promptly", or "immediately" would be better?)
I agree, the v3 should address your concerns.
>
> > Check the same condition against the domain. commoncap runs
> > + * first, so this only sees requests that commoncap allowed. capset(2) discards
> > + * @new if this hook fails, so nothing is committed.
> > + *
> > + * Return: 0 if allowed, -EPERM if CAP_SETPCAP use is denied.
> > + */
> > +static int hook_capset(struct cred *new, const struct cred *old,
> > + const kernel_cap_t *effective,
> > + const kernel_cap_t *inheritable,
> > + const kernel_cap_t *permitted)
> > +{
> > + if (cap_issubset(*inheritable,
> > + cap_combine(old->cap_inheritable, old->cap_permitted)))
> > + return 0;
> > +
> > + return check_cap(old, CAP_SETPCAP, CAP_OPT_NONE);
> > +}
> > +
> > /**
> > * hook_mmap_addr - Restrict mappings below dac_mmap_min_addr
> > *
> > @@ -113,6 +142,7 @@ static int hook_mmap_addr(unsigned long addr)
> >
> > static struct security_hook_list landlock_hooks[] __ro_after_init = {
> > LSM_HOOK_INIT(capable, hook_capable),
> > + LSM_HOOK_INIT(capset, hook_capset),
> > LSM_HOOK_INIT(mmap_addr, hook_mmap_addr),
> > };
> >
> > --
> > 2.56.0
> >
>
> Reviewed-by: Günther Noack <gnoack@google.com>
>
> Code checks out, only minor comments about the documentation. It has
> taken me a bit to understand how the Landlock hook's logic matches the
> one in cap_capset().
>
> —Günther
next prev parent reply other threads:[~2026-11-18 17:01 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 10:11 [PATCH v2 0/6] Fix Landlock mediation of commoncap's capability checks Mickaël Salaün
2026-11-17 10:11 ` [PATCH v2 1/6] landlock: Factor out capability denial checks Mickaël Salaün
2026-11-17 13:56 ` Günther Noack
2026-11-17 10:11 ` [PATCH v2 2/6] landlock: Mediate CAP_SYS_RAWIO for mappings below mmap_min_addr Mickaël Salaün
2026-11-17 14:23 ` Günther Noack
2026-11-18 17:00 ` Mickaël Salaün
2026-11-17 10:11 ` [PATCH v2 3/6] landlock: Mediate CAP_SETPCAP for inheritable capabilities Mickaël Salaün
2026-11-17 15:41 ` Günther Noack
2026-11-18 17:01 ` Mickaël Salaün [this message]
2026-11-17 10:11 ` [PATCH v2 4/6] landlock: Mediate CAP_SYS_ADMIN for the admin memory reserve Mickaël Salaün
2026-11-17 15:43 ` Günther Noack
2026-11-17 10:11 ` [PATCH v2 5/6] selftests/landlock: Test capability checks outside the capable hook Mickaël Salaün
2026-11-17 16:11 ` Günther Noack
2026-11-18 17:11 ` Mickaël Salaün
2026-11-17 10:11 ` [PATCH v2 6/6] landlock: Fix capability restriction documentation Mickaël Salaün
2026-11-17 16:25 ` Günther Noack
2026-11-18 17:11 ` Mickaël Salaün
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=20261118.noo1uNoh7vey@digikod.net \
--to=mic@digikod.net \
--cc=adasmithgt@gmail.com \
--cc=dennylin0707@gmail.com \
--cc=gnoack@google.com \
--cc=jmorris@namei.org \
--cc=josef@toxicpanda.com \
--cc=kernel-team@cloudflare.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=paul@paul-moore.com \
--cc=serge@hallyn.com \
--cc=sergeh@kernel.org \
/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
all inboxes | Powered by JetHome®