public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: Stefano Brivio <sbrivio@redhat.com>
Cc: passt-dev@passt.top
Subject: Re: [PATCH 3/3] isolation: Initially Keep CAP_SETFCAP if running as UID 0 in non-init
Date: Mon, 22 May 2023 15:48:13 +1000	[thread overview]
Message-ID: <ZGsCHcJxbOaci3xD@yekko> (raw)
In-Reply-To: <20230521234158.2769867-4-sbrivio@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 2033 bytes --]

On Mon, May 22, 2023 at 01:41:58AM +0200, Stefano Brivio wrote:
> If pasta spawns a child process while running as UID 0, which is only
> allowed from a non-init namespace, we need to keep CAP_SETFCAP before
> pasta_start_ns() is called: otherwise, starting from Linux 5.12, we
> won't be able to update /proc/self/uid_map with the intended mapping
> (from 0 to 0). See user_namespaces(7).
> 
> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>

> ---
>  isolation.c | 17 ++++++++++++++---
>  1 file changed, 14 insertions(+), 3 deletions(-)
> 
> diff --git a/isolation.c b/isolation.c
> index 5f89047..19932bf 100644
> --- a/isolation.c
> +++ b/isolation.c
> @@ -177,6 +177,8 @@ static void clamp_caps(void)
>   */
>  void isolate_initial(void)
>  {
> +	uint64_t keep;
> +
>  	/* We want to keep CAP_NET_BIND_SERVICE in the initial
>  	 * namespace if we have it, so that we can forward low ports
>  	 * into the guest/namespace
> @@ -193,9 +195,18 @@ void isolate_initial(void)
>  	 * further capabilites in isolate_user() and
>  	 * isolate_prefork().
>  	 */
> -	drop_caps_ep_except(BIT(CAP_NET_BIND_SERVICE) |
> -			    BIT(CAP_SETUID) | BIT(CAP_SETGID) |
> -			    BIT(CAP_SYS_ADMIN) | BIT(CAP_NET_ADMIN));
> +	keep = BIT(CAP_NET_BIND_SERVICE) | BIT(CAP_SETUID) | BIT(CAP_SETGID) |
> +	       BIT(CAP_SYS_ADMIN) | BIT(CAP_NET_ADMIN);
> +
> +	/* Since Linux 5.12, if we want to update /proc/self/uid_map to create
> +	 * a mapping from UID 0, which only happens with pasta spawning a child
> +	 * from a non-init user namespace (pasta can't run as root), we need to
> +	 * retain CAP_SETFCAP too.
> +	 */
> +	if (!ns_is_init() && !geteuid())
> +		keep |= BIT(CAP_SETFCAP);
> +
> +	drop_caps_ep_except(keep);
>  }
>  
>  /**

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

      reply	other threads:[~2023-05-22  6:01 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-21 23:41 [PATCH 0/3] Fix pasta-in-pasta operation (and similar) Stefano Brivio
2023-05-21 23:41 ` [PATCH 1/3] util, conf: Add and use ns_is_init() helper Stefano Brivio
2023-05-22  5:41   ` David Gibson
2023-05-22  8:50     ` Stefano Brivio
2023-05-21 23:41 ` [PATCH 2/3] pasta: Detach mount namespace, (re)mount procfs before spawning command Stefano Brivio
2023-05-22  5:42   ` David Gibson
2023-05-21 23:41 ` [PATCH 3/3] isolation: Initially Keep CAP_SETFCAP if running as UID 0 in non-init Stefano Brivio
2023-05-22  5:48   ` David Gibson [this message]

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=ZGsCHcJxbOaci3xD@yekko \
    --to=david@gibson.dropbear.id.au \
    --cc=passt-dev@passt.top \
    --cc=sbrivio@redhat.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.
Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

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 IMAP folder(s).