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=1796382417; b=2UcwYnkUniqeED3o8TEJAIVvu9AGvTqSTfCzh6zvNZv0FTwz02tLYCtesK6E3OeIKcAH a8laVcWTXuSbcbgYMRE1QkfG1/Vw6k9/EvMrJboC8bN1sKA5Lw/UEMxcc4zVHLi9wS1aY /NFQscjDZ6MhsmtWG6vswuP3FKKAkKkNcdD8STBhAhsHtcG3FFbq5xIJQ7VM9JQahBc6F 0dpOGcDazU5+zM9P+Po+97UB4y09IJTXmRh16NaqUMy9E/kHR9Cmt2YW3E9x3DmCFHroH 93RYNZGMmONJ2bEARUPuhKJWJr+khn08x+d6DivVyrqAIcjf7bQx7Upgle87W2Zvgkw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382417; 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=0h4QU5CWxv5bEhpvX2nSrlKWvjdL++O/P+0a0Fa1eWo=; b=O8nGVPzQ0ZnmyeWwaR4hQnRLoUIwFLt7tBGrEwLucCXjw7mQ+R7dWnJJi4LzsFgrpbkn putmOjD7bCFYNUhCm1m+frus5D0a5YQPnZY2J5mHIwrNz9GIJhdV0zSqe+zoVycSYvh9s 0vuxlR4JcMpuCYNqBpQ4DlXGkjIhcIJdJM5VifwqAKeMSNWMHKLJrlCKjCFidM16kl3nM VFmZNBUvR8sedcUGslfaKcINLye4QCT53T+QZmKhCnxe7ojKCishva/9H3T6yKyy+iWZ/ XYtQiNK+WhiB8LMcW39KVf3dqLqn/z5ijaJ1t94fvo0joEm7U3+sdSm6k+r8Wp9Wczg== 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=Q9Y+wKmU; 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 BEABD606A32D; Fri, 4 Dec 2026 11:06:57 +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=Q9Y+wKmU Received: by smtp.kernel.org (Postfix) with ESMTPSA id 366BA1F0092C; Fri, 4 Dec 2026 11:06:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796382417; bh=0h4QU5CWxv5bEhpvX2nSrlKWvjdL++O/P+0a0Fa1eWo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Q9Y+wKmU8+cvLMydtS0XoDdLDrZnAWs8BG498urTO0IRf9E+b4zTa2HrMd9qoxNBx kJZhKhMkWayBwxc8vRYs9y60g6iMpjG11d+XjZREADeawZb3/zXbJF2jxV5rPXHdfZ 99ffJtssf2BPSdeankq65QEU1fD4u/r44in9uS9w= 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 6.18 408/703] capabilities: Check PR_SET_SECUREBITS with ns_capable() Date: Fri, 4 Dec 2026 19:05:07 +0900 Message-ID: <20261204100638.685719645@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore 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 6.18-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 @@ -1273,6 +1273,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 @@ -1336,28 +1356,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)