From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTP id BF2145A026D for ; Wed, 5 Apr 2023 13:59:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680695948; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nl5tKf2v+qdyG2hIPINHNxUCQs7BGY3peGaGNelVPjI=; b=YUcA7Be9+DveP9FQQXTUKAajbr2N0oy4mrbeMd+TyzQ+Xpd4JWi1Q3PAE5TabYywSqPWiA nTocTAG/3Bx8l87mATIuJtek72wlED9IPSw7+rihmtBshImU+r5RwECIgwWjX1Fis4ZEl2 LkPvQvBxHhzVfFcZzz0prIdnJpfpn6U= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-646--5mL5CfUNx-3yP1EtAOWjg-1; Wed, 05 Apr 2023 07:59:05 -0400 X-MC-Unique: -5mL5CfUNx-3yP1EtAOWjg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 493413C10228; Wed, 5 Apr 2023 11:59:05 +0000 (UTC) Received: from elisabeth (unknown [10.39.208.33]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 956891121314; Wed, 5 Apr 2023 11:59:04 +0000 (UTC) Date: Wed, 5 Apr 2023 13:59:02 +0200 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH 10/14] nstool: Add --keep-caps option to nstool exec Message-ID: <20230405135903.24139711@elisabeth> In-Reply-To: <20230404014638.3225556-11-david@gibson.dropbear.id.au> References: <20230404014638.3225556-1-david@gibson.dropbear.id.au> <20230404014638.3225556-11-david@gibson.dropbear.id.au> Organization: Red Hat MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: BCTLBBEWYOOGBZQ756Y6M5FZMEPWKJHL X-Message-ID-Hash: BCTLBBEWYOOGBZQ756Y6M5FZMEPWKJHL X-MailFrom: sbrivio@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On Tue, 4 Apr 2023 11:46:34 +1000 David Gibson wrote: > This allows you to run commands within a user namespace with the > privilege that comes from owning that userns. > > Signed-off-by: David Gibson > --- > test/nstool.c | 89 +++++++++++++++++++++++++++++++++++++++++++++------ > 1 file changed, 79 insertions(+), 10 deletions(-) > > diff --git a/test/nstool.c b/test/nstool.c > index 25079aa..3ecc456 100644 > --- a/test/nstool.c > +++ b/test/nstool.c > @@ -18,11 +18,15 @@ > #include > #include > #include > +#include > +#include > #include > #include > +#include > +#include > #include > -#include > #include > +#include > > #define ARRAY_SIZE(a) ((int)(sizeof(a) / sizeof((a)[0]))) > > @@ -75,11 +79,13 @@ static void usage(void) > " nstool info [-pw] pid SOCK\n" > " Print information about the nstool hold process with control\n" > " socket at SOCK\n" > - " -p Print just the holder's PID as seen by the caller\n" > - " -w Retry connecting to SOCK until it is ready\n" > - " nstool exec SOCK [COMMAND [ARGS...]]\n" > + " -p Print just the holder's PID as seen by the caller\n" > + " -w Retry connecting to SOCK until it is ready\n" > + " nstool exec [--keep-caps] SOCK [COMMAND [ARGS...]]\n" > " Execute command or shell in the namespaces of the nstool hold\n" > " with control socket at SOCK\n" > + " --keep-caps Give all possible capabilities to COMMAND via\n" > + " the ambient capability mask\n" > " nstool stop SOCK\n" > " Instruct the nstool hold with control socket at SOCK to\n" > " terminate.\n"); > @@ -275,7 +281,6 @@ static void cmd_info(int argc, char *argv[]) > } while (opt != -1); > > if (optind != argc - 1) { > - fprintf(stderr, "B\n"); > usage(); > } > > @@ -356,21 +361,82 @@ static void wait_for_child(pid_t pid) > die("Unexpected status for child %d\n", pid); > } > > +static void caps_to_ambient(void) > +{ > + /* Use raw system calls to avoid the overly complex caps > + * libraries. */ Bad indentation here. -- Stefano