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=1796380843; b=WKRKry5RS22sQ741XpdZkvD4E9IBaSScRQUf4REEmR6L1aX0J8qdj9f50QYMrPtiN5wu d1tpfPBBG1wiyYCwDdw2wmMKaUmuk47V1T/BOxi3aTvzRhyqzKpEdkg1mFpTh2/hfJMYk Gq5TWVbWTvKLK5vQy5bhwpz1mNbi7+Rn6lpBXrEhkh9WyyuYYG2dGUrcnlX0NaEkl/02I ORg+YAH0tdBPJFALhenvZXHl/RJLkkc2OYTFsqFMiqFJrU5U021mx3t6td5AthPohed4D b4j3u4TPXlglJdaX6Ek22hxxYhy21jCJBDUsdwtaY9txpbd0yT7mtYYNqUXigw9lhhg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380843; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=hcRnDZrSGx0+9yR5tPSbe5T81hIIHDMIwgkNEdlzRlI=; b=5HurBB19U+aVfR8Lve90s9pHxtRVAFdSEfOFVHnNbxw5S2fqPPufNRC1Wv+8DVoEsIcG 2UTTO/U89luHi0Ge6GGJ67qBV769S+H64zQEagVsYQc3vl6gTeLrK4VoWmF3KjSjqkJyB yH6CbKnVbLWfGGr/6L3yGB6hM886Vk/+5EWxKsetMwdM/+kJXDnOMOVTXg05ipv5W7GIx DOkQD/Ml1QWw8iAvj+s/+BhBSkg1LB/4105teqZT1n4oM6PqMZtIKY2lMZdJZkNAC/riv gbfvJYVEhXvN7WIPFhLdVsO3q4xG3yAo//Tg+pojzv0Ma72qttVzqsOktFfq99YNOlQ== 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=n6G5YCIF; 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 D362B606A322; Fri, 4 Dec 2026 10:40:43 +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=n6G5YCIF Received: by smtp.kernel.org (Postfix) with ESMTPSA id 554621F000C2; Fri, 4 Dec 2026 10:40:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380843; bh=hcRnDZrSGx0+9yR5tPSbe5T81hIIHDMIwgkNEdlzRlI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=n6G5YCIFVAqx9hRZKryso/sctas4RPOV2HllHKvYJMQaqRP1psoPbV11bZoKYvxde j2plDdxIz18+VeAe4df9PJC/Ioou1BT4DxLA/2ppmq+z2nynImb51AIIGHV9mwrp/x IV+gJjlowIH6xWWXYCaoaEl03K2PPbRLtDqg/kU0= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Christian Brauner , =?UTF-8?q?G=C3=BCnther=20Noack?= , James Morris , John Johansen , KP Singh , Matt Bobrowski , Paul Moore , Serge Hallyn , Stephen Smalley , "Serge Hallyn (AMD)" , =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= Subject: [PATCH 7.3 449/742] capabilities: Check PR_SET_SECUREBITS with ns_capable() Date: Fri, 4 Dec 2026 19:05:13 +0900 Message-ID: <20261204100647.083479873@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev 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 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Mickaël Salaün commit 2ff5a29db0f542226d5bd029459de9703fc2a2ae upstream. 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 Signed-off-by: Greg Kroah-Hartman --- security/commoncap.c | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) --- a/security/commoncap.c +++ b/security/commoncap.c @@ -1283,6 +1283,26 @@ static int cap_prctl_drop(unsigned long 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 /* 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)