From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.112 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794325885; b=Z+Inb8hxxIeLquCpq+NkfAO0wm65xVCVFZd9sURF94hGnhpfs2lv1g7suYssN6lqDYsd 8WWxkvrdpVMJK3wxgU7gtKM6JVCNjckl3UVqWMhjtSbVXw9J5ULoCzOf8Omb/intBxHzG 2cmpuRUohEZgMkse32VXJ3oQmzFLQUgxvKXYAWHGa8PHHGwXcdqKZQ9OCaaHVA3kNZEWH hC7jwAbtOZ36EzuzYvCVSLBnB0f9a5ThMcLXa7ywoX8L4KT94t4DF1SyOQXtLldAFJkrI frt6a7vCIPWqvjyeEfO0kKwlf22DL+Mr5i+oJtkC96/ciOULBjEQvfXVACoYHKMV6ng== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794325885; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:Date:From:To:CC:Subject:In-Reply-To: Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding; bh=S+yaxY1IOkbr2hblsylEbiBouEaLkWRredpFXFNGEPs=; b=lDYnp9iNuST3sbcwsChiQAt/0tflPEjWKEzI9+LMNk3iWWuPBtg4+B8rvxT4Btafd8f1 SKyT2L9B0LXKSuxbPu4A7KHTNtixUfhnefgKq/s6kd2TUdaOyt748PguY5Bk8zeeVNO+A OMouqjA7AKP+CLW8sItU5q29n2YSmY+DwLAQst1r7VlVtU+sXPNv2DbLbG96jYx7jjSQz xIuVl9zQN1nj4nZLrV5fF/3hrujx9l+beIwvaiOKFRvEXyQWGCRpGFqerPOaL5Ef9TLuW NNgaX9YAbyJCws3p5J06BxbwrlEXT0gyBw7F6yqKBiuacSLRu2PjaRgEWThV4L+jBMg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=rld116DC; arc=none smtp.remote-ip=91.218.175.112 Received: from mta0.migadu.com (out-112.mta0.migadu.com [91.218.175.112]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 50AD1606A31C for ; Tue, 10 Nov 2026 15:51:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 50AD1606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=rld116DC X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=ekUbTVzeA1JNlzfG7xd+5633WBpvGDfH+mmSDR5DYLM=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1794325882; v=1; x=1794930682; b=rld116DCyefpF4HY6HzebCbZOPxDgtBgxSsjhBvC1bllJIxpyyrQhJq+P+PzvTn4OLH4t74n Mc9IMqMWy0YdoXmgUVTTIjmZC8DOoFaUD6ZduG7QNFZskXgOx/QcJ0nYRCt6F/hu0SpO1Vr+WNN IOz/Hc+sRP6qee1SHukxIaG4= X-Envelope-To: linux-kernel@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id ef20ab98b7ec7150; Tue, 10 Nov 2026 15:51:22 +0000 X-Mizu-Trace-ID: ef20ab98b7ec7150 X-Migadu-Flow: FLOW_OUT Date: Tue, 10 Nov 2026 15:51:18 +0000 From: Bradley Morgan To: mic@digikod.net CC: brads@mainlining.org, brauner@kernel.org, dhowells@redhat.com, jarkko@kernel.org, jmorris@namei.org, josef@toxicpanda.com, keyrings@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, morgan@kernel.org, paul@paul-moore.com, serge@hallyn.com, sergeh@kernel.org, stable@vger.kernel.org Subject: =?US-ASCII?Q?Re=3A_=5BPATCH=5D_userns=3A_Let_LSMs_deny_the_?= =?US-ASCII?Q?CAP=5FSETFCAP_snapshot_for_mapping_uid_0?= In-Reply-To: <20261110144205.2404088-1-mic@digikod.net> Message-ID: <80A558D7-7DC3-4780-91F5-990E4917E8A4@linux.dev> X-Mailing-List: linux-kernel@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 On 10 November 2026 14:42:04 GMT, "Mickaël Salaün" wrote: >Commit db2e718a4798 ("capabilities: require CAP_SETFCAP to map uid 0") >records in parent_could_setfcap whether the creator of a user namespace >had CAP_SETFCAP, because a creator writing its own uid_map only has >capabilities in the new namespace. The snapshot uses cap_raised(), so a >task whose LSM policy denies CAP_SETFCAP can still map uid 0 in a >namespace it creates. > >Use security_capable() against the parent namespace instead: the >creator's credentials still belong to it at this point, so commoncap >returns the same result, and only LSM denials are added. > >Do not audit this check: creating a user namespace does not use >CAP_SETFCAP, and most namespaces never map uid 0. The uid_map write >that later fails has no LSM audit record. > >Checking CAP_SETFCAP when the map is written would not work: the >writer's credentials then belong to the new namespace, where commoncap >grants the creator all capabilities. > >Cc: Christian Brauner >Cc: Josef Bacik >Cc: Paul Moore >Cc: Serge Hallyn Reviewed-by: Bradley Morgan I'm logging out of mainlining.org (sigh) anything meant to be cc'ing me, e.g: get maintainers should cc the linux.dev email instead, annoying brr. >Cc: stable@vger.kernel.org >Fixes: db2e718a4798 ("capabilities: require CAP_SETFCAP to map uid 0") >Signed-off-by: Mickaël Salaün >--- > >This is independent from Josef Bacik's series, which reworks this code >to close other ways around the CAP_SETFCAP rule: >https://patch.msgid.link/20261027-b4-setfcap-userns-v8-0-2674adc63f3c@toxicpanda.com > >That series still computes the creator's CAP_SETFCAP with cap_capable() >and cap_raised() in cap_setfcap_level(), so it would need the same >change. >--- > include/linux/user_namespace.h | 5 +++-- > kernel/user_namespace.c | 8 +++++++- > 2 files changed, 10 insertions(+), 3 deletions(-) > >diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h >index 91232053775d..370961fde45f 100644 >--- a/include/linux/user_namespace.h >+++ b/include/linux/user_namespace.h >@@ -86,8 +86,9 @@ struct user_namespace { > kgid_t group; > struct ns_common ns; > unsigned long flags; >- /* parent_could_setfcap: true if the creator if this ns had CAP_SETFCAP >- * in its effective capability set at the child ns creation time. */ >+ /* parent_could_setfcap: true if the creator of this ns could use >+ * CAP_SETFCAP in the parent ns at the child ns creation time. >+ */ > bool parent_could_setfcap; > > #ifdef CONFIG_KEYS >diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c >index cd748e1cbace..57b7f10be74e 100644 >--- a/kernel/user_namespace.c >+++ b/kernel/user_namespace.c >@@ -128,7 +128,13 @@ int create_user_ns(struct cred *new) > if (!ns) > goto fail_dec; > >- ns->parent_could_setfcap = cap_raised(new->cap_effective, CAP_SETFCAP); >+ /* >+ * verify_root_map() relies on this once the creator only has >+ * capabilities in the new namespace. Let LSMs deny it, but do not >+ * audit: the creator may never map uid 0. >+ */ >+ ns->parent_could_setfcap = >+ !security_capable(new, parent_ns, CAP_SETFCAP, CAP_OPT_NOAUDIT); > > ret = ns_common_init(ns); > if (ret) > --- Thanks!