From nobody Sat May 17 06:37:31 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=midokura.com ARC-Seal: i=1; a=rsa-sha256; t=1622440524; cv=none; d=zohomail.com; s=zohoarc; b=N/GyWvpaHIF76v/Fdn1yW28Dd49Ey8tmH3XPsEamhdvfEy50HHHfT9WunX8mherqhdzkzebNmij+vW4cxGOnyFpQaB2k8SWoWO6f6jYck/bqzM3mAe+JDRxSg2zAEMIrZQu3AqQdIVzAkIrv4DKMjU6wvDGsE8TKYODnuxX/pJk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622440524; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=QiVXcm0ooVlb13HKGZjjy0yp8OcOQBWPELFyhh4ee78=; b=f8cUenta7MDh4Vgfj0rxkANRlal8a1mmWz81kQWCLbmL+4udNbBdafSvjfTspvfZbKZbGLvEuw2zNDYwoMKqa79ukpW1xRUN1lZK1ahCGBti23sdcPPhaKJZuOEuZUUnTBFrA1oV+UHrXMJTVJnZc0UmYYkTBiQnKAynZU+1TBU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622440524773484.31164678751645; Sun, 30 May 2021 22:55:24 -0700 (PDT) Received: from localhost ([::1]:53356 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lnatX-0005Bh-Ho for importer@patchew.org; Mon, 31 May 2021 01:55:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43816) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lnapc-0005KK-AC for qemu-devel@nongnu.org; Mon, 31 May 2021 01:51:20 -0400 Received: from mail-pg1-x52a.google.com ([2607:f8b0:4864:20::52a]:42654) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lnapa-0003tf-DY for qemu-devel@nongnu.org; Mon, 31 May 2021 01:51:19 -0400 Received: by mail-pg1-x52a.google.com with SMTP id t8so1332632pgb.9 for ; Sun, 30 May 2021 22:51:17 -0700 (PDT) Received: from spacetanuki.lan ([202.12.244.32]) by smtp.gmail.com with ESMTPSA id b10sm4744058pfi.122.2021.05.30.22.51.15 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 30 May 2021 22:51:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=midokura.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QiVXcm0ooVlb13HKGZjjy0yp8OcOQBWPELFyhh4ee78=; b=U6GtVCZFfjz2EupehhRqV6Z47mFdvElNaKSOLZgJ7Esj6COuUGrXYq+9I/a2y8BNKG H5JNkIv34wQOJFC0IWPjYph8/4PRq4MmRtNtRjtxL6g5fPw0gk/PxfiI9e2gp6BtB+5Y KjyRT0UfJyoBrN6rXOhKwXrnCUbhoc9Uo+tuY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QiVXcm0ooVlb13HKGZjjy0yp8OcOQBWPELFyhh4ee78=; b=o88PKxC9a2tmWFb4QZrxOb3LQchHx93+cUbiiy6NL5ppk/xO8C3j5+PMnBBv2C4dSp EFnl9CIu6w3BZqUyFQivX/2KyuhvNjqYTe/qb55++RsasWmtLHSeEyd7Jg2TR1MgzBe1 +tfm010vFWCZkzjRrIYtQofooPI7buRgFSfI8VxvFRX1W+iRi3NsRcVC/u2HZyLzN6mt TVaN68U/wVZmY7cV0t1AzpTT6jbdGcxMOoXLPCjOiJn8GLSEqYryW4RGcII1IQqRdtzR fcJJpz6BhCEPf0T/qqzBNbkJHlbgXM0BNUImJbk9DmEf4Lx/ZZG6czxnX7l4XLNUHu72 A4HQ== X-Gm-Message-State: AOAM530AkgnsTCLu0dByt7TpWKVd7qa+G8R4IAIbWuTFuV9cXGw3TEoL 85BJ8+2h0vrXHxvI7O1Hd1Qmtx0ubZHGVA== X-Google-Smtp-Source: ABdhPJxHcB1cpYxCpPTnJslReTzUNzvoGWmo9Fqhe96/hl7fdeJxHVHW+pH//DTxYP6KnWMwTPyRxQ== X-Received: by 2002:a62:3001:0:b029:2e9:39d0:46cd with SMTP id w1-20020a6230010000b02902e939d046cdmr15197833pfw.47.1622440276933; Sun, 30 May 2021 22:51:16 -0700 (PDT) From: YAMAMOTO Takashi To: qemu-devel@nongnu.org Cc: YAMAMOTO Takashi , Laurent Vivier Subject: [PATCH v2 08/11] linux-user: Implement exec of /proc/$pid/exe of qemu process Date: Mon, 31 May 2021 14:50:15 +0900 Message-Id: <20210531055019.10149-9-yamamoto@midokura.com> X-Mailer: git-send-email 2.21.1 (Apple Git-122.3) In-Reply-To: <20210531055019.10149-1-yamamoto@midokura.com> References: <20210531055019.10149-1-yamamoto@midokura.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::52a; envelope-from=yamamoto@midokura.com; helo=mail-pg1-x52a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @midokura.com) Content-Type: text/plain; charset="utf-8" dockerd makes runc invoke dockerd using /proc/$pid/exe. This commit makes it work when both of dockerd and runc are emulated by qemu linux-user. In that case, we (the qemu interpreting runc) need to invoke the real executable (dockerd), where /proc/$pid/exe in question is the qemu command interpreting dockerd. Signed-off-by: YAMAMOTO Takashi --- linux-user/syscall.c | 59 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 86b12cc8b4..6f9161dbe4 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -7988,10 +7988,69 @@ static int open_self_auxv(void *cpu_env, int fd) =20 static const char *get_exe_path(int pid, char *buf, size_t bufsize) { + ssize_t ssz; + int fd; + if (pid =3D=3D getpid()) { return exec_path; } =20 + /* dockerd makes runc invoke dockerd using "/proc/${dockerd_pid}/exe".= */ + snprintf(buf, bufsize, "/proc/%d/cmdline", pid); + fd =3D open(buf, O_RDONLY); + if (fd =3D=3D -1) { + return NULL; + } + ssz =3D read(fd, buf, bufsize); + if (ssz !=3D -1) { + const char *argv0; + const char *argv1; + const char *cp; + const char *ep; + const char *slash; + + cp =3D buf; + ep =3D cp + ssz; + + argv0 =3D cp; + while (*cp !=3D 0) { + cp++; + if (cp >=3D ep) { + goto fail; + } + } + + cp++; + if (cp >=3D ep) { + goto fail; + } + + argv1 =3D cp; + while (*cp !=3D 0) { + cp++; + if (cp >=3D ep) { + goto fail; + } + } + + /* + * XXX a bit too loose detection of qemu. + * maybe we can compare /proc/$pid/exe with ours. + */ + slash =3D strrchr(argv0, '/'); + if (slash !=3D NULL) { + argv0 =3D slash + 1; /* basename */ + } + if (strncmp(argv0, "qemu-", sizeof("qemu-") - 1)) { + goto fail; + } + + close(fd); + return argv1; + } +fail: + close(fd); + return NULL; } =20 --=20 2.21.1 (Apple Git-122.3)