From: "Serge E. Hallyn" <serge@hallyn.com>
To: gregkh@linuxfoundation.org
Cc: mic@digikod.net, brauner@kernel.org, gnoack@google.com,
jmorris@namei.org, john.johansen@canonical.com,
kpsingh@kernel.org, matt@bobrowski.net, paul@paul-moore.com,
sergeh@kernel.org, stephen.smalley.work@gmail.com,
stable@vger.kernel.org
Subject: Re: FAILED: patch "[PATCH] capabilities: Check PR_SET_SECUREBITS with ns_capable()" failed to apply to 6.6-stable tree
Date: Wed, 2 Dec 2026 09:25:37 -0600 [thread overview]
Message-ID: <axA4cUecKrtHzg7r@hallyn.com> (raw)
In-Reply-To: <2026120222-aspirin-anyplace-2c7d@gregkh>
On Wed, Dec 02, 2026 at 01:59:22PM +0100, gregkh@linuxfoundation.org wrote:
>
> The patch below does not apply to the 6.6-stable tree.
> If someone wants it applied there, or to any other stable or longterm
> tree, then please email the backport, including the original git commit
> id to <stable@vger.kernel.org>.
Hm, yeah, Mickaël, is this really needed for stable?
> To reproduce the conflict and resubmit, you may use the following commands:
>
> git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.6.y
> git checkout FETCH_HEAD
> git cherry-pick -x 2ff5a29db0f542226d5bd029459de9703fc2a2ae
> # <resolve conflicts, build, test, etc.>
> git commit -s
> git send-email --to '<stable@vger.kernel.org>' --in-reply-to '2026120222-aspirin-anyplace-2c7d@gregkh' --subject-prefix 'PATCH 6.6.y' 'HEAD^..'
>
> Possible dependencies:
>
>
>
> thanks,
>
> greg k-h
>
> ------------------ original commit in Linus's tree ------------------
>
> >From 2ff5a29db0f542226d5bd029459de9703fc2a2ae Mon Sep 17 00:00:00 2001
> From: =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= <mic@digikod.net>
> Date: Wed, 18 Nov 2026 15:54:28 +0100
> Subject: [PATCH] capabilities: Check PR_SET_SECUREBITS with ns_capable()
> MIME-Version: 1.0
> Content-Type: text/plain; charset=UTF-8
> Content-Transfer-Encoding: 8bit
>
> PR_SET_SECUREBITS checks CAP_SETPCAP with cap_capable(), which skips the
> LSM capable hooks, so a task can change privileged securebits despite an
> LSM denial.
>
> Use ns_capable() instead, as PR_CAPBSET_DROP already does. Move the
> check to a helper that only requires CAP_SETPCAP when needed, so that
> changes limited to the unprivileged securebits still do not reach the
> LSMs or set PF_SUPERPRIV.
>
> Cc: Christian Brauner <brauner@kernel.org>
> Cc: Günther Noack <gnoack@google.com>
> Cc: James Morris <jmorris@namei.org>
> Cc: John Johansen <john.johansen@canonical.com>
> Cc: KP Singh <kpsingh@kernel.org>
> Cc: Matt Bobrowski <matt@bobrowski.net>
> Cc: Paul Moore <paul@paul-moore.com>
> Cc: Serge Hallyn <serge@hallyn.com>
> Cc: Stephen Smalley <stephen.smalley.work@gmail.com>
> Cc: stable@vger.kernel.org
> Reviewed-by: Serge Hallyn (AMD) <sergeh@kernel.org>
> Fixes: 3898b1b4ebff ("capabilities: implement per-process securebits")
> Link: https://patch.msgid.link/20261118145431.2551578-2-mic@digikod.net
> Signed-off-by: Mickaël Salaün <mic@digikod.net>
>
> diff --git a/security/commoncap.c b/security/commoncap.c
> index d47ab3022343..9794a594bdd9 100644
> --- a/security/commoncap.c
> +++ b/security/commoncap.c
> @@ -1283,6 +1283,26 @@ static int cap_prctl_drop(unsigned long cap)
> return commit_creds(new);
> }
>
> +/*
> + * Doing anything with securebits requires privilege (go read about the
> + * "sendmail capabilities bug"), except for unprivileged bits. Indeed, the
> + * SECURE_ALL_UNPRIVILEGED bits are not restrictions enforced by the kernel but
> + * by user space on itself. Only checking CAP_SETPCAP when it is needed keeps
> + * LSMs from seeing (and logging) a capability check for unprivileged changes.
> + */
> +static bool securebits_need_setpcap(unsigned long old, unsigned long new)
> +{
> + const unsigned long unpriv_and_locks = SECURE_ALL_UNPRIVILEGED |
> + SECURE_ALL_UNPRIVILEGED << 1;
> + const unsigned long changed = old ^ new;
> +
> + /* For legacy reasons, a non-change requires privilege. */
> + if (!changed)
> + return true;
> +
> + return changed & ~unpriv_and_locks;
> +}
> +
> /**
> * cap_task_prctl - Implement process control functions for this security module
> * @option: The process control function requested
> @@ -1346,28 +1366,9 @@ int cap_task_prctl(int option, unsigned long arg2, unsigned long arg3,
> /* cannot change a locked bit */
> return -EPERM;
>
> - /*
> - * Doing anything requires privilege (go read about the
> - * "sendmail capabilities bug"), except for unprivileged bits.
> - * Indeed, the SECURE_ALL_UNPRIVILEGED bits are not
> - * restrictions enforced by the kernel but by user space on
> - * itself.
> - */
> - if (cap_capable(current_cred(), current_cred()->user_ns,
> - CAP_SETPCAP, CAP_OPT_NONE) != 0) {
> - const unsigned long unpriv_and_locks =
> - SECURE_ALL_UNPRIVILEGED |
> - SECURE_ALL_UNPRIVILEGED << 1;
> - const unsigned long changed = old->securebits ^ arg2;
> -
> - /* For legacy reason, denies non-change. */
> - if (!changed)
> - return -EPERM;
> -
> - /* Denies privileged changes. */
> - if (changed & ~unpriv_and_locks)
> - return -EPERM;
> - }
> + if (securebits_need_setpcap(old->securebits, arg2) &&
> + !ns_capable(current_user_ns(), CAP_SETPCAP))
> + return -EPERM;
>
> new = prepare_creds();
> if (!new)
prev parent reply other threads:[~2026-12-02 15:25 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 12:59 FAILED: patch "[PATCH] capabilities: Check PR_SET_SECUREBITS with ns_capable()" failed to apply to 6.6-stable tree gregkh
2026-12-02 15:25 ` Serge E. Hallyn [this message]
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=axA4cUecKrtHzg7r@hallyn.com \
--to=serge@hallyn.com \
--cc=brauner@kernel.org \
--cc=gnoack@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=jmorris@namei.org \
--cc=john.johansen@canonical.com \
--cc=kpsingh@kernel.org \
--cc=matt@bobrowski.net \
--cc=mic@digikod.net \
--cc=paul@paul-moore.com \
--cc=sergeh@kernel.org \
--cc=stable@vger.kernel.org \
--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