From nobody Sun May 5 16:13:04 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=midokura.com ARC-Seal: i=1; a=rsa-sha256; t=1621832209; cv=none; d=zohomail.com; s=zohoarc; b=CxnJqyivGlsNVt2S5+BboAdanhJ6qgEoODzyDlZtmYZA6wMLe1MQkdG7ariNpOdyrdmdvrpxawtkhV6w9MPBX1XSVMEMz+mNR1RrA174KNESe+6VOkvU/uxjMxyIO9XhK9Mgpfl0Zb1qVJfcz8sybyaWNfo6CmpUzVE4rnrIP74= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621832209; 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=OeAn/cQqWx3M6p6wyRkeBhZn1UMAlrViv39KO/QNygU=; b=fj1kqjZITc0ITF5DxgWNkm1P3piR+XSNJXQIH5iXtFFel2pH9Ir3ef1XK9Nl8S+xBIzIG1knZ8txY/bzkleMjhg+AvedSGlU9iJkgo2GkGUxdRvRtcC3z4HDDcVez8PyGvAuJ/jAHFipXo1HXvb9vmW2mnCnT4REIY8h2RWPOTs= 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+importer2=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 1621832209152818.7455310824186; Sun, 23 May 2021 21:56:49 -0700 (PDT) Received: from localhost ([::1]:52266 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ll2e0-0004oG-5a for importer2@patchew.org; Mon, 24 May 2021 00:56:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35718) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ll2cS-0002iP-9b for qemu-devel@nongnu.org; Mon, 24 May 2021 00:55:12 -0400 Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]:41974) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ll2cQ-0003Zk-3Y for qemu-devel@nongnu.org; Mon, 24 May 2021 00:55:12 -0400 Received: by mail-pf1-x430.google.com with SMTP id p39so3503503pfw.8 for ; Sun, 23 May 2021 21:55:09 -0700 (PDT) Received: from spacetanuki.lan ([202.12.244.32]) by smtp.gmail.com with ESMTPSA id 24sm10040142pgz.77.2021.05.23.21.55.07 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 23 May 2021 21:55:08 -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=OeAn/cQqWx3M6p6wyRkeBhZn1UMAlrViv39KO/QNygU=; b=dYQOvLaFs4ra50N8xknUtPMsdJq6p4/AH1KSVKlJFzYJDwFMsDfrOK7GUpv2X2lrnf FDmUYCJkMBFUlxjkMY8FnhsLNAqQCaRBUdtmV+p/criLKxqFjoiX3k1Prg7ITfiXtOWs ftlLA8zboj1QsRtlV4YOs0f8qj7hy7VvJEg+Q= 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=OeAn/cQqWx3M6p6wyRkeBhZn1UMAlrViv39KO/QNygU=; b=SwKEMaZyVjzfo4CgP830n2zGVJu3s66I3Fz8R7P6uAozdQa+zmf0WmK7hF6KtYVZIJ ELyHqamL//qEHVmRfxU/AWKbjlW1HSAJ5LjcvuPC+rGGHix3+0wTvPMHvlX8Fo7rHD2f PMHIBgg6NE7QVVHwAflD9xvaYrTSznD7/V8QLlaC2Xp9GI2Jtq9U+O5l3Onk3Ke3MWJ1 7yMrKczZtiZFZ9MT/zje1I0YLtAUZAZ4ZIsSUc5SyR6jWmDhQ5UBfXFkiJhpLm6T2+oM VBfusJLRLuoZ9ReLOl4xkhHWdWL9eukJjfewVD2o/3SzE2sUCn50Y7Sjt1Y+kQTD3MA5 47KQ== X-Gm-Message-State: AOAM530NI2Vvuf5wlNLK+koj2C1cG+IfrcHLJUqpaLeAx3VAExPBxQgr aD9qjjY4JUgsmLCRwVEiym1uPhqNjTGuMg== X-Google-Smtp-Source: ABdhPJxckaOYC02JcZo46MIgafsS8Lao7RgcHh7zLQEUW6ncoRImWWiQDN4q4vJkDpDeLaJLQq1tmg== X-Received: by 2002:a62:c541:0:b029:2e8:c7c7:d96e with SMTP id j62-20020a62c5410000b02902e8c7c7d96emr4775272pfg.26.1621832108727; Sun, 23 May 2021 21:55:08 -0700 (PDT) From: YAMAMOTO Takashi To: qemu-devel@nongnu.org Cc: YAMAMOTO Takashi , Laurent Vivier Subject: [PATCH 1/5] linux-user: handle /proc/self/exe for execve Date: Mon, 24 May 2021 13:54:07 +0900 Message-Id: <20210524045412.15152-2-yamamoto@midokura.com> X-Mailer: git-send-email 2.21.1 (Apple Git-122.3) In-Reply-To: <20210524045412.15152-1-yamamoto@midokura.com> References: <20210524045412.15152-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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::430; envelope-from=yamamoto@midokura.com; helo=mail-pf1-x430.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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @midokura.com) Content-Type: text/plain; charset="utf-8" It seems somehow common to execve /proc/self/exe in docker or golang community these days. At least, moby "reexec" and runc "libcontainer" do that. Signed-off-by: YAMAMOTO Takashi --- linux-user/syscall.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index c9f812091c..a2b03ecb8b 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8470,6 +8470,7 @@ static abi_long do_syscall1(void *cpu_env, int num, a= bi_long arg1, #endif case TARGET_NR_execve: { + const char *path; char **argp, **envp; int argc, envc; abi_ulong gp; @@ -8537,7 +8538,11 @@ static abi_long do_syscall1(void *cpu_env, int num, = abi_long arg1, * before the execve completes and makes it the other * program's problem. */ - ret =3D get_errno(safe_execve(p, argp, envp)); + path =3D p; + if (is_proc_myself(path, "exe")) { + path =3D exec_path; + } + ret =3D get_errno(safe_execve(path, argp, envp)); unlock_user(p, arg1, 0); =20 goto execve_end; --=20 2.21.1 (Apple Git-122.3) From nobody Sun May 5 16:13:04 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=midokura.com ARC-Seal: i=1; a=rsa-sha256; t=1621832280; cv=none; d=zohomail.com; s=zohoarc; b=ZVQTb+hTn7IpRezwdiwaLv1hncncNuVRhFbNqU0d5GTnZJiJb/QXpQdY3gkKezBSnUzBP3NqrLVqHy+igeHVew9ZUNv3rV6+kKQPK7kOG0b2IgE8vVo1NS37aO/mLEQOvrUQ0f+OJ3K9PInwiOVdgNGbw8g+Ise9imVppfxQhYE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621832280; 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=OjEvdBCaEtLFXNObt2sjDlAUMq69u4KYkjfRSX5e7ww=; b=liIkQNrzXmsuAj1QU5GBZPiZHxYnLeit70HUyHZZYULJEgi+00k2LFrkLxVSro1J48uGYMXG/rrBYOP+9cYLbItjkLKe+FYdlR8W2ePJSZSSUQ8SZ4qF+2kyTgs5GMI1Z9X2njTxECckv11wd+ksJA9uKY887IBYEnz9/UaKTCc= 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+importer2=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 1621832280005819.9313709869554; Sun, 23 May 2021 21:58:00 -0700 (PDT) Received: from localhost ([::1]:57938 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ll2f9-0000Gj-0S for importer2@patchew.org; Mon, 24 May 2021 00:57:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35740) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ll2cT-0002ix-F0 for qemu-devel@nongnu.org; Mon, 24 May 2021 00:55:13 -0400 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]:46022) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ll2cR-0003bF-Qz for qemu-devel@nongnu.org; Mon, 24 May 2021 00:55:13 -0400 Received: by mail-pf1-x42c.google.com with SMTP id d16so19831534pfn.12 for ; Sun, 23 May 2021 21:55:11 -0700 (PDT) Received: from spacetanuki.lan ([202.12.244.32]) by smtp.gmail.com with ESMTPSA id 24sm10040142pgz.77.2021.05.23.21.55.09 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 23 May 2021 21:55:10 -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=OjEvdBCaEtLFXNObt2sjDlAUMq69u4KYkjfRSX5e7ww=; b=bw77HFJEdVpxj5YK5BwJ9cO8b1B+215dFODgfuwmqMqRqNt6O1TMp2KMKVmV3Og5IQ 1nyqGtKAH0dahrIrY/gKZKyoyhBvycYZpmb34YDB3n2U0bluCQgk3w6MJVf56vDUNaMX GWk1PCYFtuAvTLCZuYuB8IIaK00feAgapobbI= 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=OjEvdBCaEtLFXNObt2sjDlAUMq69u4KYkjfRSX5e7ww=; b=PNIeCZcTVkSo7Oi6QvSrr5VrjvNMqcODM/dpqd9TFYgznkfBL1WfCge26bXNB5Dsuh EFN29xwHigY7XDiGplBeUNdbpok0Om1U7aLOVKXgAIKHAXMuwhv2+J4Ker99MDcARYYu H4GxS+9v81ImHgg16r/bH1EyXuZ5ckbtL4s5Ux773q0S0jUucxW8bxqDw3f+e8aXb1FL H6UNrw2n0pk4ffyHIjZuFH8WRzECadHE37mSN/reVrAt9Ml4YKsEIwgjH7UiWzhW2Aut YBSHMNTr3i5YEPGpq9eXnaygBGMbHImPrHNHSjfSJFLiEgPrgRx1HbBVEkLQngo1Rq2L JLHA== X-Gm-Message-State: AOAM533hIEVNlyD5xfkc1SzffLrrgJoSPKY8Ls8PLjx0Z2ONdS6S+/Is U73+xM67f+lnr+p8YHaooS10rdGKkYIoyg== X-Google-Smtp-Source: ABdhPJx1dCaEMY75gNn39FuUOhZ/OttWumVmj//cNq2s3MYMSuGLof5LcT8UOyma5UjtSQeCjtof8Q== X-Received: by 2002:a65:53c8:: with SMTP id z8mr11700527pgr.192.1621832110444; Sun, 23 May 2021 21:55:10 -0700 (PDT) From: YAMAMOTO Takashi To: qemu-devel@nongnu.org Cc: YAMAMOTO Takashi , Laurent Vivier Subject: [PATCH 2/5] linux-uesr: make exec_path realpath Date: Mon, 24 May 2021 13:54:08 +0900 Message-Id: <20210524045412.15152-3-yamamoto@midokura.com> X-Mailer: git-send-email 2.21.1 (Apple Git-122.3) In-Reply-To: <20210524045412.15152-1-yamamoto@midokura.com> References: <20210524045412.15152-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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::42c; envelope-from=yamamoto@midokura.com; helo=mail-pf1-x42c.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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @midokura.com) Content-Type: text/plain; charset="utf-8" Otherwise, it can be easily fooled by the user app using chdir(). Signed-off-by: YAMAMOTO Takashi --- linux-user/main.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/linux-user/main.c b/linux-user/main.c index 4dfc47ad3b..1f9f4e3820 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -55,6 +55,7 @@ #endif =20 char *exec_path; +char exec_path_store[PATH_MAX]; =20 int singlestep; static const char *argv0; @@ -610,7 +611,10 @@ static int parse_args(int argc, char **argv) exit(EXIT_FAILURE); } =20 - exec_path =3D argv[optind]; + exec_path =3D realpath(argv[optind], exec_path_store); + if (exec_path =3D=3D NULL) { + exec_path =3D argv[optind]; + } =20 return optind; } --=20 2.21.1 (Apple Git-122.3) From nobody Sun May 5 16:13:04 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=midokura.com ARC-Seal: i=1; a=rsa-sha256; t=1621832274; cv=none; d=zohomail.com; s=zohoarc; b=JJy0GaTlwEBzfrMFraQ/VmArfcfPMtfhQcJMC0IACJ6veB8jbIIXy14HAmNI2c4K0EuI07eZ3JdwotUKmqDfkOxl0yd+ntFkaTRI59YFNk6Bj0XMZ0gzuGioBkx+Onrw8+40jmwHepRwZd0gcmSKVQFP3MRk6xhV0yPl1r5NJ3I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621832274; 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=PESTXN59EwLMWjjV5A2aXDktqX9ai+DunPJniUgY9VA=; b=UZkLoJZNJQuG9SUGceCDkFft5hdx/ce5WMlw/kscR8S03h1ml0GW3dbM3agnOvgmf5Sqtl90VKwtTFgc4j+NRDoKlijFVYNrM/wwnt/rOXtSEXr9eH8+BxKB55rp0SA7GC8CkBMv9c1rMpP+YdL5t6Y94XD2q2grIpuP/aPL1io= 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+importer2=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 162183227402551.62921800724132; Sun, 23 May 2021 21:57:54 -0700 (PDT) Received: from localhost ([::1]:57814 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ll2f3-0000Bl-0d for importer2@patchew.org; Mon, 24 May 2021 00:57:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35766) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ll2cV-0002mG-3g for qemu-devel@nongnu.org; Mon, 24 May 2021 00:55:15 -0400 Received: from mail-pg1-x52a.google.com ([2607:f8b0:4864:20::52a]:42988) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ll2cT-0003cH-EA for qemu-devel@nongnu.org; Mon, 24 May 2021 00:55:14 -0400 Received: by mail-pg1-x52a.google.com with SMTP id f22so18267974pgb.9 for ; Sun, 23 May 2021 21:55:13 -0700 (PDT) Received: from spacetanuki.lan ([202.12.244.32]) by smtp.gmail.com with ESMTPSA id 24sm10040142pgz.77.2021.05.23.21.55.10 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 23 May 2021 21:55:11 -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=PESTXN59EwLMWjjV5A2aXDktqX9ai+DunPJniUgY9VA=; b=YAdC5XJSbjP3uhZ+k+kdd3Y6JLo0X/lX5Y8iF88i2V34zpPn48vyah2BSR1qSyNnNE lvncEFX4piLaHu5LAOlMeEueDn6BTLN+WJbnlSrf5IIxxv58fcmiigmwHBVYVqAKDkyH MRJRh7ty6h0HznsY/Bi0ZEKQsdaFigjRCYBEA= 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=PESTXN59EwLMWjjV5A2aXDktqX9ai+DunPJniUgY9VA=; b=Sns5qTqoZRv5Im+XeFxwjCzcb3IZg5/u/MC7tXZ7DZllbkXy5I7ntWDU0IsJbmu8IN hJp5WeunSiUuImXsaUGIb1hoJL++p6rI9XANrdufdJsFRKzsQRLiO418NyLTgu6WcL4Y ol+xgCDVa/ES2Ka1iD/lcAompgeh+qRtKwurZElT+l+Gvkbw9mWa3xU+FA9ixDSIKLDa +P63zWDVwisImy476aLJw9jqJXLJn1IG3MHL/C7wSXzf/Zze0CX0p8xF18BcJb/ziGD5 AMJJSjpjNJr1XJtbiQ4/x1EHzIjHpeAvX7pHBfJSztk2Vb0h9JwvnkBnEGOhD+kiRKWS CUSQ== X-Gm-Message-State: AOAM531vef4FG8DUSMFcUChPgzanUR5L8dY/k1oLtFex8lRedi49WK02 jyWdyH0XThYPf8UHAvkLr2Z7137yW0u4EA== X-Google-Smtp-Source: ABdhPJx4nk9h4hHKYmp/zHWK9adDZvY5ZFpDEx7MxxjjHaC5jvJ/MH/Neaz1J413PdpO+s+Vic0LYQ== X-Received: by 2002:a05:6a00:23c6:b029:28f:d463:17ba with SMTP id g6-20020a056a0023c6b029028fd46317bamr22992343pfc.65.1621832112054; Sun, 23 May 2021 21:55:12 -0700 (PDT) From: YAMAMOTO Takashi To: qemu-devel@nongnu.org Cc: YAMAMOTO Takashi , Laurent Vivier Subject: [PATCH 3/5] linux-user: Fix the execfd case of /proc/self/exe open Date: Mon, 24 May 2021 13:54:09 +0900 Message-Id: <20210524045412.15152-4-yamamoto@midokura.com> X-Mailer: git-send-email 2.21.1 (Apple Git-122.3) In-Reply-To: <20210524045412.15152-1-yamamoto@midokura.com> References: <20210524045412.15152-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+importer2=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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @midokura.com) Content-Type: text/plain; charset="utf-8" It's problematic to return AT_EXECFD as it is because the user app would close it. This patch opens it via /proc/self/fd instead. Signed-off-by: YAMAMOTO Takashi --- linux-user/syscall.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index a2b03ecb8b..14a63518e2 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8118,7 +8118,17 @@ static int do_openat(void *cpu_env, int dirfd, const= char *pathname, int flags, =20 if (is_proc_myself(pathname, "exe")) { int execfd =3D qemu_getauxval(AT_EXECFD); - return execfd ? execfd : safe_openat(dirfd, exec_path, flags, mode= ); + if (execfd) { + char filename[PATH_MAX]; + int ret; + + snprintf(filename, sizeof(filename), "/proc/self/fd/%d", execf= d); + ret =3D safe_openat(dirfd, filename, flags, mode); + if (ret !=3D -1) { + return ret; + } + } + return safe_openat(dirfd, exec_path, flags, mode); } =20 for (fake_open =3D fakes; fake_open->filename; fake_open++) { --=20 2.21.1 (Apple Git-122.3) From nobody Sun May 5 16:13:04 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=midokura.com ARC-Seal: i=1; a=rsa-sha256; t=1621832212; cv=none; d=zohomail.com; s=zohoarc; b=dUTyj4n/ERvKkiviyFSQQpoKWaPxgxp/YPeQsCEdgPzwJk4hYMfKzyhn/gdR9AnQ56E8VeaF8vX1mo7Go6YZijoaa0nmTMe9ZF69lWtiIyaiXTvlPXiGyHVJBvm7QLKuKqBW1Msc4MFanvhgSL6MJijO/TuhcnPSLcGWtX0K9+Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621832212; 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=m89buCPgpozLCxeMx0IXmxkOBtSNDh85t/lIV1xW87I=; b=agsPE92ojYVCXrbZnPVE37FhofJMUdtALCTPEmmkvcVfq23HGL6HtbSbZ/zYOKhGOJSJ30s1Q3G/8AvgZdFlpd8BYGpVc1pPh0qoMHmvB+EXCaFgU2/7OPRkGnhKJagvGyWWzz4Q4nr9NfTDUEYx1l1FCmJi+Uaq6OKShq0EBV4= 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+importer2=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 1621832212381606.3584860775865; Sun, 23 May 2021 21:56:52 -0700 (PDT) Received: from localhost ([::1]:52576 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ll2e3-00051v-DD for importer2@patchew.org; Mon, 24 May 2021 00:56:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35786) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ll2cW-0002r9-Sp for qemu-devel@nongnu.org; Mon, 24 May 2021 00:55:16 -0400 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]:37504) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ll2cV-0003dr-7B for qemu-devel@nongnu.org; Mon, 24 May 2021 00:55:16 -0400 Received: by mail-pf1-x435.google.com with SMTP id q67so2798942pfb.4 for ; Sun, 23 May 2021 21:55:14 -0700 (PDT) Received: from spacetanuki.lan ([202.12.244.32]) by smtp.gmail.com with ESMTPSA id 24sm10040142pgz.77.2021.05.23.21.55.12 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 23 May 2021 21:55: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=m89buCPgpozLCxeMx0IXmxkOBtSNDh85t/lIV1xW87I=; b=C7Z9xryBcnYbATE6fvhIKU5L1SoRVtpiMwIMxdd78xO0c49bomE7JzVOL3qaCuOsYT CGEOFpVZW31KLJBhV4d9iBVoLuM0PLHVBwO+uMgRnArxZbTxxKi5kYWSRSO2oYjWzUFq GOkjvAW+ebX/MJfGsVTVJkffcKbiTOba4jH/o= 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=m89buCPgpozLCxeMx0IXmxkOBtSNDh85t/lIV1xW87I=; b=e9UNw0sDE2/rBUTaFCGCDOhEV03FSvR9e3cKawtF46FPJDdlzNtpv92rJ/EtqQ2A/X S6hWEoRwrWgCdyMhOoVMy7kneR+X1+nwdETVk0fvGtnw6XUh+wPICJ6AfD0XNSuq7Jgx yKELqiuXWWix2sK6x0x8toE49OrswzKhIEVfwFY5RK3FPNzultAdCSRqa9yqlK/fwZ1P DSR7hrIMthJtBo1yuLcraY2YPgE3o/xbsbVQNczxih20mAr3GGdwMd0KI+LA/86Hseke PVQDmE1cges9dJaTn7ffi0LiBbh8EtoOkrld/4x8GR1gejX3uYIcr2c0J3OK7SoacBJB EKqg== X-Gm-Message-State: AOAM531HEqCxLNrtPaFpELYkZWlNA7rk+gbtcG4D/rld9Cg4vOzGT1yH dgwCZLGOmat4qyX2n97tC9dUAXV2XWAxTg== X-Google-Smtp-Source: ABdhPJxVI07QWih+uncYTBFIt7HPbCWU3PUVKKui0PTHkX3qMr2rJbNHLDVzF9MPPfdO3xqHUG1yDA== X-Received: by 2002:a63:fc20:: with SMTP id j32mr11718223pgi.8.1621832113586; Sun, 23 May 2021 21:55:13 -0700 (PDT) From: YAMAMOTO Takashi To: qemu-devel@nongnu.org Cc: YAMAMOTO Takashi , Laurent Vivier Subject: [PATCH 4/5] linux-user: dup the execfd on start up Date: Mon, 24 May 2021 13:54:10 +0900 Message-Id: <20210524045412.15152-5-yamamoto@midokura.com> X-Mailer: git-send-email 2.21.1 (Apple Git-122.3) In-Reply-To: <20210524045412.15152-1-yamamoto@midokura.com> References: <20210524045412.15152-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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::435; envelope-from=yamamoto@midokura.com; helo=mail-pf1-x435.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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @midokura.com) Content-Type: text/plain; charset="utf-8" So that it can be used for other purposes (e.g. syscall.c) after the elf loader closed it. Signed-off-by: YAMAMOTO Takashi --- linux-user/main.c | 8 ++++++++ linux-user/qemu.h | 2 ++ linux-user/syscall.c | 5 ++--- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/linux-user/main.c b/linux-user/main.c index 1f9f4e3820..86ddba8b62 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -56,6 +56,7 @@ =20 char *exec_path; char exec_path_store[PATH_MAX]; +int exec_fd =3D -1; =20 int singlestep; static const char *argv0; @@ -833,6 +834,13 @@ int main(int argc, char **argv, char **envp) cpu->opaque =3D ts; task_settid(ts); =20 + /* + * dup execfd to a global so that it can be used after loader_exec + * closes it. + */ + + exec_fd =3D dup(execfd); + ret =3D loader_exec(execfd, exec_path, target_argv, target_environ, re= gs, info, &bprm); if (ret !=3D 0) { diff --git a/linux-user/qemu.h b/linux-user/qemu.h index 3b0b6b75fe..ee4e9a1779 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -160,6 +160,8 @@ typedef struct TaskState { } __attribute__((aligned(16))) TaskState; =20 extern char *exec_path; +extern int exec_fd; + void init_task_state(TaskState *ts); void task_settid(TaskState *); void stop_all_tasks(void); diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 14a63518e2..2947e79dc0 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8117,12 +8117,11 @@ static int do_openat(void *cpu_env, int dirfd, cons= t char *pathname, int flags, }; =20 if (is_proc_myself(pathname, "exe")) { - int execfd =3D qemu_getauxval(AT_EXECFD); - if (execfd) { + if (exec_fd !=3D -1) { char filename[PATH_MAX]; int ret; =20 - snprintf(filename, sizeof(filename), "/proc/self/fd/%d", execf= d); + snprintf(filename, sizeof(filename), "/proc/self/fd/%d", exec_= fd); ret =3D safe_openat(dirfd, filename, flags, mode); if (ret !=3D -1) { return ret; --=20 2.21.1 (Apple Git-122.3) From nobody Sun May 5 16:13:04 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=midokura.com ARC-Seal: i=1; a=rsa-sha256; t=1621832391; cv=none; d=zohomail.com; s=zohoarc; b=HHeYu/ky5g9mYkNjEZNCRgaF4c9dThNvjBYOyfHZzNlFClfopW0kfIeqySnfcxYK2WIJi7YEM+hiWSZtV6zysPrLH512z00ckPriwuRTkPQlKMdbOXxQjQ+Lzn9W+JN10qQcdDYJX2VrZ4PRWTWVnWO82ePnfCjTDxsRTKmvMPM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621832391; 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=D+ig9QEHBa0VtdnZHEiwQpPJhF1VPhhLA5g2SBOkaAQ=; b=nlbMdQFDetrnMa4ECDH9E5yL+DIBNoSK2t3WdzlwioEUvZvvotbr/AH41jy/DLlkVwIE+zgtIbnI87jQEtZwWr2Sbmorib8I7pa4NBweUNt7nC5KrumixwbGUZqG89Fer9ofKxvZLJh3gmTQ8+BwL0CV8TrQUwE5nRDnRx0tX5U= 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+importer2=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 1621832391124836.137287924573; Sun, 23 May 2021 21:59:51 -0700 (PDT) Received: from localhost ([::1]:32930 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ll2gw-0002Rz-63 for importer2@patchew.org; Mon, 24 May 2021 00:59:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35808) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ll2cc-0002uK-3L for qemu-devel@nongnu.org; Mon, 24 May 2021 00:55:22 -0400 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]:46024) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ll2cW-0003en-JB for qemu-devel@nongnu.org; Mon, 24 May 2021 00:55:21 -0400 Received: by mail-pf1-x42c.google.com with SMTP id d16so19831667pfn.12 for ; Sun, 23 May 2021 21:55:16 -0700 (PDT) Received: from spacetanuki.lan ([202.12.244.32]) by smtp.gmail.com with ESMTPSA id 24sm10040142pgz.77.2021.05.23.21.55.14 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 23 May 2021 21:55:15 -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=D+ig9QEHBa0VtdnZHEiwQpPJhF1VPhhLA5g2SBOkaAQ=; b=ZE2K9/2knnKnL+VF5neAFzcylin1qcdvgDsSOavAmYFSPH+P0IhwIgoCj9oHjJhYqP mQ7JKhc0/JHo2V7Te5c3GrxzolJjxyJMYaOyHg73RCX33d732WaNmu5PGTNaCfOVEan8 KVwCVaRz3BDpeOuJAUS+mEa8WOjDLvqyoatrg= 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=D+ig9QEHBa0VtdnZHEiwQpPJhF1VPhhLA5g2SBOkaAQ=; b=E4vl7Jjh8lXelAgp0HNe/BTNlqFcJbOGchX6cIZu65cBC7GpBbp0w4mVQLEzjutLqZ VzheX3QvbqVc/57FOySB/IFKj2RUipvBdRlMPQ4MsiKWyUK7L3bPeUonCZ+oeZBB3Qlh RQMYKhXlGwKN66HsqUX5THZdUUDvdJbe6rAfA1/73evPeffwPdquISxCh0jyp2kjqCBY 10vnZYM7ScXuemiPYZZ8+b5jsusC7z1xk5vIFa3uAVU71kV4d1fNly6+d0cJzPZc7I7s 7ChDZ9hZ6nAD65ufFNNmaGu/g5J2HLF10+DZyY6X2Ny9mwbtNCMWHlpESeNTeExLBc8a tCuA== X-Gm-Message-State: AOAM5321SsaF+Snjm50LAMgyoDawLXbEpLDC+ooSQXaElq89ZkhhCMw0 sm3KCom+DwIG2YKtAAs0wJNYC3hWszWLYA== X-Google-Smtp-Source: ABdhPJwqm4+nZk2gKjcOTOodx86q1Rs6ZAcI8j9A/FeRXsw6T7lmWS8b4fj/rQEw2Xn4IDh8W9/QUA== X-Received: by 2002:a65:625a:: with SMTP id q26mr4648298pgv.311.1621832115226; Sun, 23 May 2021 21:55:15 -0700 (PDT) From: YAMAMOTO Takashi To: qemu-devel@nongnu.org Cc: YAMAMOTO Takashi , Laurent Vivier Subject: [PATCH 5/5] linux-user: Implement pivot_root Date: Mon, 24 May 2021 13:54:11 +0900 Message-Id: <20210524045412.15152-6-yamamoto@midokura.com> X-Mailer: git-send-email 2.21.1 (Apple Git-122.3) In-Reply-To: <20210524045412.15152-1-yamamoto@midokura.com> References: <20210524045412.15152-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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::42c; envelope-from=yamamoto@midokura.com; helo=mail-pf1-x42c.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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @midokura.com) Content-Type: text/plain; charset="utf-8" Used by runc. Signed-off-by: YAMAMOTO Takashi --- linux-user/syscall.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 2947e79dc0..e739921e86 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -8254,6 +8255,11 @@ static int host_to_target_cpu_mask(const unsigned lo= ng *host_mask, return 0; } =20 +static int pivot_root(const char *new_root, const char *put_old) +{ + return syscall(SYS_pivot_root, new_root, put_old); +} + /* This is an internal helper for do_syscall so that it is easier * to have a single return point, so that actions, such as logging * of syscall results, can be performed. @@ -13222,6 +13228,23 @@ static abi_long do_syscall1(void *cpu_env, int num= , abi_long arg1, return ret; #endif =20 +#if defined(TARGET_NR_pivot_root) + case TARGET_NR_pivot_root: + { + void *p2; + p =3D lock_user_string(arg1); /* new_root */ + p2 =3D lock_user_string(arg2); /* put_old */ + if (!p || !p2) { + ret =3D -TARGET_EFAULT; + } else { + ret =3D get_errno(pivot_root(p, p2)); + } + unlock_user(p2, arg2, 0); + unlock_user(p, arg1, 0); + } + return ret; +#endif + default: qemu_log_mask(LOG_UNIMP, "Unsupported syscall: %d\n", num); return -TARGET_ENOSYS; --=20 2.21.1 (Apple Git-122.3)