From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id C5DE95A0273 for ; Thu, 6 Apr 2023 05:28:26 +0200 (CEST) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4PsRm56TcBz4xFk; Thu, 6 Apr 2023 13:28:21 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1680751701; bh=Hs+0eooSvTGoP/kO/i1Z/LNXTvLl5VyLKNK+lw/yJO4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=miWemW03CiAxBgLi/gkj3ArSSATpgnwuLyuyRfAg9lT6o1s9S5fhNFJzlTiBup00T yN8w3ga+2yD90gCTyL0tGT0wyzH7ax379k7MtyJ6GzLGF9RYv+7tsgxnd+Bh0QVTZS eAzeUrC3DqxAwCAckVXnr2TOZN6gE1XpmtpcNe8c= From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH v2 07/14] nstool: Add magic number to advertized information Date: Thu, 6 Apr 2023 13:28:12 +1000 Message-Id: <20230406032819.707441-8-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230406032819.707441-1-david@gibson.dropbear.id.au> References: <20230406032819.707441-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: BBWZHGXUKQTD3DVRMRPHLO3GRDGJJPEK X-Message-ID-Hash: BBWZHGXUKQTD3DVRMRPHLO3GRDGJJPEK 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 146b66e..7b222dd 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 0x7570017575601d75ULL + struct holder_info { + uint64_t magic; pid_t pid; uid_t uid; gid_t gid; @@ -104,6 +108,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); @@ -143,6 +151,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