Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp256696lqo; Thu, 16 May 2024 05:42:30 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVW06fwvsPh03THA+QJOqP1zVKB3/gMyRsLLDKVLmR0eVfPgti0h7u/MBnnudvcK1YZaox26alI9XBoeJYhicqviZVNpS1jG2a4hZELvA== X-Google-Smtp-Source: AGHT+IGFSli6J6w3mwvkQlC8CPOEmJb5e8156dMkN4aK+wMn0aVituIt2t8RL999sPbP5snlztnW X-Received: by 2002:a17:902:d352:b0:1dd:c288:899f with SMTP id d9443c01a7336-1ef43d17ff9mr168489165ad.18.1715863350027; Thu, 16 May 2024 05:42:30 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715863350; cv=pass; d=google.com; s=arc-20160816; b=FO5f7RamwFowJRa3OJuKymCzgztFvIGl0/1fJhH258Z58bUnnTsNiGYMxgTmaJz4CA PCLMm/0cpFivpfu6Dwm0mvqhPOYc/B99yDmQ4hSzh0wQSHvv2ZxE3sPGPoI8i7b6CHJE zC95aNBb5OlMQLCTpOYnW3wiWi7h/BEz2uI5xhY62zRUVqoUcWRbAsWjIEXZRC34T0le FlyCbehajTKpPRSUoyR2ng5LknnvZe5reZeqaCU215BN7vCLrsXpkK9m5RKqSJZT3LsZ YmgiXWkG+GgLf5SPB22mGcTYEU2h2MP1Fbl8gYqlN1LtZvnLbRTf1U4/iBHhNkMgCGPM clCA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:references:cc:to:from:subject:message-id:date :content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:dkim-signature; bh=ndUpGyswepM5VzVZDt17edr43UGTNUXwp4pu+7NOlBA=; fh=T9X/TGS7ps+i7yPfL9xUrrCc2qmfofKV6wbfrIYCe4E=; b=dHRtDMHkoDjvJAXs66Wl2Xewo3fFkhwVxV1RtUX5VTKop9IyFfaXmAq/5x1BapNDBo zKLvSWhph+nIxafd+sHILw9chOuSp5JbMwOXXbX0MS9hVyKkVmXgs98ptfmgG1ufFri/ HMj//sD2d7fvkbOxD+NwXVh8/q6dsJz3X34Y0oHi3Mul+RqjwiiOOMc2/N9wjCKSXRYa XvqV9HBv7Clf0HM+a3RByUUUWGDYBZ+yPH9g3tWFisGk9ILCPWchSzeOAgU+6Lw5nbL1 yjMu8l6bkEC+IYmgGWwTXL4AB/L3VZyNLzipmVlhgl4+RGd3PwAsmA8pMYhihLf1qSfe ALmw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ANsanT6n; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-181045-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-181045-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d9443c01a7336-1ef0bf31d70si155384525ad.259.2024.05.16.05.42.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 May 2024 05:42:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-181045-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ANsanT6n; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-181045-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-181045-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 91BEB282114 for ; Thu, 16 May 2024 12:42:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 39D77146580; Thu, 16 May 2024 12:42:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ANsanT6n" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4B2C2335B5; Thu, 16 May 2024 12:42:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715863337; cv=none; b=P8TFyJliYGT2ehOJ2NQOWXOu3pL0J71sBjM28QtyuMf527FQFwgPYppk4jUrDYW3TLMtTNHlwJgeLW0I3vtsWPe84dMpYmYfk+pCPPFgEVWK5Tu1PtXrZFrlr3pQUqqt4gyb0Kw3Xf3eZrbJQ/4ZwcBYl30cDEUO3GGoCXrg/6I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715863337; c=relaxed/simple; bh=dZuc6aEkLxsStlqKWqRbYGaBpp818DtL48GR/YcgDws=; h=Mime-Version:Content-Type:Date:Message-Id:Subject:From:To:Cc: References:In-Reply-To; b=etumGbeVDAwga1CInjBSl0hzs9k/n2YOC3bqCGauorHTVhp6rr6qdwP0NAbXioY+VgNLtOUzF7K/9V3d4FBi976dtx5e++fGQF1bVjjKW6f46Fd0XafKDZ/72aftAJ+Vz38c+4Ri3l95+bfToksPglx4JgVbybQh8RPgTNKa8R4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ANsanT6n; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id D3040C2BD11; Thu, 16 May 2024 12:42:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715863336; bh=dZuc6aEkLxsStlqKWqRbYGaBpp818DtL48GR/YcgDws=; h=Date:Subject:From:To:Cc:References:In-Reply-To:From; b=ANsanT6nZYIwvn7RXLoXPppfuchIVNZvA8h22fH680TVIxuzInBAS9F7+/g10GnBd Wb3ALcWC4UFNXjQeAW0VXeiznDONGwjCvMtUsYPJbDow8QsH73paA3fynPyoROgrcC VLGgouxeyvzOtAVP4zcTuAmK+45d2VssRgPzogb/FsDmn1sP5+z0WxzVVAhEoAeeO4 GdyXwSHp8Vh9gKRU0d33phVuo1nJ5OHH5Y74XhlfEMSm//q6YRGHnqcezqs0BjVtoQ kwoWiKmDCT2LtTpxGV6JTq9mpHsmEG7hHC/8vd0RZ2yqWT4ZCYYIvyEGT9Y/y561N/ uVDdO2xmJgXZA== Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Thu, 16 May 2024 15:42:11 +0300 Message-Id: Subject: Re: [PATCH 2/3] capabilities: add securebit for strict userns caps From: "Jarkko Sakkinen" To: "Jonathan Calmels" , , , "Luis Chamberlain" , "Kees Cook" , "Joel Granados" , "Serge Hallyn" , "Paul Moore" , "James Morris" , "David Howells" Cc: , , , , X-Mailer: aerc 0.17.0 References: <20240516092213.6799-1-jcalmels@3xx0.net> <20240516092213.6799-3-jcalmels@3xx0.net> In-Reply-To: <20240516092213.6799-3-jcalmels@3xx0.net> Maintainer dependent but at least on x86 patches people tend to prefer capital letter in the short summary i.e. s/add/Add/ On Thu May 16, 2024 at 12:22 PM EEST, Jonathan Calmels wrote: > This patch adds a new capability security bit designed to constrain a > task=E2=80=99s userns capability set to its bounding set. The reason for = this is > twofold: > > - This serves as a quick and easy way to lock down a set of capabilities > for a task, thus ensuring that any namespace it creates will never be > more privileged than itself is. > - This helps userspace transition to more secure defaults by not requirin= g > specific logic for the userns capability set, or libcap support. > > Example: > > # capsh --secbits=3D$((1 << 8)) --drop=3Dcap_sys_rawio -- \ > -c 'unshare -r grep Cap /proc/self/status' > CapInh: 0000000000000000 > CapPrm: 000001fffffdffff > CapEff: 000001fffffdffff > CapBnd: 000001fffffdffff > CapAmb: 0000000000000000 > CapUNs: 000001fffffdffff > > Signed-off-by: Jonathan Calmels > --- > include/linux/securebits.h | 1 + > include/uapi/linux/securebits.h | 11 ++++++++++- > kernel/user_namespace.c | 5 +++++ > 3 files changed, 16 insertions(+), 1 deletion(-) > > diff --git a/include/linux/securebits.h b/include/linux/securebits.h > index 656528673983..5f9d85cd69c3 100644 > --- a/include/linux/securebits.h > +++ b/include/linux/securebits.h > @@ -5,4 +5,5 @@ > #include > =20 > #define issecure(X) (issecure_mask(X) & current_cred_xxx(securebits)) > +#define iscredsecure(cred, X) (issecure_mask(X) & cred->securebits) > #endif /* !_LINUX_SECUREBITS_H */ > diff --git a/include/uapi/linux/securebits.h b/include/uapi/linux/secureb= its.h > index d6d98877ff1a..2da3f4be4531 100644 > --- a/include/uapi/linux/securebits.h > +++ b/include/uapi/linux/securebits.h > @@ -52,10 +52,19 @@ > #define SECBIT_NO_CAP_AMBIENT_RAISE_LOCKED \ > (issecure_mask(SECURE_NO_CAP_AMBIENT_RAISE_LOCKED)) > =20 > +/* When set, user namespace capabilities are restricted to their parent'= s bounding set. */ > +#define SECURE_USERNS_STRICT_CAPS 8 > +#define SECURE_USERNS_STRICT_CAPS_LOCKED 9 /* make bit-8 immutable */ > + > +#define SECBIT_USERNS_STRICT_CAPS (issecure_mask(SECURE_USERNS_STRICT_CA= PS)) > +#define SECBIT_USERNS_STRICT_CAPS_LOCKED \ > + (issecure_mask(SECURE_USERNS_STRICT_CAPS_LOCKED)) > + > #define SECURE_ALL_BITS (issecure_mask(SECURE_NOROOT) | \ > issecure_mask(SECURE_NO_SETUID_FIXUP) | \ > issecure_mask(SECURE_KEEP_CAPS) | \ > - issecure_mask(SECURE_NO_CAP_AMBIENT_RAISE)) > + issecure_mask(SECURE_NO_CAP_AMBIENT_RAISE) | \ > + issecure_mask(SECURE_USERNS_STRICT_CAPS)) > #define SECURE_ALL_LOCKS (SECURE_ALL_BITS << 1) > =20 > #endif /* _UAPI_LINUX_SECUREBITS_H */ > diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c > index 7e624607330b..53848e2b68cd 100644 > --- a/kernel/user_namespace.c > +++ b/kernel/user_namespace.c > @@ -10,6 +10,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -42,6 +43,10 @@ static void dec_user_namespaces(struct ucounts *ucount= s) > =20 > static void set_cred_user_ns(struct cred *cred, struct user_namespace *u= ser_ns) > { > + /* Limit userns capabilities to our parent's bounding set. */ > + if (iscredsecure(cred, SECURE_USERNS_STRICT_CAPS)) > + cred->cap_userns =3D cap_intersect(cred->cap_userns, cred->cap_bset); > + > /* Start with the capabilities defined in the userns set. */ > cred->cap_bset =3D cred->cap_userns; > cred->cap_permitted =3D cred->cap_userns; BR, Jarkko