From nobody Sun May 19 03:02:53 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; dkim=fail; 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=1568651760; cv=none; d=zoho.com; s=zohoarc; b=gmmJiAcfoFNiCk4qkNzRf3lMmObpL1Eh7z3yVJfYYUHtI8Y9j0jU01o1edgHCyJmySvGMMVIj5UcrG5oAUzBrVeXXLerxadLZawzgSQ+jWaxiYObqyJW8B1VITI2UCBRbj4FbIipR20WwOMu7WbmMjbOsK7v9xgpVHJC5ff0qtY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568651760; 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=/hSMpdkHAV+GRRFXHYbEqSBWoOpNrQe7qkJthuSQHIs=; b=olz+GPvGkNAPezuOA4tMhKEgfr6MhsNutp8BDxTIy6AYRSjUvnb+mR1TanTSYSs6y3mMEnknt5jtoX9mfIkvRIZm5h/2BStTtJLf+EW2zwteImxsD6Nixr1VJ9fKgiSvpPPB5M3Tshy26jnoY/pzahCfJWbJr8xKkBehwY1K0tw= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; 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 1568651759987139.86148487440835; Mon, 16 Sep 2019 09:35:59 -0700 (PDT) Received: from localhost ([::1]:36996 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i9tym-0001vi-Ef for importer@patchew.org; Mon, 16 Sep 2019 12:35:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36657) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i9tMb-0007yl-RI for qemu-devel@nongnu.org; Mon, 16 Sep 2019 11:56:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i9tMZ-00047k-8t for qemu-devel@nongnu.org; Mon, 16 Sep 2019 11:56:29 -0400 Received: from smtp.polymtl.ca ([132.207.4.11]:47308) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i9tMZ-00045z-2F for qemu-devel@nongnu.org; Mon, 16 Sep 2019 11:56:27 -0400 Received: from clara.localdomain (modemcable059.101-200-24.mc.videotron.ca [24.200.101.59]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id x8GFtwgY006121 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Mon, 16 Sep 2019 11:56:18 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca x8GFtwgY006121 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=polymtl.ca; s=default; t=1568649379; bh=/hSMpdkHAV+GRRFXHYbEqSBWoOpNrQe7qkJthuSQHIs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bR9mu/FJAJGWMgWeMw7baUP6ePWd7ZOe9l2h8vomZGAqDCynhHjwjCX5j5/+h/Tfr T71cLNgQlH2ud+YsEOWO0+zaWpAx21r0LdUdAvdao7QsXhShBnJWdgX+GXTj3pHO+e uNqMb4pz+wPICaCYO4ZtVNA/b/OXWu559klJkYSo= From: Olivier Dion To: qemu-devel@nongnu.org Date: Mon, 16 Sep 2019 11:55:45 -0400 Message-Id: <20190916155545.29928-2-olivier.dion@polymtl.ca> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190916155545.29928-1-olivier.dion@polymtl.ca> References: <20190807135458.32440-1-dion@linutronix.de> <20190916155545.29928-1-olivier.dion@polymtl.ca> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Poly-FromMTA: (modemcable059.101-200-24.mc.videotron.ca [24.200.101.59]) at Mon, 16 Sep 2019 15:55:58 +0000 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 132.207.4.11 Subject: [Qemu-devel] [PATCH v2 1/1] 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" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" If not handled, QEMU will execve itself instead of the emulated process. The function do_openat already solves the /proc/self/exe problem, so we can use it to get the executable file descriptor. We then make a safe call to execveat. Note that safe_execve has been replaced by safe_execveat, since the former is now useless. Signed-off-by: Olivier Dion --- linux-user/syscall.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index e2af3c1494..68340bcb67 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -736,7 +736,7 @@ safe_syscall4(pid_t, wait4, pid_t, pid, int *, status, = int, options, \ struct rusage *, rusage) safe_syscall5(int, waitid, idtype_t, idtype, id_t, id, siginfo_t *, infop,= \ int, options, struct rusage *, rusage) -safe_syscall3(int, execve, const char *, filename, char **, argv, char **,= envp) +safe_syscall5(int, execveat, int, dirfd, const char *, pathname, char **, = argv, char **, envp, int, flags) safe_syscall6(int, pselect6, int, nfds, fd_set *, readfds, fd_set *, write= fds, \ fd_set *, exceptfds, struct timespec *, timeout, void *, sig) safe_syscall5(int, ppoll, struct pollfd *, ufds, unsigned int, nfds, @@ -7507,8 +7507,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)); - unlock_user(p, arg1, 0); + { + int execfd =3D get_errno(do_openat(cpu_env, AT_FDCWD, p, O= _PATH, 0)); + unlock_user(p, arg1, 0); + if (is_error(execfd)) { + ret =3D execfd; + goto execve_end; + } + ret =3D get_errno(safe_execveat(execfd, "", + argp, envp, + AT_EMPTY_PATH)); + close(execfd); + } =20 goto execve_end; =20 --=20 2.23.0