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.129.124]) by passt.top (Postfix) with ESMTP id C18225A026D for ; Wed, 5 Apr 2023 13:58:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680695909; 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=rRhWzcFdV9883tBmIoDnZbILvLft1ZjtKrcdn/qXgsw=; b=ErW11VGoisUtnxkuUG3xopwIPHG8ZBB+ch1lLepwtNqN9NTd7wh+IausoZjoroIUAGitLM QGut/NYx8XXvDeEPkxEza6a2CzKrPrweRzo3QTWqsyPE6RqUFU6gI5WTSJJy2R/dXMYNtY ejoGlN0WXv5Wk2hGkcOYkFUItNAbcUk= 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-351-PMrF9XXEN3imJNjiPo3BKg-1; Wed, 05 Apr 2023 07:58:28 -0400 X-MC-Unique: PMrF9XXEN3imJNjiPo3BKg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A2555382C96B; Wed, 5 Apr 2023 11:58:27 +0000 (UTC) Received: from elisabeth (unknown [10.39.208.33]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 01516C084B3; Wed, 5 Apr 2023 11:58:26 +0000 (UTC) Date: Wed, 5 Apr 2023 13:58:25 +0200 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH 06/14] nstool: Detect what namespaces target is in Message-ID: <20230405135825.13e18482@elisabeth> In-Reply-To: <20230404014638.3225556-7-david@gibson.dropbear.id.au> References: <20230404014638.3225556-1-david@gibson.dropbear.id.au> <20230404014638.3225556-7-david@gibson.dropbear.id.au> Organization: Red Hat MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: MJ63KUMEMVSXYCRL4VBINPX5F2BRATLE X-Message-ID-Hash: MJ63KUMEMVSXYCRL4VBINPX5F2BRATLE 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:30 +1000 David Gibson wrote: > Give nstool the ability to detect what namespaces the target process is in, > relative to where it's called. That is, those namespace types for which > the target is not in the same namespace as the caller. For now, just > print this information with "info", which can be useful for debugging. > > Signed-off-by: David Gibson > --- > test/nstool.c | 154 +++++++++++++++++++++++++++++++++++++++++++++----- > 1 file changed, 140 insertions(+), 14 deletions(-) > > diff --git a/test/nstool.c b/test/nstool.c > index 2cb4fb3..428c9c4 100644 > --- a/test/nstool.c > +++ b/test/nstool.c > @@ -15,8 +15,13 @@ > #include > #include > #include > +#include > #include > #include > +#include > +#include > + > +#define ARRAY_SIZE(a) ((int)(sizeof(a) / sizeof((a)[0]))) > > #define die(...) \ > do { \ > @@ -24,6 +29,28 @@ > exit(1); \ > } while (0) > > +struct ns_type { > + int flag; > + const char *name; > +}; > + > +const struct ns_type nstypes[] = { > + { CLONE_NEWCGROUP, "cgroup" }, > + { CLONE_NEWIPC, "ipc" }, > + { CLONE_NEWNET, "net" }, > + { CLONE_NEWNS, "mnt" }, > + { CLONE_NEWPID, "pid" }, > + { CLONE_NEWTIME, "time" }, > + { CLONE_NEWUSER, "user" }, > + { CLONE_NEWUTS, "uts" }, > +}; > + > +struct holder_info { > + pid_t pid; > + uid_t uid; > + gid_t gid; > +}; > + > static void usage(void) > { > die("Usage:\n" > @@ -41,12 +68,16 @@ static void usage(void) > " terminate.\n"); > } > > -static int connect_ctl(const char * sockpath, bool wait) > +static int connect_ctl(const char *sockpath, bool wait, > + struct holder_info *info, > + struct ucred *peercred) > { > int fd = socket(AF_UNIX, SOCK_STREAM, PF_UNIX); > struct sockaddr_un addr = { > .sun_family = AF_UNIX, > }; > + struct holder_info discard; > + ssize_t len; > int rc; > > if (fd < 0) > @@ -61,6 +92,25 @@ static int connect_ctl(const char * sockpath, bool wait) > die("connect() to %s: %s\n", sockpath, strerror(errno)); > } while (rc < 0); > > + if (!info) > + info = &discard; As you close the socket anyway moments later, I wonder if it wouldn't be doable (and more natural) to just do: if (info) { len = read(fd, info, sizeof(*info)); ... } if (peercred) { ... } ...but maybe it adds unnecessary complication to 7/14 (or perhaps the magic is not really part of 'info'?). -- Stefano