From nobody Sun May 19 00:47:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1565186079; cv=none; d=zoho.com; s=zohoarc; b=UG4wcY18OeV7CIwQXZJoHX7gYyDM1C5UTN4/DxcxHdwKG775IdDq1BZtvkxrP8ft9WC6SbyGfYE/Y/V3Uiwhkmr3IxveKqqwriNFeAcKQLj077yA2FVWfEYEeNV18c3ZfdMOHFpIRx1UrhtbKPW0Cef+8hWirvbGWVWk6U1wJvA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565186079; 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:ARC-Authentication-Results; bh=c3RYPrGsyKUm1hzPu5xtj1FFwZnff4pdTDSn1fUGhQE=; b=lvczoN+0uth5+ILp+RcLvfNeM6wKNMm78iNU+/39YxV00MMlGqQcnvIxc0D65Y/F57quELc8tZO81fCIRRQxFFdaMviq9APLMf0mJlDSS8DdbqvTsgbZZvlc+3l/llvL9RQ52oR/uzI8dz9EwMVcIiWtrOvfDGySyTIARVVOceg= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1565186079027405.1133441664505; Wed, 7 Aug 2019 06:54:39 -0700 (PDT) Received: from localhost ([::1]:41468 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hvMOk-0000T5-4G for importer@patchew.org; Wed, 07 Aug 2019 09:54:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60798) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hvMLi-0006Nk-TP for qemu-devel@nongnu.org; Wed, 07 Aug 2019 09:51:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hvMLh-0000wn-W5 for qemu-devel@nongnu.org; Wed, 07 Aug 2019 09:51:30 -0400 Received: from galois.linutronix.de ([2a0a:51c0:0:12e:550::1]:42932) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hvMLh-0000nv-Qc for qemu-devel@nongnu.org; Wed, 07 Aug 2019 09:51:29 -0400 Received: from [5.158.153.55] (helo=clara.guests.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1hvMLX-0002b2-Jk; Wed, 07 Aug 2019 15:51:19 +0200 From: dion@linutronix.de To: qemu-devel@nongnu.org Date: Wed, 7 Aug 2019 15:54:58 +0200 Message-Id: <20190807135458.32440-2-dion@linutronix.de> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190807135458.32440-1-dion@linutronix.de> References: <20190807135458.32440-1-dion@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1, SHORTCIRCUIT=-0.0001 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 2a0a:51c0:0:12e:550::1 X-Mailman-Approved-At: Wed, 07 Aug 2019 09:54:14 -0400 Subject: [Qemu-devel] [PATCH 1/1] linux-user: Handle /proc/self/exe in syscall execve 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: , Cc: Olivier Dion , john.ogness@linutronix.de Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Olivier Dion If not handled, QEMU will execve itself instead of the emulated process. This could result in potential security risk. Signed-off-by: Olivier Dion --- linux-user/syscall.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 8367cb138d..1a475896a6 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -7504,7 +7504,18 @@ 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)); + { + const char *pathname =3D p; + char real_path[PATH_MAX]; + if (is_proc_myself(pathname, "exe")) { + if (NULL =3D=3D realpath(exec_path, real_path)) { + ret =3D get_errno(-1); + goto execve_efault; + } + pathname =3D real_path; + } + ret =3D get_errno(safe_execve(pathname, argp, envp)); + } unlock_user(p, arg1, 0); =20 goto execve_end; --=20 2.22.0