From nobody Tue May 14 10:01:23 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=1622440391; cv=none; d=zohomail.com; s=zohoarc; b=Qii0u9yN/wu3Gtvn6yBaqxVCeb8FdYZaU2wNDT3cVxYs5awmeNzz7F1ujeiz9mZqA9TlugOslsLZpTmNC7hcoXRsIHkhuZ8eF4igtAG0UiOjsXcl7AGlB+8E1sJ+BSiwulwupJSsRoAKm2XBQNo3s4vk6OaTynRoEo+PY/syOs0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622440391; 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=LCk1kjgRWmQkikfr/cg+HZPQeskRY0GdMwZTbc8Qmx7jLEg+mkeULWCWDd9N7ZqLLfvs27sAn6vyLiMzaMVfWYbHIKpcP5olwf7W4klUOjVtVATLz5cth+45kI+vFn0A7RtNAWuaJp/QRLGFqvM9OU0EHBvJz3ey2LefUbqjxSc= 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 1622440390899217.27886662218293; Sun, 30 May 2021 22:53:10 -0700 (PDT) Received: from localhost ([::1]:44118 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lnarM-0007Vv-O5 for importer@patchew.org; Mon, 31 May 2021 01:53:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43690) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lnapR-0004r5-W0 for qemu-devel@nongnu.org; Mon, 31 May 2021 01:51:10 -0400 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]:47036) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lnapQ-0003l6-6c for qemu-devel@nongnu.org; Mon, 31 May 2021 01:51:09 -0400 Received: by mail-pl1-x634.google.com with SMTP id e1so392721pld.13 for ; Sun, 30 May 2021 22:51:07 -0700 (PDT) Received: from spacetanuki.lan ([202.12.244.32]) by smtp.gmail.com with ESMTPSA id b10sm4744058pfi.122.2021.05.30.22.51.05 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 30 May 2021 22:51:06 -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=mXfeLo0C63QDtvkw2najSeuNEyo/d0ZeDx0gkZIhe0q7VWzD5dGFzkGwEapR9dmTiW WyGwY3wFBIffO2vyS34EpLv+lPSz0M9YTNcFP1jE7Kcmi98JPzVXjT6tHGGBFji7tWQK uz3R4Q6tNl6JL3etkZhZ0Zc+xYtTwkIJHAJdg= 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=P4cYxH6Bot9kU/ol36W79rvbPyVvzxGyITMGq4d8C7VdmeLPEsDalBLesWNrA8YLeG 0IlMNfMNTlLTLNnQI8E+LoLtOxngCzUvoFhSDeaAWCvPDNDZBodAw/ViS4hl5FGYjrv8 5eBjvi2YKJJitJDMpdYAATJcQGMLIBD6LGk4O93DRq75sNh20clFNG2H6q1N+qGjTRPX HEudIWxGlnt9Txab/rT0jXYg2YW9+VcA41EwaYH+5jztGq1sgjBhEFncqvpieQzaKYIz RIKa73LrYsz7/VndGffeuKeWURG4QP8u3FKQsVUKUb81e/YLUlYK5lkiTANkd08VBDA/ I4cQ== X-Gm-Message-State: AOAM530qhfYRuj1sqJRU+crIztAzZ1+XL8uTD1DQ87peDWveH+UVdPvT xsO23/XlJhnSPI3gj/Gn0a3+rL7G+J3ZgA== X-Google-Smtp-Source: ABdhPJwAh07FJKuuI6yCHuGtnSF6u/z21RWyoK23GzthxtZ9HYEG/w+SVOjmQ5GQDx8fDTfmeC9UXA== X-Received: by 2002:a17:90a:7e07:: with SMTP id i7mr5796807pjl.191.1622440266613; Sun, 30 May 2021 22:51:06 -0700 (PDT) From: YAMAMOTO Takashi To: qemu-devel@nongnu.org Cc: YAMAMOTO Takashi , Laurent Vivier Subject: [PATCH v2 01/11] linux-user: handle /proc/self/exe for execve Date: Mon, 31 May 2021 14:50:08 +0900 Message-Id: <20210531055019.10149-2-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::634; envelope-from=yamamoto@midokura.com; helo=mail-pl1-x634.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" 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 Tue May 14 10:01:23 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=1622440393; cv=none; d=zohomail.com; s=zohoarc; b=R6JBPi5ap+bCOzeYNCi7M1zN2QDkPMhkcl0aXogSwXaUd92xgVs7C6hDiPPVGwm5AcfJ9wRztEhVEBI4G8waVs1dz9tT2mIU+OO//Xa6vpRYJAw55Ye80YFBn3SEjURVgJ7rPVeXFO8NeQzAjo70I7r9sb1Q9NWAyW3VLWwGSuQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622440393; 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=Iu6ORUQniYHkKyAD8Zgfg0z2QGWDfEG7nilt1UqBh4iS/tn0hARxMoqw6DJIde7a+f0zUtE2c8LnfXGGrWxxD9bkBwGh2kaBIgqx8KtHJIlAxWHywXw6EwezKEcgN9MtBQc6e1cDyrTMuacOi6vygOKEEXideAd36OeohLqg59Q= 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 162244039362738.52650453718729; Sun, 30 May 2021 22:53:13 -0700 (PDT) Received: from localhost ([::1]:44340 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lnarP-0007f2-HV for importer@patchew.org; Mon, 31 May 2021 01:53:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43700) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lnapT-0004rE-9q for qemu-devel@nongnu.org; Mon, 31 May 2021 01:51:11 -0400 Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]:42749) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lnapR-0003mJ-N9 for qemu-devel@nongnu.org; Mon, 31 May 2021 01:51:11 -0400 Received: by mail-pf1-x431.google.com with SMTP id x18so8191393pfi.9 for ; Sun, 30 May 2021 22:51:09 -0700 (PDT) Received: from spacetanuki.lan ([202.12.244.32]) by smtp.gmail.com with ESMTPSA id b10sm4744058pfi.122.2021.05.30.22.51.06 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 30 May 2021 22:51: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=PESTXN59EwLMWjjV5A2aXDktqX9ai+DunPJniUgY9VA=; b=oS3XReGyor7uDwlHLyZQhjNp4g7PElnFgzLAzwv7FGoqVvNVBkkeZGCt3/2NIKMqxF JLOsHojQwwCDTsZbrGEuD+dFjoVW1RSyYh/aGBOK+WnNta2ItzXeHdNOd7O+dmuzHwbV Bp6DuMDt2W9fUHI2LzpJ2Dr7p2OHrFgarXBbM= 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=sDWgSlaYYXSMt1+6SfOpjrFdt5dHpfqeNKz0phnGU9hi7JEFx4nosWOAehMd1rgg6t PTnk/MB0IRL2R5McdFaReUnP4tRlWPlutvshxzmC42voo+pCtQqRDHSM9CgG2bfkn3Ea hh7TyjWbEq80XpgsEIwByu28iullLWbafdWfo3t2sriU9Ptuh+qfSTS0QU7whjzXlalj XpKXC9ByzbK/46DxVO/EWNC+8L9wjXj6nFx5ASG0Tmn/sTbvLN7lEroxtTeQ2M9Ng6B5 EvlhBkHgmyT00lphQBmvy5/fwL2uy59NTVZGkI78K5GO5gcMkcRNrnXAoUf2EDPoGjme JqrQ== X-Gm-Message-State: AOAM531GuRB1Q2tzrds6gMn9cVvS//CgbLqVwKS90QRXwsqtNwnojXPx Im1auxA9Vrs0/wprx2UOw0JI5YPMv0nAbg== X-Google-Smtp-Source: ABdhPJw/uKDTW7aaRX0KdQoFeq+j6NjL9wUpcyPnd+Byg6DufJogMJKw4fdNoq71nFtCGaaKcupNzA== X-Received: by 2002:a05:6a00:1a8b:b029:28e:7b62:5118 with SMTP id e11-20020a056a001a8bb029028e7b625118mr15333588pfv.49.1622440268384; Sun, 30 May 2021 22:51:08 -0700 (PDT) From: YAMAMOTO Takashi To: qemu-devel@nongnu.org Cc: YAMAMOTO Takashi , Laurent Vivier Subject: [PATCH v2 02/11] linux-user: Fix the execfd case of /proc/self/exe open Date: Mon, 31 May 2021 14:50:09 +0900 Message-Id: <20210531055019.10149-3-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::431; envelope-from=yamamoto@midokura.com; helo=mail-pf1-x431.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" 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 Tue May 14 10:01:23 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=1622440393; cv=none; d=zohomail.com; s=zohoarc; b=kRVmPIK2ws41b061wQRJJPodrAALNTISQnJ0ySFMKXJlddM6szLGyKySI/zkagt4zb0vHC9RIMU03DfT+Jl050GsArJVsijUKsXd6nF8lgY//FG3rsV6pbeaTlBdhcUTeFvTU2g/XuvHXklO9fuTfLJAGhwccc+zwH8dRpqf2aM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622440393; 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=6OHb5vr+xooTxpqfVh+yYzyV8snT/0WRGHVgk3YW6HY=; b=L3hVlMw4o0MCYB36R6KRsNmw+jkD1D6vj1sOvP9IIKmvXnyrQgmCs1JUTCmnrUvO9JWxGKz2aFaI8dWUAr4UZZPC78KBcOYYjmB/DnGdo0ecNIHY+FbpU3mk2y4RAllfykCgxYRXnCWCtbhUCxmE2oOlRgTNVA140smWVoaW1MI= 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 1622440393217251.99854848974826; Sun, 30 May 2021 22:53:13 -0700 (PDT) Received: from localhost ([::1]:44422 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lnarP-0007iA-RT for importer@patchew.org; Mon, 31 May 2021 01:53:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43722) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lnapU-0004tJ-RZ for qemu-devel@nongnu.org; Mon, 31 May 2021 01:51:12 -0400 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]:46070) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lnapT-0003o4-6y for qemu-devel@nongnu.org; Mon, 31 May 2021 01:51:12 -0400 Received: by mail-pf1-x42a.google.com with SMTP id d16so8166434pfn.12 for ; Sun, 30 May 2021 22:51:10 -0700 (PDT) Received: from spacetanuki.lan ([202.12.244.32]) by smtp.gmail.com with ESMTPSA id b10sm4744058pfi.122.2021.05.30.22.51.08 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 30 May 2021 22:51: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=6OHb5vr+xooTxpqfVh+yYzyV8snT/0WRGHVgk3YW6HY=; b=R+eTsrt0eRtz8Gdf4CHAOrxrZd9tAp0NcYqQ1ZyaySCrLRgbu7EGgrWFaIXNpYsHsb 6dmWJe7u9D4tYxHmpMyv5hhyPVzPuoKd1G9YgdLIkFmu4DMILdxIDNgF8eHIpR+tnqGj dWeViTWetRlRShswBgvxRREKfNXjLfeNG+nrc= 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=6OHb5vr+xooTxpqfVh+yYzyV8snT/0WRGHVgk3YW6HY=; b=JcMdk8FdjH5Qj/LQdLbqPDBJZZo14RIQC+yJzwlcGiUaCdbH/UFYRKOyedV5ZGHLAo EuwKLJ5SngrrMBnS8zIMW4ofEM7jUQQ08AKOQmEp7JVN9D+e7u2tJJMGKMPzffRV0iCy qVNUzcxZrRcJjDQy6Pvbc5HKJWBCLFZSbjxJKPyD7YGDd9qeD1gcfVC7ubj2TsFFfhZ5 nG5C7eFJ+K36BHK9PM4iejHAmRn9xgv6jYEkZFQvfe7NB+jSTsGvLwRyNlvLyy+E2Uny hLogPTMhPqG++0e5VC9zWMow4o/Aw88fcIph5h9J+QRAZER6WxuUi+upwdNBPDeH1TlF Njkg== X-Gm-Message-State: AOAM533891SorIeESkDScwepcF6HYx1vmpLXppXdL9wuHQDZJVArjtPc hmhCuJjMrRYa2NOLXYLMPJt0NffqVFdW7A== X-Google-Smtp-Source: ABdhPJxPE+wmCj5VB+nRBANPbfsgM1NM6R7fg5IPJ1chofrPHojnjF1aHyUyhrHxEsLTs7pBDdIM2A== X-Received: by 2002:aa7:820f:0:b029:2e9:3aea:2e05 with SMTP id k15-20020aa7820f0000b02902e93aea2e05mr15315498pfi.13.1622440269800; Sun, 30 May 2021 22:51:09 -0700 (PDT) From: YAMAMOTO Takashi To: qemu-devel@nongnu.org Cc: YAMAMOTO Takashi , Laurent Vivier Subject: [PATCH v2 03/11] linux-user: dup the execfd on start up Date: Mon, 31 May 2021 14:50:10 +0900 Message-Id: <20210531055019.10149-4-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::42a; envelope-from=yamamoto@midokura.com; helo=mail-pf1-x42a.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" 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 | 10 +++++++++- linux-user/qemu.h | 2 ++ linux-user/syscall.c | 5 ++--- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/linux-user/main.c b/linux-user/main.c index 4dfc47ad3b..a9d02f9583 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -55,6 +55,7 @@ #endif =20 char *exec_path; +int exec_fd =3D -1; =20 int singlestep; static const char *argv0; @@ -693,7 +694,14 @@ int main(int argc, char **argv, char **envp) * Manage binfmt-misc open-binary flag */ execfd =3D qemu_getauxval(AT_EXECFD); - if (execfd =3D=3D 0) { + if (execfd > 0) { + /* + * dup execfd to a global so that it can be used after loader_exec + * closes it. + */ + + exec_fd =3D dup(execfd); + } else { execfd =3D open(exec_path, O_RDONLY); if (execfd < 0) { printf("Error while loading %s: %s\n", exec_path, strerror(err= no)); 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 Tue May 14 10:01:23 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=1622440396; cv=none; d=zohomail.com; s=zohoarc; b=P0JN6cNjFRwezb9UoCmV+gKX3+CcOzGbr7R9fBUjvLrjW2Nm8YdvlL4bdqjB/NEhghnzutrSEO7dRIE5g7uY26+kxLucxAVY1NzB2VyJ0RJQel+/+rkedxoh1vPabeAy0LQspXOqlgfbj6rWTrDTXyuKRKjFGA5Vmi6hCKXWlA4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622440396; 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=DAsgew0PuL4nW9yTQE28tqe8JgDQa0h/wMivkuc7Sqs=; b=ElndNf7bzK2ywsqgRYmzkBkqCLVCnqJDSvnF4es01wLdxGQmbg+J6M5bzVkZVb5eiB/6StwtMb8aejfnK8lesdPRWq5WdrJt0fRitckG1Wfx2rwtqyRyswT/wEyczDp8es3wAuEE+eZEnjaIaHqwMiZV459WgFMTjtnc+j7zZ6A= 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 1622440396015253.03595194420177; Sun, 30 May 2021 22:53:16 -0700 (PDT) Received: from localhost ([::1]:44702 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lnarT-0007tb-0v for importer@patchew.org; Mon, 31 May 2021 01:53:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43734) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lnapW-0004wn-5J for qemu-devel@nongnu.org; Mon, 31 May 2021 01:51:14 -0400 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]:43977) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lnapU-0003oo-JN for qemu-devel@nongnu.org; Mon, 31 May 2021 01:51:13 -0400 Received: by mail-pl1-x62d.google.com with SMTP id v12so4647145plo.10 for ; Sun, 30 May 2021 22:51:12 -0700 (PDT) Received: from spacetanuki.lan ([202.12.244.32]) by smtp.gmail.com with ESMTPSA id b10sm4744058pfi.122.2021.05.30.22.51.10 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 30 May 2021 22:51: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=DAsgew0PuL4nW9yTQE28tqe8JgDQa0h/wMivkuc7Sqs=; b=YJNev2eneIe6WmmLgurJ2stSBhx5kKSiExGV3uLvfyOjdfZUOlc1UovaIwAvh21LD6 V57+HI0dpqOqqdoCRevAZdqnahe1oJ/kwWnVA1bPHzj7PAqXCueHMHG4kQ6xV6fbu/Pc sWMNjxAbCbqv7iVG7rMTk3YWuXhjXUWUk20JQ= 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=DAsgew0PuL4nW9yTQE28tqe8JgDQa0h/wMivkuc7Sqs=; b=iT4laYPPC6KHFNBKA2DPR8KHLHNPfuS5kZqedYfnfZEHOUdMC5NSQuifUc1A1dLJly uNhBfXBHI3l+khjnQKT4JmjtCL0xA9m2qUc26XETrNJnqs2H8X383oroAOVfkItbSPjP fo7Z07ZQnXtUs06ZlFEJ3Wns5900uQdsWiRkd5XxSpFNW/O23SUEU/IlH+gStnn7Ts3C +hWVvncJrAomuJqAoPqiD65Wi3HL8GeI6IYkazbupyC7DSqmVrfWF3tXG9Y0SQXNm2L+ kQDQG5S80YCLFXk3BoB9m5ZEm5cgZo8mWq0/7tZ+cPRtSS6S1udECoECliiRuxj0wtZv jCfQ== X-Gm-Message-State: AOAM530qproxLX/x6PsLFYoZuFTEUBtXEMHV/Pm6VE2IhF6ECwlt62Od aFJu5Kv5KXwijHFTMXUWGZe+/QJG1Lg9Hw== X-Google-Smtp-Source: ABdhPJxyHFIOisANzzN2h3H/XQ95b/AJM0t3feppzfdN+U2yf6tsywUSh747UiMvL9K77QiXIiQoJg== X-Received: by 2002:a17:90b:4384:: with SMTP id in4mr17741440pjb.159.1622440271198; Sun, 30 May 2021 22:51:11 -0700 (PDT) From: YAMAMOTO Takashi To: qemu-devel@nongnu.org Cc: YAMAMOTO Takashi , Laurent Vivier Subject: [PATCH v2 04/11] linux-user: make exec_path realpath Date: Mon, 31 May 2021 14:50:11 +0900 Message-Id: <20210531055019.10149-5-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::62d; envelope-from=yamamoto@midokura.com; helo=mail-pl1-x62d.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" Otherwise, it can be easily fooled by the user app using chdir(). Signed-off-by: YAMAMOTO Takashi --- linux-user/main.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/linux-user/main.c b/linux-user/main.c index a9d02f9583..be604a84f9 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]; int exec_fd =3D -1; =20 int singlestep; @@ -611,7 +612,20 @@ static int parse_args(int argc, char **argv) exit(EXIT_FAILURE); } =20 - exec_path =3D argv[optind]; + /* + * Try to get the realpath of the executable to avoid being + * fooled by chdir is the user app. + * + * Note: realpath here can fail for some use cases. + * For example, runc executes an unlinked binary via + * /proc/self/fd. + * It isn't fatal as far as we have an exec fd. + * (Otherwise, we will fail to load the binary. + */ + 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 Tue May 14 10:01:23 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=1622440520; cv=none; d=zohomail.com; s=zohoarc; b=MX62dA30FG6OVhyI6ry/7Q2qRNuCLLkD7871EsDpywipMYq/k1aNMEIwOr1aV3PoHlmJDE2IhnPHL/d2Crs6uHksqNEgXoszgPTV3oATtj6/z+B8EQKdK6PyJDxCa5M2KYO7CMvJagnDhUa0ukiDYz32jG3RfJ3R+RG2ud1SkDo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622440520; 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=jZBlbfeu3NXCpv3F7hDFEvZVI/DgvLfsFk5ytNgoOU8=; b=REyhvTWXpbA0MwMDwkYFqy6OEphbN6+vwZfSebhN4Gbr/Mx9eFK+UAFnVPR72+czpx72xh1ggD3PI8+HBhj0jMr4nYpT3RefpLj5c3+Ep2UB5Re8WU7eZjg6hCde+NH3EevFTVi/HUfY4M+SF2fu4kTukx3uK0Rt6J+Jd3Bu3Gg= 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 1622440520647290.41190827525384; Sun, 30 May 2021 22:55:20 -0700 (PDT) Received: from localhost ([::1]:52918 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lnatT-0004tF-Hx for importer@patchew.org; Mon, 31 May 2021 01:55:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43748) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lnapX-00052p-PX for qemu-devel@nongnu.org; Mon, 31 May 2021 01:51:15 -0400 Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]:33534) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lnapW-0003qG-1x for qemu-devel@nongnu.org; Mon, 31 May 2021 01:51:15 -0400 Received: by mail-pj1-x1036.google.com with SMTP id k22-20020a17090aef16b0290163512accedso1149685pjz.0 for ; Sun, 30 May 2021 22:51:13 -0700 (PDT) Received: from spacetanuki.lan ([202.12.244.32]) by smtp.gmail.com with ESMTPSA id b10sm4744058pfi.122.2021.05.30.22.51.11 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 30 May 2021 22:51:12 -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=jZBlbfeu3NXCpv3F7hDFEvZVI/DgvLfsFk5ytNgoOU8=; b=bJfck3h20NHGnpqQRT+T2eDYLj+kBbtUmaE2JQgaBcHcVSyCLbSr88XQfl29FqXiyp ZXstTRQNJQn18TZiHsbl5Llv3NQJM4im4N2PfV2bvCNZJ8Z/RRhCsqTrInbAzFtL0kzB MrIrTsmlZPOg3TsBUgEppv6Q7KiOB+qtxoRxQ= 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=jZBlbfeu3NXCpv3F7hDFEvZVI/DgvLfsFk5ytNgoOU8=; b=s3v48yyfPiul318XLnaoEpPtJ7mFB9D4dAUd8k0R0kFvUokBfHR7BATEcgLqnEijLJ Ck3EWbxhkeGdlP8kJXc8RQSeHSRKa80tQ1HfyDurtMhLjrfEX7E26rMTotrIdC/E6p3P uSnafYp1uikLKuaOZvVpIDhJHC9rvk8b0amgM17198q7n52HESGG8xPgRYOrwlydfAt/ M8Eajf9FuACBR1YLoyFKyoMqDTwjMxgYLSuZwPXomDhpl9KnRl5hXt9m7hKC8R30G8yM Bu1sIpjS7Ym5k5AzOrXRO4Op4M5jkm05C+CJmFG8slVmfUO9C459gpV4tP/PUBK1WkbP ID9A== X-Gm-Message-State: AOAM531yrTexEViUuiC04hq6j3hKavsNkmMAqbkgjs1OoiM6dZ9Y7P1v 9J63aGAmvpPMZHk+zvFUclb+3VpQUtxVwg== X-Google-Smtp-Source: ABdhPJwh1uedUhYhEmbjiMqyLbr0yJ5ksuTHLDs72YpRqsswRZ2KLPfCwelD8c0vWbzutyBjM17OLA== X-Received: by 2002:a17:90a:4e0b:: with SMTP id n11mr17391336pjh.155.1622440272659; Sun, 30 May 2021 22:51:12 -0700 (PDT) From: YAMAMOTO Takashi To: qemu-devel@nongnu.org Cc: YAMAMOTO Takashi , Laurent Vivier Subject: [PATCH v2 05/11] linux-user: Implement pivot_root Date: Mon, 31 May 2021 14:50:12 +0900 Message-Id: <20210531055019.10149-6-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::1036; envelope-from=yamamoto@midokura.com; helo=mail-pj1-x1036.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" Used by runc. Signed-off-by: YAMAMOTO Takashi Reviewed-by: Laurent Vivier --- linux-user/syscall.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 2947e79dc0..51144c6d29 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8254,6 +8254,10 @@ static int host_to_target_cpu_mask(const unsigned lo= ng *host_mask, return 0; } =20 +#if defined(TARGET_NR_pivot_root) && defined(__NR_pivot_root) +_syscall2(int, pivot_root, const char *, new_root, const char *, put_old) +#endif + /* 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 +13226,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) From nobody Tue May 14 10:01:23 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) From nobody Tue May 14 10:01:23 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=1622440677; cv=none; d=zohomail.com; s=zohoarc; b=WF4TJDLrs9BkH0IpAntzyR7sN/2FnA5ApWYu4es1T6xm4LdlH+YPgrzGV2Sfib/2eMg+U45zaj4HTeXg0e20xgwR3JowFkrE1yjiTOboagAYFBIsaxEQllzh5krnH4tf5vtIq1YXy1T6xpREzihmZb76ccQYSdQAo8TIKh9Mw+4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622440677; 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=3+BI+nbaPKoWHm/U4VU/VNR8sz2T1YSSyUR4DMbZdYQ=; b=mWGfEbGiO5pif5LEIf5HzTAyO1tGNbw93A4/sqTlKs50sEXG8ZckuVOJnJy/NlLvHtVx22sCIlrZl/bz38rg4bY8oQIXwELKNaR+M7RbGASg9y5ky6Rkhw6a1ZFIgbEVg5vqzbR/aqqzlUqqWPLA/0GavtFEZck5qS7dwVd25sw= 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 1622440677070263.13042399910285; Sun, 30 May 2021 22:57:57 -0700 (PDT) Received: from localhost ([::1]:60420 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lnavz-0001Wn-Bt for importer@patchew.org; Mon, 31 May 2021 01:57:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43804) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lnapa-0005E6-LT for qemu-devel@nongnu.org; Mon, 31 May 2021 01:51:18 -0400 Received: from mail-pg1-x52d.google.com ([2607:f8b0:4864:20::52d]:44939) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lnapY-0003sN-Tn for qemu-devel@nongnu.org; Mon, 31 May 2021 01:51:18 -0400 Received: by mail-pg1-x52d.google.com with SMTP id 29so7524022pgu.11 for ; Sun, 30 May 2021 22:51:16 -0700 (PDT) Received: from spacetanuki.lan ([202.12.244.32]) by smtp.gmail.com with ESMTPSA id b10sm4744058pfi.122.2021.05.30.22.51.14 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 30 May 2021 22:51: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=3+BI+nbaPKoWHm/U4VU/VNR8sz2T1YSSyUR4DMbZdYQ=; b=m9OxVrwiDG928ILBrr0wmVGm3v4IMmdVFZob2B76I7dHw7YIV8pOhG7VU4IxLJ9Vcd w5KOYU9py0tSnWrlz8y0S8/Pe4B1Se+CsGPzJJSbv/Tq3aCTAK37mbgm9AdzMSvK51XC GajBC95x9ik2LlF1hnbKspBNUKOmoO1ZUNuK8= 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=3+BI+nbaPKoWHm/U4VU/VNR8sz2T1YSSyUR4DMbZdYQ=; b=TZzGJIBAtl7gDlz+5DTCDYWwpt0rfhCd/6B/xk+7s8Q/easw8/0jqzGpDG6QLhe+Us kGb961OG4ZLONJfVUnlpwxxHT9SFyni6CbCzBHI7u/qiTKSIpciw41jsOeNy/9rge9CS CVHGcZUgiZLrJyhl1apQSglza+uSMlYtffw09VtjDI5kgz6jaEPOMhJo3axeRhZHVgRm 7gYUK/L6Iczlyx6Q9M4aaMOiGNbC/WvYJIcP+TMmJz6mnxCCheFt9hvRjxK+Ou7GQrPM 0PcP0xvXwy+5GumXSfGAo3M5lJN5wvZK6XcY+GvSCVyfH2DePT8vyIq4LOZBB4JbEaJ0 ossA== X-Gm-Message-State: AOAM533LDp7VuqhxvpKXii0z6jzK+6fGHQ2FOr7JvArAWk2vBXznFLJ1 RVPNXQFNAqY1bBUr0dakyLpdbg4AFEDrhg== X-Google-Smtp-Source: ABdhPJy9N13/m6zW7EvfU4PW5SmbcYRrPB/cJPRoNWqy5/9VRgYGqvwB8hWk76DWT90gZEOPG43Uzw== X-Received: by 2002:aa7:9a4f:0:b029:2e6:cf9a:f469 with SMTP id x15-20020aa79a4f0000b02902e6cf9af469mr15776116pfj.43.1622440275505; Sun, 30 May 2021 22:51:15 -0700 (PDT) From: YAMAMOTO Takashi To: qemu-devel@nongnu.org Cc: YAMAMOTO Takashi , Laurent Vivier Subject: [PATCH v2 07/11] linux-user: simplify is_proc_myself Date: Mon, 31 May 2021 14:50:14 +0900 Message-Id: <20210531055019.10149-8-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::52d; envelope-from=yamamoto@midokura.com; helo=mail-pg1-x52d.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" Signed-off-by: YAMAMOTO Takashi --- linux-user/syscall.c | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 999760448d..86b12cc8b4 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8027,26 +8027,9 @@ static int is_proc_file(const char *filename, int *p= idp, const char *entry) =20 static int is_proc_myself(const char *filename, const char *entry) { - if (!strncmp(filename, "/proc/", strlen("/proc/"))) { - filename +=3D strlen("/proc/"); - if (!strncmp(filename, "self/", strlen("self/"))) { - filename +=3D strlen("self/"); - } else if (*filename >=3D '1' && *filename <=3D '9') { - char myself[80]; - snprintf(myself, sizeof(myself), "%d/", getpid()); - if (!strncmp(filename, myself, strlen(myself))) { - filename +=3D strlen(myself); - } else { - return 0; - } - } else { - return 0; - } - if (!strcmp(filename, entry)) { - return 1; - } - } - return 0; + int pid; + + return is_proc_file(filename, &pid, entry) && pid =3D=3D getpid(); } =20 #if defined(HOST_WORDS_BIGENDIAN) !=3D defined(TARGET_WORDS_BIGENDIAN) || \ --=20 2.21.1 (Apple Git-122.3) From nobody Tue May 14 10:01:23 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=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) From nobody Tue May 14 10:01:23 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=1622440710; cv=none; d=zohomail.com; s=zohoarc; b=R959TOblgifsc2KENO1Qbl/GRa3NbAhVRKR5B1B0N0oV4zUQmjpXxkJRrCW0/WP8SifHg2cFqv981UkilTjWzT/D727KYVdz/ln6dNgntvbmAmr3GhFItuxF79XtF+ZsJ9/8RRb7+pND8UqVo1B49TNzmKDxxaE7hp5ePO4nJ8w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622440710; 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=WqynZrm202cJ+1KbwogFv1gd7AynKLBgDPVt0umzdNg=; b=enq9QgLQChE3FRMkZci2DNhoqJuAnwu8qpSM/1wRleNQFeZ9onFOreFM+n20CarlkpwIczh6wLBggbEhX8IfO4SHj/0uqQfwKQ+YUuPRh5FACYRhj+57Pcp/svi8kSOJ+XDDxvLrz1btawYqGikB0QMQSnEUN1Ta8iY3cFT1n1g= 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 16224407101496.786022247832307; Sun, 30 May 2021 22:58:30 -0700 (PDT) Received: from localhost ([::1]:60976 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lnawW-0001uF-Ev for importer@patchew.org; Mon, 31 May 2021 01:58:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43834) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lnapd-0005Pu-Iu for qemu-devel@nongnu.org; Mon, 31 May 2021 01:51:21 -0400 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]:38451) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lnapb-0003uU-LZ for qemu-devel@nongnu.org; Mon, 31 May 2021 01:51:21 -0400 Received: by mail-pf1-x42a.google.com with SMTP id z26so4200807pfj.5 for ; Sun, 30 May 2021 22:51:19 -0700 (PDT) Received: from spacetanuki.lan ([202.12.244.32]) by smtp.gmail.com with ESMTPSA id b10sm4744058pfi.122.2021.05.30.22.51.17 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 30 May 2021 22:51:18 -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=WqynZrm202cJ+1KbwogFv1gd7AynKLBgDPVt0umzdNg=; b=snEmV1QNyoBNT7PpX8XL0MQ03TpBMqXcOZ9XvW+goZR7tiMdoY8mgjrq2/Ub+fEKNY KMc1f28+AHGliTS32hp20LarQ5A8XIkwK4oAH4WaKul2p8KTK5dbupeZQnWv928VbP5R AdeUobxs42kuTk+BMUFNCdRSPvTNW31+rbbEk= 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=WqynZrm202cJ+1KbwogFv1gd7AynKLBgDPVt0umzdNg=; b=UQVJykyc1m6llJnsrkuAldorIbZYq5rMdz0TtO8iS0gSgV+6L5V2H242Nwvt3ClAbr t6OT/cELt/5I/vaAxi8Nw//6rDrNmhTQMUHxEIIqSo0p6lUDrfs1eEEbmgsjl6l7tKrL HK1P3HIKYe8cto4DbIDP5puumk9my9ZMW5bAk386XB5C6JSErZyoC4aalgXVb7Hnubys VpljHBSZ1LSmkT2c64OT9/HPHWX/oN5QBB4SkgbJayWLHrKtlKoDuOB78kmbAmNL5lco Lf8J24mLQ/U3KQP5prgFL0Oe4XRp1pb+2WKTx4SbgH33nSH3hLt53R2Q5/+UEOqo/Gdb KxNw== X-Gm-Message-State: AOAM533dTQ5hmEjExli72vU/0G3MbcjJYulyTYSAsLTsnRgECYpo2u4U V0wOH1RaiQGj9O8g1+S73/0FyyI2vwpHQg== X-Google-Smtp-Source: ABdhPJyzp2QGV2PnoohXGMnbunHtvrTvB2ikPDvuXjsjiDa3p2h7jPps2yPh9OFpqt1o/hFxJe7q9A== X-Received: by 2002:a62:3106:0:b029:25c:cd66:3be1 with SMTP id x6-20020a6231060000b029025ccd663be1mr15373233pfx.29.1622440278341; Sun, 30 May 2021 22:51:18 -0700 (PDT) From: YAMAMOTO Takashi To: qemu-devel@nongnu.org Cc: YAMAMOTO Takashi , Laurent Vivier Subject: [PATCH v2 09/11] linux-user: Make the qemu detection for /proc/$pid/exe a bit conservative Date: Mon, 31 May 2021 14:50:16 +0900 Message-Id: <20210531055019.10149-10-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::42a; envelope-from=yamamoto@midokura.com; helo=mail-pf1-x42a.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" Perform the qemu special case only when the binary seems the same as our own executable. This is enough for my use case (docker and runc) where the involved qemu binaries are always for the same arch. Signed-off-by: YAMAMOTO Takashi --- linux-user/syscall.c | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 6f9161dbe4..56a3c37d83 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -7986,6 +7986,26 @@ static int open_self_auxv(void *cpu_env, int fd) return 0; } =20 +static int is_same_qemu(const char *their_exe) +{ + struct stat our_st; + struct stat their_st; + + if (stat("/proc/self/exe", &our_st) !=3D 0) { + return 0; + } + if (stat(their_exe, &their_st) !=3D 0) { + return 0; + } + if (our_st.st_dev !=3D their_st.st_dev) { + return 0; + } + if (our_st.st_ino !=3D their_st.st_ino) { + return 0; + } + return 1; +} + static const char *get_exe_path(int pid, char *buf, size_t bufsize) { ssize_t ssz; @@ -7996,6 +8016,20 @@ static const char *get_exe_path(int pid, char *buf, = size_t bufsize) } =20 /* dockerd makes runc invoke dockerd using "/proc/${dockerd_pid}/exe".= */ + + /* + * Check that it's the same qemu binary as ours + * to avoid false positives. + * + * While ideally we want to allow different qemu binaries, + * (E.g. linux-user for a different arch) + * I can't think of any reliable way to detect the cases. + */ + snprintf(buf, bufsize, "/proc/%d/exe", pid); + if (!is_same_qemu(buf)) { + return NULL; + } + snprintf(buf, bufsize, "/proc/%d/cmdline", pid); fd =3D open(buf, O_RDONLY); if (fd =3D=3D -1) { @@ -8033,10 +8067,6 @@ static const char *get_exe_path(int pid, char *buf, = size_t bufsize) } } =20 - /* - * 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 */ --=20 2.21.1 (Apple Git-122.3) From nobody Tue May 14 10:01:23 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=1622440908; cv=none; d=zohomail.com; s=zohoarc; b=goPsyab2TJoB/eHMF90Zy0y1PFgE1EbiO6dAFIgmKaLkG3hw8MKB/Q6nyYJDUt1xxQqCxwjzm3RvIH5za6zVv5osdwexbPTj21xpLERyqmnC6q+nnJTbJRWxEpKz357YI09HOVP16Fx8++ys0m79q8tcSpcEjke7hElQPswO0fc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622440908; 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=5ltY72nVCK5TD5ps8fDCHUS2LTRD8qK8p7I13wFYy/w=; b=IO2Ajp3Gvzqmx38xHnBYoTvQYkYqeO4vsj4I7EeKGSiv9Xlf9szlaRf8WG2hOgDIZiFyKrhTckbgHBxg/2gwtcEtRcjPQDCfmWkR1yM2/Kds85dM+nrLkno2PMxZUG5Wn6qW4A1uvamVuUyqp0TecSYmNQ8bd7wPoxPD87T12h4= 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 1622440908416747.752612536629; Sun, 30 May 2021 23:01:48 -0700 (PDT) Received: from localhost ([::1]:38346 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lnazj-0005kl-D9 for importer@patchew.org; Mon, 31 May 2021 02:01:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43852) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lnapf-0005Zv-Cm for qemu-devel@nongnu.org; Mon, 31 May 2021 01:51:23 -0400 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]:43979) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lnapd-0003vt-Iz for qemu-devel@nongnu.org; Mon, 31 May 2021 01:51:23 -0400 Received: by mail-pl1-x62f.google.com with SMTP id v12so4647285plo.10 for ; Sun, 30 May 2021 22:51:21 -0700 (PDT) Received: from spacetanuki.lan ([202.12.244.32]) by smtp.gmail.com with ESMTPSA id b10sm4744058pfi.122.2021.05.30.22.51.18 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 30 May 2021 22:51:19 -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=5ltY72nVCK5TD5ps8fDCHUS2LTRD8qK8p7I13wFYy/w=; b=FQAQwiLaPrc6M9XYDEcETipLElSsh0a5poFIobF1pvCUcZOTaU1upETL8XguThcMt4 OLo2lo9roYiqoiraX5Unf6NxkuG5EjjS0pTbZSWFIx8KGz0SwXicT5CqN6JWpJTGjTnq cE3UiDWspqONxjqC3p7hrlPfamVuNy8YEYKwA= 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=5ltY72nVCK5TD5ps8fDCHUS2LTRD8qK8p7I13wFYy/w=; b=jYmxZCkP9sn/7W6NXIsV7PoHReCMJnaDxaHFp9E7l0kGL2HNJlwBndq17ru4n7YZkP Q/OiBFVh/KrVSeaD95t7B817FU4DqHT8r/KQh9F1jiNcsCl0AveBgFRKXTmcJkBfCeDp ViuNo/ocdcnWK7MltU+gW8zlpMGMgtJXM7fAl+OZbqluHlXKBaAlNqjKAvtGJ+QgjF3p nPdAI0nAUvCOdB5BCLmDwBHjBkI3KSbGmjYakvwb4oDVm7N+kJjDt9+SKq56vhMR849M 5N8mTB9NDt2eY4UHafZOCmTESGWM2N4mYMuJ+V9+toli0UcPBhN/Of8rQT91NmzEcJro MTng== X-Gm-Message-State: AOAM531EcjxvD57/TqevsKwdQnDa2vprtopxeRMIauSJMxvqvJ0twuiM hkFj/Wec/zqxzzSZ5Pzf9rqMRdp3sXVX9w== X-Google-Smtp-Source: ABdhPJyL2IdKPd2kX9yCMt4rULbyQOwmDnMb8jYzqLBZMljwhiN8Mj+nwv2Gi5ZYkvPYWDzAsZG1xA== X-Received: by 2002:a17:902:6546:b029:101:abf0:d882 with SMTP id d6-20020a1709026546b0290101abf0d882mr11708422pln.73.1622440280120; Sun, 30 May 2021 22:51:20 -0700 (PDT) From: YAMAMOTO Takashi To: qemu-devel@nongnu.org Cc: YAMAMOTO Takashi , Laurent Vivier Subject: [PATCH v2 10/11] linux-user: a crude hack for libcontainer (CLONE_PARENT) [!MERGE] Date: Mon, 31 May 2021 14:50:17 +0900 Message-Id: <20210531055019.10149-11-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::62f; envelope-from=yamamoto@midokura.com; helo=mail-pl1-x62f.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" runc uses clone() with a combination of flags which we don't support. This commit works it around by ignoring CLONE_PARENT. [!MERGE] because this is just a crude hack for the very specific application. Signed-off-by: YAMAMOTO Takashi --- linux-user/syscall.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 56a3c37d83..7645ed36e4 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -6553,6 +6553,8 @@ static int do_fork(CPUArchState *env, unsigned int fl= ags, abi_ulong newsp, pthread_mutex_destroy(&info.mutex); pthread_mutex_unlock(&clone_lock); } else { + flags &=3D ~CLONE_PARENT; /* XXX crude hack for libcontainer. */ + /* if no CLONE_VM, we consider it is a fork */ if (flags & CLONE_INVALID_FORK_FLAGS) { return -TARGET_EINVAL; --=20 2.21.1 (Apple Git-122.3) From nobody Tue May 14 10:01:23 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=1622441041; cv=none; d=zohomail.com; s=zohoarc; b=G5gypQzLqyY+ThW5wXG+gDDKDnodSZEavXqAkUdqs+QV/dQA0VV9RH8psMIY78MXFnXfqIbIaQyKkSuGSxB1q2N9BwNmo2zruQwhrGg8MHXwMnh+A8JZii6bHgoKMWLaFTrM/zh2pBS00gRFV6S4qP1itg4qpN/BiLbEbonipaY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622441041; 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=YGM0A3xANIWNJBynR8wWOFO7oOccgAc2f90y4T8qD0s=; b=jMZCFcMIinZrVGlisQPZZ0MiuM44dqEHOJcDBe61GiBfPDLiRJ1p/MCr3zUGOnY7J5VdwtNBVYDks/PQ/COHe9oNn5jLWtWXJA+3VH5URNbrQDfNyybjJ47fxQjsrW1DtcWjPErIyPKwcq0xaFkgiOYL2BbQ8fVZGmNjhtVUAYM= 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 16224410417650.6529560791838094; Sun, 30 May 2021 23:04:01 -0700 (PDT) Received: from localhost ([::1]:41538 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lnb1s-0007yE-23 for importer@patchew.org; Mon, 31 May 2021 02:04:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43864) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lnaph-0005je-Pg for qemu-devel@nongnu.org; Mon, 31 May 2021 01:51:26 -0400 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]:38851) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lnapf-0003xG-BD for qemu-devel@nongnu.org; Mon, 31 May 2021 01:51:25 -0400 Received: by mail-pj1-x102a.google.com with SMTP id m13-20020a17090b068db02901656cc93a75so272018pjz.3 for ; Sun, 30 May 2021 22:51:22 -0700 (PDT) Received: from spacetanuki.lan ([202.12.244.32]) by smtp.gmail.com with ESMTPSA id b10sm4744058pfi.122.2021.05.30.22.51.20 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 30 May 2021 22:51:21 -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=YGM0A3xANIWNJBynR8wWOFO7oOccgAc2f90y4T8qD0s=; b=lWcbnTCu1XnMF/sAdZu9PEmwL8HywlKELa15k/0rh/ijHGQjFohDZugWqxMnDVSNDX zyO19G+NGe/9KuuMyQN40eQMd5TtWWwVTVSYnvRQX6WrfLX6nO3OJ7g3rpRmK6gO7pp3 BvGdRrEQrwecKf28PW8B1rl/yK7FFLRDMiE5Y= 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=YGM0A3xANIWNJBynR8wWOFO7oOccgAc2f90y4T8qD0s=; b=bSXsZ0qQByoM81QQ8IMQzXJFYUSnEkvuot4b8GLMUCiPrCpfex1Yykwcizr0+2drK2 17EWv6fy5mH1qcvtLpkIzzStQEWEUTM3ZsMQF7steP4YCgextbFMUVWGPy3NPVjksGxO RVlda3QISyfYN6G99TCafWKNsciUJQwagEgmCii2XAa2H8Rgk1M/zIHd+WO7ro1E8QfL h+nR36XcDnKW47Q7uuiXaFbNQxRc6kVozfSJCZc79K5/m66S8MfR4CU+TYUJkmcXPpGi mvIONgwvwkXoODmJTcO1+isXUenzZq/lYWC+ts7gVFGhrzlAYw25DItEtka+NEl2+fGJ cKAQ== X-Gm-Message-State: AOAM530BkiM6OE+dQVavmwAHyRXwHLLaztRCc5ZzpOUnbTdYyL1Skb8z x6keZMF3dqA9VPzWFsaoHRFQgi6pJbPO1Q== X-Google-Smtp-Source: ABdhPJyLpSjjwl6iUoESmDC4ZQT5BH1cefRcv1jHgk8e/4nB1my5tnNOju/b6ucDQRSeBzJQhqPvbA== X-Received: by 2002:a17:902:9f83:b029:f6:5c3c:db03 with SMTP id g3-20020a1709029f83b02900f65c3cdb03mr19260040plq.2.1622440281902; Sun, 30 May 2021 22:51:21 -0700 (PDT) From: YAMAMOTO Takashi To: qemu-devel@nongnu.org Cc: YAMAMOTO Takashi , Laurent Vivier Subject: [PATCH v2 11/11] linux-user: always assume preserve_argv0 for now [!MERGE] Date: Mon, 31 May 2021 14:50:18 +0900 Message-Id: <20210531055019.10149-12-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::102a; envelope-from=yamamoto@midokura.com; helo=mail-pj1-x102a.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" Just because the kernel I'm using is not new enough. [!MERGE] because this is specific to my environment and would break others. Signed-off-by: YAMAMOTO Takashi --- linux-user/main.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/linux-user/main.c b/linux-user/main.c index be604a84f9..a3d8b7788f 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -726,7 +726,38 @@ int main(int argc, char **argv, char **envp) /* * get binfmt_misc flags */ +#if 0 preserve_argv0 =3D !!(qemu_getauxval(AT_FLAGS) & AT_FLAGS_PRESERVE_ARG= V0); +#else +/* + * my kernel doesn't have the following commit. this is a crude workaroud. + +commit 2347961b11d4079deace3c81dceed460c08a8fc1 +Author: Laurent Vivier +Date: Tue Jan 28 14:25:39 2020 +0100 + + binfmt_misc: pass binfmt_misc flags to the interpreter + + It can be useful to the interpreter to know which flags are in use. + + For instance, knowing if the preserve-argv[0] is in use would + allow to skip the pathname argument. + + This patch uses an unused auxiliary vector, AT_FLAGS, to add a + flag to inform interpreter if the preserve-argv[0] is enabled. + + Note by Helge Deller: + The real-world user of this patch is qemu-user, which needs to know + if it has to preserve the argv[0]. See Debian bug #970460. + + Signed-off-by: Laurent Vivier + Reviewed-by: YunQiang Su + URL: http://bugs.debian.org/970460 + Signed-off-by: Helge Deller + + */ + preserve_argv0 =3D true; +#endif =20 /* * Manage binfmt-misc preserve-arg[0] flag --=20 2.21.1 (Apple Git-122.3)