From patchwork Wed Aug 7 13:54:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: dion@linutronix.de X-Patchwork-Id: 11082203 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 769BA14E5 for ; Wed, 7 Aug 2019 13:54:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 606C426CFF for ; Wed, 7 Aug 2019 13:54:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 54C3128780; Wed, 7 Aug 2019 13:54:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id F07BA26CFF for ; Wed, 7 Aug 2019 13:54:31 +0000 (UTC) Received: from localhost ([::1]:41468 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hvMOd-0000T5-89 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 07 Aug 2019 09:54:31 -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 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 = get_errno(safe_execve(p, argp, envp)); + { + const char *pathname = p; + char real_path[PATH_MAX]; + if (is_proc_myself(pathname, "exe")) { + if (NULL == realpath(exec_path, real_path)) { + ret = get_errno(-1); + goto execve_efault; + } + pathname = real_path; + } + ret = get_errno(safe_execve(pathname, argp, envp)); + } unlock_user(p, arg1, 0); goto execve_end;