From nobody Thu Oct 31 00:18:51 2024 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=1622440521; cv=none; d=zohomail.com; s=zohoarc; b=LdoxhxYJ74cou+Dii5kAc532yQe8OH89HRvcfXqOt9V9i7bEL7UW17SeZcqFuDXtiQfaGH+7wvgNoytS6C/AWeBfBZij9ggGgAdo1FGXS5y5/K9qFkjTwyGk3kcIPDW3OVShgJilh1AjzaWX5iDmUh9njgiRruxYPeGmTQmKlA8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622440521; 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=dlWjyYn6jZhO5w9ByfPHmWQImE5zU40oNP6aZuC/oSw=; b=UTbpKPT+d+caTAkKPn8JTd5B/kXNdPuMz+nx3kj5mXX1+QH/xNajQliJ8/OGTE1orDg8/wjvOGGuFOVrD1rtX8XBee13KFbYwCJtM9b8k+IdRL4evYEOh5mF+Hu5qxHo1Vk3Y8sezlT9nG9MIlAJt1HC/vZJL4SA2A0g1b3/UKU= 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 1622440521949525.5941830806898; Sun, 30 May 2021 22:55:21 -0700 (PDT) Received: from localhost ([::1]:53032 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lnatU-0004yI-VK for importer@patchew.org; Mon, 31 May 2021 01:55:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43762) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lnapZ-00059Z-Fe for qemu-devel@nongnu.org; Mon, 31 May 2021 01:51:17 -0400 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]:39688) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lnapX-0003rZ-Ii for qemu-devel@nongnu.org; Mon, 31 May 2021 01:51:17 -0400 Received: by mail-pj1-x1032.google.com with SMTP id o17-20020a17090a9f91b029015cef5b3c50so7972147pjp.4 for ; Sun, 30 May 2021 22:51:15 -0700 (PDT) Received: from spacetanuki.lan ([202.12.244.32]) by smtp.gmail.com with ESMTPSA id b10sm4744058pfi.122.2021.05.30.22.51.12 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 30 May 2021 22:51:13 -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=dlWjyYn6jZhO5w9ByfPHmWQImE5zU40oNP6aZuC/oSw=; b=Gv4g6Jh5CSxDG0PgPzkb8TV0/+UHm9el30zb+Ym5l2h4pHIVFGDUmCkUYUOzadtsvv 57r7bgSYx/N/W8XiTWpcUapC8Ii6X6rKKyU+Qc5U7o9fb/ignAyfgnGuDj1XdHqHRC6Z 7akG834PYSJ1YuNI3yPWSX6KaUswoLYHGOlzU= 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=dlWjyYn6jZhO5w9ByfPHmWQImE5zU40oNP6aZuC/oSw=; b=cZDaZ0qmpXCn89ce8MSCZX78Uev9OMKo1szrhauiQIbwXUuQ/oBd5WjhQ2QQSWHOjI yZJc3Wnfjgemvi3k6PAM/3LCY7U708uug5Qi4cRO1E3UUMZvmDPIIQxvp9phC9JLXUva FhffQk0AAKqWDq3NZ8Ipql1DMuZNCfrRpm1DJ6RYu9MRv6evFGcGgxUeb9wDnh6dXNGd tTxBgbzJZhh+9QJQmFG0wiQ65eRRzozm0vCAY9HeWa6pGVF1g4WWhNDEqrfOnyB7kd6U qdYtRoUiHlFTAft+/SFZaweaAiwP2NRXhLDVDZhUAO0BH0qH6ICUE5aTq3mh7FHr3Mvn TEIg== X-Gm-Message-State: AOAM532dqM1TK3lFvL7HGALXUsiK+CpK8xIkUTTEGGTemCbUIRjssC7m RFtQoyja1gkH7Ti9l0jv3M7BFFeuzCjgeA== X-Google-Smtp-Source: ABdhPJyTors0eOKSYyI8SaR7GIuQM1Kw0Im0e0mrDUHlCUiVrqnt0rzOP+gNXUyQGw8dHL2rWp8nNw== X-Received: by 2002:a17:902:e9cb:b029:101:cebc:b8d with SMTP id 11-20020a170902e9cbb0290101cebc0b8dmr10973690plk.5.1622440274098; Sun, 30 May 2021 22:51:14 -0700 (PDT) From: YAMAMOTO Takashi To: qemu-devel@nongnu.org Cc: YAMAMOTO Takashi , Laurent Vivier Subject: [PATCH v2 06/11] linux-user: add get_exe_path Date: Mon, 31 May 2021 14:50:13 +0900 Message-Id: <20210531055019.10149-7-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::1032; envelope-from=yamamoto@midokura.com; helo=mail-pj1-x1032.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" Refactor to prepare the special cases for /proc/$pid/exe where pid is not the calling process. Signed-off-by: YAMAMOTO Takashi --- linux-user/syscall.c | 48 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 51144c6d29..999760448d 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -7986,6 +7986,45 @@ static int open_self_auxv(void *cpu_env, int fd) return 0; } =20 +static const char *get_exe_path(int pid, char *buf, size_t bufsize) +{ + if (pid =3D=3D getpid()) { + return exec_path; + } + + return NULL; +} + +static int is_proc_file(const char *filename, int *pidp, const char *entry) +{ + if (!strncmp(filename, "/proc/", strlen("/proc/"))) { + int pid; + + filename +=3D strlen("/proc/"); + if (!strncmp(filename, "self/", strlen("self/"))) { + pid =3D getpid(); + filename +=3D strlen("self/"); + } else if (*filename >=3D '1' && *filename <=3D '9') { + pid =3D 0; + while (*filename >=3D '0' && *filename <=3D '9') { + pid =3D pid * 10 + *filename - '0'; + filename++; + } + if (*filename !=3D '/') { + return 0; + } + filename++; + } else { + return 0; + } + if (!strcmp(filename, entry)) { + *pidp =3D pid; + return 1; + } + } + return 0; +} + static int is_proc_myself(const char *filename, const char *entry) { if (!strncmp(filename, "/proc/", strlen("/proc/"))) { @@ -8492,6 +8531,8 @@ static abi_long do_syscall1(void *cpu_env, int num, a= bi_long arg1, abi_ulong addr; char **q; int total_size =3D 0; + int pid; + char path_store[PATH_MAX]; =20 argc =3D 0; guest_argp =3D arg2; @@ -8552,8 +8593,11 @@ static abi_long do_syscall1(void *cpu_env, int num, = abi_long arg1, * program's problem. */ path =3D p; - if (is_proc_myself(path, "exe")) { - path =3D exec_path; + if (is_proc_file(path, &pid, "exe")) { + path =3D get_exe_path(pid, path_store, sizeof(path_store)); + if (path =3D=3D NULL) { + path =3D p; + } } ret =3D get_errno(safe_execve(path, argp, envp)); unlock_user(p, arg1, 0); --=20 2.21.1 (Apple Git-122.3)