From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 83CD75A026F for ; Tue, 4 Apr 2023 03:46:50 +0200 (CEST) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4Pr9bj43NJz4xFZ; Tue, 4 Apr 2023 11:46:41 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1680572801; bh=ck4p/B+yyP7/3sGzkaS8MMfzI94txMdwchYVEnFXbUw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YS0HmhQGVRvpEqgih3LKpcjHMGQuS7bsCDEHOhcED1Hj1cx5zUz/uH6vWpJhiiSIj +Ahzgzq3rwkOaF6AzIGPAE2ZKzT3vUkRtlVDjlGufyXfILnQPGyOzl8PdyKTzVsuOk HtioKVfnqnIEfe1cU8jWyZAz0cFndSpKOXjHwq+Y= From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH 07/14] nstool: Add magic number to advertized information Date: Tue, 4 Apr 2023 11:46:31 +1000 Message-Id: <20230404014638.3225556-8-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230404014638.3225556-1-david@gibson.dropbear.id.au> References: <20230404014638.3225556-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: O2DPJBW3GZZQRXV3ONQHIUKABANUOLER X-Message-ID-Hash: O2DPJBW3GZZQRXV3ONQHIUKABANUOLER X-MailFrom: dgibson@gandalf.ozlabs.org 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: David Gibson 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: So that we'll probably give a better error if you point it at something that's not an nstool hold control socket. Signed-off-by: David Gibson --- test/nstool.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/nstool.c b/test/nstool.c index 428c9c4..e995f3e 100644 --- a/test/nstool.c +++ b/test/nstool.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -45,7 +46,10 @@ const struct ns_type nstypes[] = { { CLONE_NEWUTS, "uts" }, }; +#define NSTOOL_MAGIC 0x75601d75 + struct holder_info { + uint64_t magic; pid_t pid; uid_t uid; gid_t gid; @@ -101,6 +105,10 @@ static int connect_ctl(const char *sockpath, bool wait, if ((size_t)len < sizeof(*info)) die("short read() on control socket %s\n", sockpath); + if (info->magic != NSTOOL_MAGIC) + die("Control socket %s doesn't appear to belong to nstool\n", + sockpath); + if (peercred) { socklen_t optlen = sizeof(*peercred); @@ -140,6 +148,7 @@ static void cmd_hold(int argc, char *argv[]) if (rc < 0) die("listen() on %s: %s\n", sockpath, strerror(errno)); + info.magic = NSTOOL_MAGIC; info.pid = getpid(); info.uid = getuid(); info.gid = getgid(); -- 2.39.2