From patchwork Sun May 19 20:36:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 164511 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp4789355ili; Sun, 19 May 2019 13:56:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqxVLs930JIkj1d4wjVAarm+9ta/bjspsLgvBwh9NRckbySjsUh47AscZGpPiqPF5SxnfNGW X-Received: by 2002:a17:906:c4f:: with SMTP id t15mr12703038ejf.190.1558299390653; Sun, 19 May 2019 13:56:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558299390; cv=none; d=google.com; s=arc-20160816; b=aV/5Jff8bDvCpTI7NJssqUkNfsKiBdC9ra5bdBpV9L8z76c8HPBi8VE6snPjI/vUED nk/20WDWUmvalVnYd5JxxdsFQfo3lInRWE0wRIzcsXahcsJ8TFrLN1EWYWgtHrprmyJY vBI5JVWsQrLHY7dy1H4OkJthuoXcJ0wBrTu1baUz1Sqz4ND67kLpQG1jhEwgJED0iwJL 9zEogRKYv+TyL4K5orCJWGLFNyWK3axyS+FLeUjFiw3B/dZi/qGaDaWB3F5TNX3iScFr SMeojwgv61jR0GytPwoAa4ItXpVRRU+5J1ccaytZx9VfQ9ppMKSTV41pLK9FhuaI3CN3 E1Tg== 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=CUstonr/slKQsOp95jk6g1WJFMbRRVPH2v9t0llMUoM=; b=H/Ah7KmrHp4VhpEbAOEA9IQFi23qc5CsYvzr/s5T4SYsZRKx+WUmLqJMYjIbduEBc7 aPwM5qKqBnze5za0Jzh8r/WZq1AwHt7vVOV++Jv4hdRPSZgDv9lQx/urQCECZ/hRupOZ X2tgEPmWlem4QDBbeZmPmuwrntele/02XtUasT93jMIKWboYnc0fc/7ECf8YsLqPmK5X NhlT4RZZ+L4e19L/HEvNLhgzrxBqI5zlzGkgd103A1CNCf6tuL6jUZnQCEQpGUyUkESl VvtNcCRYEqkcEgX95oFrxyav3EW1PoYJmtHEyRlbGAIYTH2HFL5/qKdPnEV4TZP461rw kohA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=gztWdzs8; 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 n5si3100619ejc.359.2019.05.19.13.56.30 for (version=TLS1 cipher=AES128-SHA bits=128/128); Sun, 19 May 2019 13:56:30 -0700 (PDT) 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=gztWdzs8; 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]:53382 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hSSr7-0001sT-Hn for patch@linaro.org; Sun, 19 May 2019 16:56:29 -0400 Received: from eggs.gnu.org ([209.51.188.92]:50452) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hSSZH-0003MX-Mo for qemu-devel@nongnu.org; Sun, 19 May 2019 16:38:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hSSZG-0003xg-Jq for qemu-devel@nongnu.org; Sun, 19 May 2019 16:38:03 -0400 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]:45523) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hSSZG-0003wx-D8 for qemu-devel@nongnu.org; Sun, 19 May 2019 16:38:02 -0400 Received: by mail-pg1-x542.google.com with SMTP id i21so5720909pgi.12 for ; Sun, 19 May 2019 13:38:02 -0700 (PDT) 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=CUstonr/slKQsOp95jk6g1WJFMbRRVPH2v9t0llMUoM=; b=gztWdzs8chvklwyvFRigzSUIlJ58+409oA0pFmMX6kvHD9UoGLi2aYp4xSZ/QLsCT/ i5zUc8HPJWhG/PYEU6ecEV5qVWGkWb9pbEC5/cEDUD7ZOm4u4YuFAX229/1RZSJzXlN4 0GTMknJR+PtwwAnChPiQHqeT0Xs6g5tadTlFrvpPk/gvRDjv0c3FQnaKNrIXllJbI4ez Tr/8g7PLp8/nH1AKxCC95sYOPwiouWzUjTnxleY2DHDoa2zsgC9iFzkMmI2EesYmKWU8 5udxp5Mrm2YpXNK3LNlTIPtzv5cOlfGq8nohVMkQ8oM0rrp5fsjVRaO0Qt/Dvl92AO2r 3T1A== 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=CUstonr/slKQsOp95jk6g1WJFMbRRVPH2v9t0llMUoM=; b=RiFXru9AUxYSzsxWT8S9aZDK8eru46tGarQW8GY0uMhLNBB+m9iY12Gz2oqrc9aCOq wU2DfyE7ULReTQ30Vc6YSfwYeqckNSpLcYmKu5hjfvDfpon6CErd/BfC7FP/jlw7D+0C YmKoGSbGrzOefrbXI2w8WowAuTwZyso0kTlZDPG+mBgUaMYMV2AhytqkCrsbO/S6nodR CM/maWuUj4SvXahaP+AJ3hDbzUDH0IFwQo8OeeQvYfQa0zkAcgwulrcEpTVd5PO48eV/ Uh06xRNuwuI36YRotM3lilCVJ6VtbXVJnNYLeUCQ1sQuzYMN5nuAzKaoQiyR4PAsVVDR Yssw== X-Gm-Message-State: APjAAAUTdpwAVxoS5+QEMaUm3vdcWfZnT/9WK835ehJfAH50Jkd5Sbal L2D29lzdXQ9KKFlG8ENrvjytQfBsw4A= X-Received: by 2002:a63:4c15:: with SMTP id z21mr27665675pga.395.1558298281198; Sun, 19 May 2019 13:38:01 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id i7sm11397448pfo.19.2019.05.19.13.37.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 19 May 2019 13:37:59 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Sun, 19 May 2019 13:36:36 -0700 Message-Id: <20190519203726.20729-25-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190519203726.20729-1-richard.henderson@linaro.org> References: <20190519203726.20729-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::542 Subject: [Qemu-devel] [PATCH v7 24/74] 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.1 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 66ad768551..fd114d1f03 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 a00df1162f..affcd81273 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -672,7 +672,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 39e5c5b1aa..c6bb475728 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