From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796220986; b=153rPwqhB6mNsZeYf0tGKQPJDLS/jI8OH5LOwKpNIzxRg7Uiuw6tgu5yB5RoGCO1LSM3 NjSFUKu3tseer0Ih1+gOk7+8TUG6Xndh3XzRgBD2bJDc9bDhHlxH22HRFg+Hpys/WYuCr +4nkcQSQP5kCdFwM/rdKyVi/htKLasUVusFZWlFXlxj4NkQlOUrgP3oLOgLcNPOkuw+sY BUwrPf7lZB9gFaso6zGqopk6zcOnrDEyc6fRNTCETsWLfjsP2QDxZWTf+AxxeHgKBl7GI bR2jCmr/VEyOIVPjOdlNMzLi7LU2LLZyIvi3DMpidhIUik6ZEWRxyM5hwK0wH1i35jw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796220986; h=Received:DKIM-Signature:Subject:To:Cc:From:Date:Message-ID: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=Yt4W7GWV2EHQaNI3qM8EUgKMjOst0vvp9E7JRNnnAjI=; b=Jp7foBbi8ZmxL8QcCU9RPqwQw38XeWyv78i1tinWHsYFbel+3oSG75OpHMn0zUiXdlFC Nh5lOzTQSZPylRWl9aV9F0wthJPppd4tEYCfwkXS6Ot1UnI3fUnMLsNLGio6rVCEH0ml4 07qZbfzbVe5Pore6UxhFSqY0OLJyVCylk51hLS63FEMkG6bslEyosPHqdMDoUXKzvbrIr Ec1mZ+YVKXSzNG0nSo6yrTFLM0lVcBvqby2yd+CyQBL3BHiZN4638XzlRxop2PIcHLGLN xtvFTGQEuyi6vnIE6pGKN8xE27brCQfD1zWyOk5+dgyda20yHyY2SEyg/zWC3RkWOhA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=T0Jq+f14; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5E5CD606A31A for ; Wed, 2 Dec 2026 14:16:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=T0Jq+f14 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 97D541F000C1; Wed, 2 Dec 2026 14:16:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796220986; bh=Yt4W7GWV2EHQaNI3qM8EUgKMjOst0vvp9E7JRNnnAjI=; h=Subject:To:Cc:From:Date; b=T0Jq+f14dZn4CjHZUMoP2QtaueSpLCH0jlPrLTUmARDHM6iO7UHz3+wyMhE7N2Isw SyMf3dV6sKhXmWPFpGi+mgUYZr0gpYyXZ6KHoFbOjUbqbgPNC1Vtp76VYp4wC3pM8U NyRWifj6Lme2Lo03zpiOjV0oXlx13t6Y3Y7lNMOU= Subject: FAILED: patch "[PATCH] capabilities: Check PR_SET_SECUREBITS with ns_capable()" failed to apply to 6.1-stable tree To: 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,serge@hallyn.com,sergeh@kernel.org,stephen.smalley.work@gmail.com Cc: From: Date: Wed, 02 Dec 2026 13:59:23 +0100 Message-ID: <2026120223-luckless-ultimate-6db0@gregkh> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The patch below does not apply to the 6.1-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 . 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.1.y git checkout FETCH_HEAD git cherry-pick -x 2ff5a29db0f542226d5bd029459de9703fc2a2ae # git commit -s git send-email --to '' --in-reply-to '2026120223-luckless-ultimate-6db0@gregkh' --subject-prefix 'PATCH 6.1.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?= 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 Cc: Günther Noack Cc: James Morris Cc: John Johansen Cc: KP Singh Cc: Matt Bobrowski Cc: Paul Moore Cc: Serge Hallyn Cc: Stephen Smalley Cc: stable@vger.kernel.org Reviewed-by: Serge Hallyn (AMD) 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 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)