From patchwork Mon May 24 04:54:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Yamamoto X-Patchwork-Id: 12275515 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8C17FC47080 for ; Mon, 24 May 2021 04:56:37 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2F99F610C8 for ; Mon, 24 May 2021 04:56:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2F99F610C8 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=midokura.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:52266 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ll2do-0004oG-9Y for qemu-devel@archiver.kernel.org; Mon, 24 May 2021 00:56:36 -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) 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) 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) 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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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, abi_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 = get_errno(safe_execve(p, argp, envp)); + path = p; + if (is_proc_myself(path, "exe")) { + path = exec_path; + } + ret = get_errno(safe_execve(path, argp, envp)); unlock_user(p, arg1, 0); goto execve_end; From patchwork Mon May 24 04:54:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Yamamoto X-Patchwork-Id: 12275521 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 926C5C47083 for ; Mon, 24 May 2021 04:57:44 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4162461104 for ; Mon, 24 May 2021 04:57:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4162461104 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=midokura.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:57938 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ll2et-0000Gj-Er for qemu-devel@archiver.kernel.org; Mon, 24 May 2021 00:57:43 -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) 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) 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) 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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 char *exec_path; +char exec_path_store[PATH_MAX]; int singlestep; static const char *argv0; @@ -610,7 +611,10 @@ static int parse_args(int argc, char **argv) exit(EXIT_FAILURE); } - exec_path = argv[optind]; + exec_path = realpath(argv[optind], exec_path_store); + if (exec_path == NULL) { + exec_path = argv[optind]; + } return optind; } From patchwork Mon May 24 04:54:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Yamamoto X-Patchwork-Id: 12275519 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2A0AEC04FF3 for ; Mon, 24 May 2021 04:57:43 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C312561104 for ; Mon, 24 May 2021 04:57:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C312561104 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=midokura.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:57814 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ll2er-0000Bl-VO for qemu-devel@archiver.kernel.org; Mon, 24 May 2021 00:57:41 -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) 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) 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) 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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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, if (is_proc_myself(pathname, "exe")) { int execfd = 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", execfd); + ret = safe_openat(dirfd, filename, flags, mode); + if (ret != -1) { + return ret; + } + } + return safe_openat(dirfd, exec_path, flags, mode); } for (fake_open = fakes; fake_open->filename; fake_open++) { From patchwork Mon May 24 04:54:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Yamamoto X-Patchwork-Id: 12275517 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E7891C04FF3 for ; Mon, 24 May 2021 04:56:40 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6BA32610C8 for ; Mon, 24 May 2021 04:56:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6BA32610C8 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=midokura.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:52576 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ll2dr-00051v-KG for qemu-devel@archiver.kernel.org; Mon, 24 May 2021 00:56:39 -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) 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) 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) 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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 @@ char *exec_path; char exec_path_store[PATH_MAX]; +int exec_fd = -1; int singlestep; static const char *argv0; @@ -833,6 +834,13 @@ int main(int argc, char **argv, char **envp) cpu->opaque = ts; task_settid(ts); + /* + * dup execfd to a global so that it can be used after loader_exec + * closes it. + */ + + exec_fd = dup(execfd); + ret = loader_exec(execfd, exec_path, target_argv, target_environ, regs, info, &bprm); if (ret != 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; 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, const char *pathname, int flags, }; if (is_proc_myself(pathname, "exe")) { - int execfd = qemu_getauxval(AT_EXECFD); - if (execfd) { + if (exec_fd != -1) { char filename[PATH_MAX]; int ret; - snprintf(filename, sizeof(filename), "/proc/self/fd/%d", execfd); + snprintf(filename, sizeof(filename), "/proc/self/fd/%d", exec_fd); ret = safe_openat(dirfd, filename, flags, mode); if (ret != -1) { return ret; From patchwork Mon May 24 04:54:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Yamamoto X-Patchwork-Id: 12275523 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BCF05C04FF3 for ; Mon, 24 May 2021 04:59:13 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7B1D0610C8 for ; Mon, 24 May 2021 04:59:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7B1D0610C8 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=midokura.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:32930 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ll2gK-0002Rz-LP for qemu-devel@archiver.kernel.org; Mon, 24 May 2021 00:59:12 -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) 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) 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) 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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 long *host_mask, return 0; } +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 +#if defined(TARGET_NR_pivot_root) + case TARGET_NR_pivot_root: + { + void *p2; + p = lock_user_string(arg1); /* new_root */ + p2 = lock_user_string(arg2); /* put_old */ + if (!p || !p2) { + ret = -TARGET_EFAULT; + } else { + ret = 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;