From patchwork Fri Jan 18 21:30:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 156055 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3732216jaa; Fri, 18 Jan 2019 13:38:39 -0800 (PST) X-Google-Smtp-Source: ALg8bN42oT97eu3Ua6CBpHXIKpZv22nXyLnBtgzt4Tn+NIUt35ia+3e8cpM8Iwc52XW2qAafZ/hu X-Received: by 2002:a1c:90cb:: with SMTP id s194mr16603970wmd.57.1547847518983; Fri, 18 Jan 2019 13:38:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547847518; cv=none; d=google.com; s=arc-20160816; b=qPLX+hw3+ObAm4PYfOJTzdD0Suugbh1k97+79w1W1/eIVBMebEhuw579+KrkVw7+Ia ZJPswbGAW88/Hh8n+MPVTrU7r+xVVFuUBF53Wu2HS6TumUPbN88ceSAhj2KJG2s9cKX4 BAtXkDiQnwRqeuNNdp8kxtrvWRwMe2yCLBkXEovwCSdsboFRFc2BPAKI+lOOLF3Vvytk 25y3ejoJf1yst/NE2NWWiAlo0BxGl+6Q/Qr472+sFrFzd1ogi6pvcFsL/5j29IbW999J 1x1kNDcYLStUiRIXZC/5u6vfqMc4D9HkaHjhNKbyVJZSysO3oyaCtOKODdILT1IGZNg7 3QhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=SMMAnvYSaJFQPxNPvJ9sKrp9BWoGMbm6WSf/IZZEqBk=; b=N2tMWmu9DHQWGgLqcFUZb9Xh8BvRoiBeyGwxviRaqcCN0nAdzf1SUF9VU1NF9uBr93 AofGsN1Ah/83UJZQCXE6YlMrrf+OZOFJYHhajbjzrPW1mBJNQ7gcX+MDgOXHLkEPT7vt SzNEcRGFk0yQuEJqQcANUYw22PWcfxTFnPb8Q1N1Q1Ej9IzOhblA2kx8klPCM+Q5nwIv Cp0lczd0VTzwJtVPtuatLseVwwoW/5LmdXViU8QJkh3Xsqsk7AYqHwxWWG/LOWp0ciL3 d9T/ABlYNnBhGcRe80LYZN5t38jlULRe2FazlnvCa0Rsh++E6lemQnbhwkk2aGurXTx1 Vrkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="ayx2SJw/"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id s126si27971898wme.154.2019.01.18.13.38.38 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 18 Jan 2019 13:38:38 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="ayx2SJw/"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:47472 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gkbqX-0001bW-VZ for patch@linaro.org; Fri, 18 Jan 2019 16:38:38 -0500 Received: from eggs.gnu.org ([209.51.188.92]:56111) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gkbkh-0005Op-Mn for qemu-devel@nongnu.org; Fri, 18 Jan 2019 16:32:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gkbkd-0004tD-QN for qemu-devel@nongnu.org; Fri, 18 Jan 2019 16:32:35 -0500 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]:38208) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gkbkd-0004oi-Ct for qemu-devel@nongnu.org; Fri, 18 Jan 2019 16:32:31 -0500 Received: by mail-pf1-x441.google.com with SMTP id q1so7203420pfi.5 for ; Fri, 18 Jan 2019 13:32:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=SMMAnvYSaJFQPxNPvJ9sKrp9BWoGMbm6WSf/IZZEqBk=; b=ayx2SJw/eNyyLQfY/KBNKHKQC4LGeUPls6JB0538aL+esqd39unFc535e7O1WPljGK paObudBLPWUFwRLotcdghcX9vnEmTTb0M2DCHsFvhv3x9uBuRn1aaeEu/YH8lOlqCmd6 KO3CaXU6R0RCdn1Q4PscWl/ZfQIlGryzI+olg= 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; bh=SMMAnvYSaJFQPxNPvJ9sKrp9BWoGMbm6WSf/IZZEqBk=; b=mpL+g9Xbweq4r1l2V5FxmWqZ09+giow6C8QiVt4IT9U5c1LvtOd3fMoGQLt3KzO+6B 2jpufdV6MRhQ8DEtnQG/kHwxDpROZKAylvCbss/55a1pieNc4ebcNYRwR+D9CkjQU5bB uAgB6UuDmO+3kok1EDPgWUwRL5mZhIwDPBpHloA83z4jAg3fwFLfG3Gzt92rCnyG8qld iQvplXlRkc0la3Jqf9ixkgSPxzricl4Nes+cd5o2/jcRirCht/rEYNW0D6jfi3xs1qfe wd25prFmr2SLs6CXFXuuHbxSlnYGHTKrH+PJy3rZ7H29W0UXd9Lypf/WSae/4FOMk1Zn KifA== X-Gm-Message-State: AJcUukfHDZeX3vI5dLDl5cDl8dJ3OIgJFLlIUd75JsN/2iV0pQwBtU2q bl7oqg/YUQ2cHLpKy396Kx1tB90hMsk= X-Received: by 2002:a63:ca02:: with SMTP id n2mr19516194pgi.187.1547847146607; Fri, 18 Jan 2019 13:32:26 -0800 (PST) Received: from cloudburst.twiddle.net ([2001:8000:10e0:a000:c673:a6b6:fdef:1933]) by smtp.gmail.com with ESMTPSA id v12sm5833667pgg.41.2019.01.18.13.32.24 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 18 Jan 2019 13:32:25 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Sat, 19 Jan 2019 08:30:58 +1100 Message-Id: <20190118213122.22865-25-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190118213122.22865-1-richard.henderson@linaro.org> References: <20190118213122.22865-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::441 Subject: [Qemu-devel] [PATCH v6 25/49] linux-user: Implement execveat X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" A trivial extension to our current execve implementation to support the new(ish) syscall. Signed-off-by: Richard Henderson --- linux-user/syscall-defs.h | 1 + linux-user/syscall-proc.inc.c | 19 ++++++++++++++----- linux-user/syscall.c | 3 ++- linux-user/strace.list | 3 --- 4 files changed, 17 insertions(+), 9 deletions(-) -- 2.17.2 diff --git a/linux-user/syscall-defs.h b/linux-user/syscall-defs.h index 58fef48666..392bd1579c 100644 --- a/linux-user/syscall-defs.h +++ b/linux-user/syscall-defs.h @@ -26,6 +26,7 @@ SYSCALL_DEF(creat, ARG_STR, ARG_MODEFLAG); #endif SYSCALL_DEF(exit, ARG_DEC); SYSCALL_DEF(execve, ARG_STR, ARG_PTR, ARG_PTR); +SYSCALL_DEF(execveat, ARG_ATDIRFD, ARG_STR, ARG_PTR, ARG_PTR, ARG_ATFLAG); #ifdef TARGET_NR_fork SYSCALL_DEF(fork); #endif diff --git a/linux-user/syscall-proc.inc.c b/linux-user/syscall-proc.inc.c index 552aea60ae..699370c290 100644 --- a/linux-user/syscall-proc.inc.c +++ b/linux-user/syscall-proc.inc.c @@ -269,14 +269,13 @@ SYSCALL_IMPL(clone) return do_clone(cpu_env, arg1, arg2, arg3, arg4, arg5); } -SYSCALL_IMPL(execve) +static abi_long do_execveat(int dirfd, abi_ulong guest_path, + abi_ulong guest_argp, abi_ulong guest_envp, + int flags) { char **argp, **envp; int argc, envc; abi_ulong gp; - abi_ulong guest_path = arg1; - abi_ulong guest_argp = arg2; - abi_ulong guest_envp = arg3; abi_ulong addr; char **q, *p; int total_size = 0; @@ -356,7 +355,7 @@ SYSCALL_IMPL(execve) * before the execve completes and makes it the other * program's problem. */ - ret = get_errno(safe_execve(p, argp, envp)); + ret = get_errno(safe_execveat(dirfd, p, argp, envp, flags)); unlock_user(p, guest_path, 0); execve_free: @@ -379,6 +378,16 @@ SYSCALL_IMPL(execve) return ret; } +SYSCALL_IMPL(execve) +{ + return do_execveat(AT_FDCWD, arg1, arg2, arg3, 0); +} + +SYSCALL_IMPL(execveat) +{ + return do_execveat(arg1, arg2, arg3, arg4, arg5); +} + SYSCALL_IMPL(exit) { CPUState *cpu = ENV_GET_CPU(cpu_env); diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 9b5b2eb7f1..3a027651e3 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -682,7 +682,8 @@ 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 *, filename, + char **, argv, char **, envp, int, flags) safe_syscall6(int, pselect6, int, nfds, fd_set *, readfds, fd_set *, writefds, \ fd_set *, exceptfds, struct timespec *, timeout, void *, sig) safe_syscall5(int, ppoll, struct pollfd *, ufds, unsigned int, nfds, diff --git a/linux-user/strace.list b/linux-user/strace.list index 8bc3fe6088..202bfa8f9e 100644 --- a/linux-user/strace.list +++ b/linux-user/strace.list @@ -139,9 +139,6 @@ #ifdef TARGET_NR_execv { TARGET_NR_execv, "execv" , NULL, print_execv, NULL }, #endif -#ifdef TARGET_NR_execveat -{ TARGET_NR_execveat, "execveat" , NULL, NULL, NULL }, -#endif #ifdef TARGET_NR_exec_with_loader { TARGET_NR_exec_with_loader, "exec_with_loader" , NULL, NULL, NULL }, #endif