linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Jarkko Sakkinen" <jarkko@kernel.org>
To: "Jonathan Calmels" <jcalmels@3xx0.net>, <brauner@kernel.org>,
	<ebiederm@xmission.com>, "Luis Chamberlain" <mcgrof@kernel.org>,
	"Kees Cook" <keescook@chromium.org>,
	"Joel Granados" <j.granados@samsung.com>,
	"Serge Hallyn" <serge@hallyn.com>,
	"Paul Moore" <paul@paul-moore.com>,
	"James Morris" <jmorris@namei.org>,
	"David Howells" <dhowells@redhat.com>
Cc: <containers@lists.linux.dev>, <linux-kernel@vger.kernel.org>,
	<linux-fsdevel@vger.kernel.org>,
	<linux-security-module@vger.kernel.org>,
	<keyrings@vger.kernel.org>
Subject: Re: [PATCH 2/3] capabilities: add securebit for strict userns caps
Date: Thu, 16 May 2024 15:42:11 +0300	[thread overview]
Message-ID: <D1B2SCNE9LOV.EQJ3T08WUX9H@kernel.org> (raw)
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’s 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 requiring
>   specific logic for the userns capability set, or libcap support.
>
> Example:
>
>     # capsh --secbits=$((1 << 8)) --drop=cap_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 <jcalmels@3xx0.net>
> ---
>  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 <uapi/linux/securebits.h>
>  
>  #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/securebits.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))
>  
> +/* 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_CAPS))
> +#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)
>  
>  #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 <linux/cred.h>
>  #include <linux/securebits.h>
>  #include <linux/security.h>
> +#include <linux/capability.h>
>  #include <linux/keyctl.h>
>  #include <linux/key-type.h>
>  #include <keys/user-type.h>
> @@ -42,6 +43,10 @@ static void dec_user_namespaces(struct ucounts *ucounts)
>  
>  static void set_cred_user_ns(struct cred *cred, struct user_namespace *user_ns)
>  {
> +	/* Limit userns capabilities to our parent's bounding set. */
> +	if (iscredsecure(cred, SECURE_USERNS_STRICT_CAPS))
> +		cred->cap_userns = cap_intersect(cred->cap_userns, cred->cap_bset);
> +
>  	/* Start with the capabilities defined in the userns set. */
>  	cred->cap_bset = cred->cap_userns;
>  	cred->cap_permitted = cred->cap_userns;

BR, Jarkko

  reply	other threads:[~2024-05-16 12:42 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-16  9:22 [PATCH 0/3] Introduce user namespace capabilities Jonathan Calmels
2024-05-16  9:22 ` [PATCH 1/3] capabilities: " Jonathan Calmels
2024-05-16 12:27   ` Jarkko Sakkinen
2024-05-16 22:07   ` John Johansen
2024-05-17 10:51     ` Jonathan Calmels
2024-05-17 11:59       ` John Johansen
2024-05-18  3:50         ` Jonathan Calmels
2024-05-18 12:27           ` John Johansen
2024-05-19  1:33             ` Jonathan Calmels
2024-05-17 11:32   ` Eric W. Biederman
2024-05-17 11:55     ` Jonathan Calmels
2024-05-17 12:48       ` John Johansen
2024-05-17 14:22       ` Eric W. Biederman
2024-05-17 18:02         ` Jonathan Calmels
2024-05-21 15:52         ` John Johansen
2024-05-20  3:30   ` Serge E. Hallyn
2024-05-20  3:36   ` Serge E. Hallyn
2024-05-16  9:22 ` [PATCH 2/3] capabilities: add securebit for strict userns caps Jonathan Calmels
2024-05-16 12:42   ` Jarkko Sakkinen [this message]
2024-05-20  3:38   ` Serge E. Hallyn
2024-05-16  9:22 ` [PATCH 3/3] capabilities: add cap userns sysctl mask Jonathan Calmels
2024-05-16 12:44   ` Jarkko Sakkinen
2024-05-20  3:38   ` Serge E. Hallyn
2024-05-20 13:30   ` Tycho Andersen
2024-05-20 19:25     ` Jonathan Calmels
2024-05-20 21:13       ` Tycho Andersen
2024-05-20 22:12         ` Jarkko Sakkinen
2024-05-21 14:29           ` Tycho Andersen
2024-05-21 14:45             ` Jarkko Sakkinen
2024-05-16 13:30 ` [PATCH 0/3] Introduce user namespace capabilities Ben Boeckel
2024-05-16 13:36   ` Jarkko Sakkinen
2024-05-17 10:00     ` Jonathan Calmels
2024-05-16 16:23 ` Paul Moore
2024-05-16 17:18   ` Jarkko Sakkinen
2024-05-16 19:07 ` Casey Schaufler
2024-05-16 19:29   ` Jarkko Sakkinen
2024-05-16 19:31     ` Jarkko Sakkinen
2024-05-16 20:00       ` Jarkko Sakkinen
2024-05-17 11:42         ` Jonathan Calmels
2024-05-17 17:53           ` Casey Schaufler
2024-05-17 19:11             ` Jonathan Calmels
2024-05-18 11:08               ` Jarkko Sakkinen
2024-05-18 11:17                 ` Jarkko Sakkinen
2024-05-18 11:21                   ` Jarkko Sakkinen
2024-05-21 13:57                     ` John Johansen
2024-05-21 14:12                       ` Jarkko Sakkinen
2024-05-21 14:45                         ` John Johansen
2024-05-22  0:45                           ` Jonathan Calmels
2024-05-31  7:43                             ` John Johansen
2024-05-18 12:20             ` Serge Hallyn
2024-05-19 17:03               ` Casey Schaufler
2024-05-20  0:54                 ` Jonathan Calmels
2024-05-21 14:29               ` John Johansen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=D1B2SCNE9LOV.EQJ3T08WUX9H@kernel.org \
    --to=jarkko@kernel.org \
    --cc=brauner@kernel.org \
    --cc=containers@lists.linux.dev \
    --cc=dhowells@redhat.com \
    --cc=ebiederm@xmission.com \
    --cc=j.granados@samsung.com \
    --cc=jcalmels@3xx0.net \
    --cc=jmorris@namei.org \
    --cc=keescook@chromium.org \
    --cc=keyrings@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=mcgrof@kernel.org \
    --cc=paul@paul-moore.com \
    --cc=serge@hallyn.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).