From patchwork Tue Jun 12 00:51:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 138274 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp4702090lji; Mon, 11 Jun 2018 17:59:28 -0700 (PDT) X-Google-Smtp-Source: ADUXVKL12DRJ17IY72vL+/RkFIJTeRZ5wqkuqlbCokgvClaEJn2Wl6FQDpSDVm8wD8+fROA1DE5y X-Received: by 2002:a37:1563:: with SMTP id f96-v6mr1425946qkh.150.1528765168443; Mon, 11 Jun 2018 17:59:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528765168; cv=none; d=google.com; s=arc-20160816; b=wa5+JlgNg5sl5R06GSbfFP8bUhZElDhSBoZC437dP5UHP2K06hZXmvBHU4X4L8BH2P EGk5xfobHHx6kl+wyQu8zA92NaVr3bK+WVRBrAmsutgUSxRciGDBbPl3hwiXMyqi8Xze 19nLuyiFhYiJ6zNaAzxLik+y8FUocvi0kGVf/aD3SnTeWEq8dKP+1dfYR70nqc94cbB9 jykzOBc55jmNODOiLgqQHa6o3FA6BG+M5xsUIqhmSiAdoSAAX18Chid97t+wGSTs4sb9 nI5CEHAgkieySISlzSWghHskKcFsj9IITj4CrHEtgZ+1qfkTJyg9Fl+PnaEMK+YAgjFU iz7g== 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:arc-authentication-results; bh=GKKkxlgC1wWPWC9wwIoQoaEvJ0CAXaQlDHYdEdiafpk=; b=JhwN71a7O2eob4pDsFbjfLvEVraz1UBiMH7VwKDfPJKCTLBgDE4ITP/CLVqElYacLu w1nNZkZ2IVn7ZD9COP2f4fMUTn3JL9h40ERJ2d4lne76G56At1e5iZI2oA0LrtrDNUEz lO/wpdC+licN7R8hEbLDC1jy77er3HrAK6wekrMnPzcEnB+5FgcoL9qv0mmqhGMWW97m KJvE4ohbH4plQsk21IyZZZx+cZHLDQkeE2u4vSti7aavUjQA40l+Qm1HG95nskmjYudx s7AGK0F+fRijHTu7/m+gxnUfjrl86ivxxVwVBsqgJ8HC/VRV5GloXQb8/HnZkKH79EDY ttfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=UQ+IuHZI; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id r51-v6si2195903qvr.205.2018.06.11.17.59.28 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 11 Jun 2018 17:59:28 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=UQ+IuHZI; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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 ([::1]:52040 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSXeh-00031l-PJ for patch@linaro.org; Mon, 11 Jun 2018 20:59:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59406) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSXXx-0005OD-WE for qemu-devel@nongnu.org; Mon, 11 Jun 2018 20:52:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fSXXw-0007kF-Hd for qemu-devel@nongnu.org; Mon, 11 Jun 2018 20:52:30 -0400 Received: from mail-pl0-x241.google.com ([2607:f8b0:400e:c01::241]:46583) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fSXXw-0007j6-8T for qemu-devel@nongnu.org; Mon, 11 Jun 2018 20:52:28 -0400 Received: by mail-pl0-x241.google.com with SMTP id 30-v6so13299721pld.13 for ; Mon, 11 Jun 2018 17:52:28 -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=GKKkxlgC1wWPWC9wwIoQoaEvJ0CAXaQlDHYdEdiafpk=; b=UQ+IuHZIJfJaDPObPWz5ZG0floKyKj8UB8YgG4dXtj4eemPB9Ur7lmSornz1tYL4Re 33X49wvRqji95xeNVVs/iOcLcZK6KO6cq1g0ju2d2/+dsSsNN2B4EBoGfTbXqER8oNI9 /DlMd3wp4lEy1MZxGUCTl51tzoa7nygQcOSh8= 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=GKKkxlgC1wWPWC9wwIoQoaEvJ0CAXaQlDHYdEdiafpk=; b=quzFXoEJCjwDZ3Sie4q4phU0OeFBfkieZIupoj+hP5t+BFjZ3difBp+7+Xwm2M+3P8 Fe430P0vGjnYNCLPJEFLaRsKrGdJFlVJvTo0arpEYBK0kITOiHrvXdMiJ4EOov8yOwq5 PaNihfZSqteWNPzGWm3U48iSfvKWnfllgP1gY5Mw6mx0965BvjEPUgrU0UMOwyaFMQKl 1X4yA4wPaPhw0HQx7MzDIxNxBESGgLtuO+s6MnApgQibwIZp+VErSzRhMouWo8u1alns wiz1YmR31Wg44hF2dTMi1KJ0JgBclwvXNK46v+AFh9wfZaf7xeu+QRrddfyu7szPwBsp xVMA== X-Gm-Message-State: APt69E0lhyIzR4fntwo3vQCPwHaLLXImE/V0bFr/WQvvloP0cbPv+Ju3 qresBlktjWCH8RBvZaLZOxgJnzWbvgQ= X-Received: by 2002:a17:902:bd8f:: with SMTP id q15-v6mr1497020pls.161.1528764746957; Mon, 11 Jun 2018 17:52:26 -0700 (PDT) Received: from cloudburst.twiddle.net (rrcs-173-198-77-219.west.biz.rr.com. [173.198.77.219]) by smtp.gmail.com with ESMTPSA id l26-v6sm43362802pgn.55.2018.06.11.17.52.25 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 11 Jun 2018 17:52:26 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 11 Jun 2018 14:51:42 -1000 Message-Id: <20180612005145.3375-17-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180612005145.3375-1-richard.henderson@linaro.org> References: <20180612005145.3375-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c01::241 Subject: [Qemu-devel] [PATCH v3 16/19] linux-user: Split out name_to_handle_at, open_by_handle_at 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: peter.maydell@linaro.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Richard Henderson --- linux-user/syscall.h | 1 + linux-user/strace.c | 5 +- linux-user/syscall.c | 98 ---------------------------------- linux-user/syscall_file.c | 88 ++++++++++++++++++++++++++++++ linux-user/gen_syscall_list.py | 2 + linux-user/strace.list | 3 -- 6 files changed, 95 insertions(+), 102 deletions(-) -- 2.17.1 diff --git a/linux-user/syscall.h b/linux-user/syscall.h index a157e25bba..217267409b 100644 --- a/linux-user/syscall.h +++ b/linux-user/syscall.h @@ -52,6 +52,7 @@ typedef enum { /* These print as sets of flags. */ ARG_ATDIRFD, + ARG_ATFLAG, ARG_MODEFLAG, ARG_OPENFLAG, diff --git a/linux-user/strace.c b/linux-user/strace.c index 1ae0057365..4240ea649a 100644 --- a/linux-user/strace.c +++ b/linux-user/strace.c @@ -780,7 +780,7 @@ UNUSED static struct flags access_flags[] = { FLAG_END, }; -UNUSED static struct flags at_file_flags[] = { +static struct flags const at_file_flags[] = { #ifdef AT_EACCESS FLAG_GENERIC(AT_EACCESS), #endif @@ -2693,6 +2693,9 @@ static void print_syscall_def1(const SyscallDef *def, int64_t args[6]) case ARG_ATDIRFD: len = add_atdirfd(b, rest, arg); break; + case ARG_ATFLAG: + len = add_flags(b, rest, at_file_flags, arg, false); + break; case ARG_MODEFLAG: len = add_flags(b, rest, mode_flags, arg, true); break; diff --git a/linux-user/syscall.c b/linux-user/syscall.c index cdc9787240..8c7dd3049e 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -7151,93 +7151,6 @@ static int do_futex(target_ulong uaddr, int op, int val, target_ulong timeout, return -TARGET_ENOSYS; } } -#if defined(TARGET_NR_name_to_handle_at) && defined(CONFIG_OPEN_BY_HANDLE) -static abi_long do_name_to_handle_at(abi_long dirfd, abi_long pathname, - abi_long handle, abi_long mount_id, - abi_long flags) -{ - struct file_handle *target_fh; - struct file_handle *fh; - int mid = 0; - abi_long ret; - char *name; - unsigned int size, total_size; - - if (get_user_s32(size, handle)) { - return -TARGET_EFAULT; - } - - name = lock_user_string(pathname); - if (!name) { - return -TARGET_EFAULT; - } - - total_size = sizeof(struct file_handle) + size; - target_fh = lock_user(VERIFY_WRITE, handle, total_size, 0); - if (!target_fh) { - unlock_user(name, pathname, 0); - return -TARGET_EFAULT; - } - - fh = g_malloc0(total_size); - fh->handle_bytes = size; - - ret = get_errno(name_to_handle_at(dirfd, path(name), fh, &mid, flags)); - unlock_user(name, pathname, 0); - - /* man name_to_handle_at(2): - * Other than the use of the handle_bytes field, the caller should treat - * the file_handle structure as an opaque data type - */ - - memcpy(target_fh, fh, total_size); - target_fh->handle_bytes = tswap32(fh->handle_bytes); - target_fh->handle_type = tswap32(fh->handle_type); - g_free(fh); - unlock_user(target_fh, handle, total_size); - - if (put_user_s32(mid, mount_id)) { - return -TARGET_EFAULT; - } - - return ret; - -} -#endif - -#if defined(TARGET_NR_open_by_handle_at) && defined(CONFIG_OPEN_BY_HANDLE) -static abi_long do_open_by_handle_at(abi_long mount_fd, abi_long handle, - abi_long flags) -{ - struct file_handle *target_fh; - struct file_handle *fh; - unsigned int size, total_size; - abi_long ret; - - if (get_user_s32(size, handle)) { - return -TARGET_EFAULT; - } - - total_size = sizeof(struct file_handle) + size; - target_fh = lock_user(VERIFY_READ, handle, total_size, 1); - if (!target_fh) { - return -TARGET_EFAULT; - } - - fh = g_memdup(target_fh, total_size); - fh->handle_bytes = size; - fh->handle_type = tswap32(target_fh->handle_type); - - ret = get_errno(open_by_handle_at(mount_fd, fh, - target_to_host_bitmask(flags, fcntl_flags_tbl))); - - g_free(fh); - - unlock_user(target_fh, handle, total_size); - - return ret; -} -#endif #if defined(TARGET_NR_signalfd) || defined(TARGET_NR_signalfd4) @@ -7533,17 +7446,6 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, gdb_exit(cpu_env, arg1); _exit(arg1); return 0; /* avoid warning */ -#if defined(TARGET_NR_name_to_handle_at) && defined(CONFIG_OPEN_BY_HANDLE) - case TARGET_NR_name_to_handle_at: - ret = do_name_to_handle_at(arg1, arg2, arg3, arg4, arg5); - return ret; -#endif -#if defined(TARGET_NR_open_by_handle_at) && defined(CONFIG_OPEN_BY_HANDLE) - case TARGET_NR_open_by_handle_at: - ret = do_open_by_handle_at(arg1, arg2, arg3); - fd_trans_unregister(ret); - return ret; -#endif case TARGET_NR_brk: return do_brk(arg1); #ifdef TARGET_NR_fork diff --git a/linux-user/syscall_file.c b/linux-user/syscall_file.c index aae9c49599..9ee10b415e 100644 --- a/linux-user/syscall_file.c +++ b/linux-user/syscall_file.c @@ -24,8 +24,12 @@ #include +safe_syscall5(int, name_to_handle_at, int, dirfd, const char *, pathname, + struct file_handle *, handle, int *, mount_id, int, flags) safe_syscall4(int, openat, int, dirfd, const char *, pathname, \ int, flags, mode_t, mode) +safe_syscall3(int, open_by_handle_at, int, mount_fd, + struct file_handle *, handle, int, flags) safe_syscall5(ssize_t, preadv, int, fd, const struct iovec *, iov, int, iovcnt, unsigned long, pos_l, unsigned long, pos_h) safe_syscall5(ssize_t, pwritev, int, fd, const struct iovec *, iov, @@ -76,6 +80,90 @@ bitmask_transtbl const fcntl_flags_tbl[] = { * Helpers for do_openat, manipulating /proc/self/foo. */ +SYSCALL_IMPL(name_to_handle_at) +{ + struct file_handle *target_fh; + struct file_handle *fh; + int mid = 0; + abi_long ret; + char *name; + uint32_t size, total_size; + + if (get_user_s32(size, arg3)) { + return -TARGET_EFAULT; + } + total_size = sizeof(struct file_handle) + size; + target_fh = lock_user(VERIFY_WRITE, arg3, total_size, 0); + if (!target_fh) { + return -TARGET_EFAULT; + } + + name = lock_user_string(arg2); + if (!name) { + unlock_user(target_fh, arg3, 0); + return -TARGET_EFAULT; + } + + + fh = g_malloc0(total_size); + fh->handle_bytes = size; + + ret = get_errno(safe_name_to_handle_at(arg1, path(name), fh, &mid, arg5)); + unlock_user(name, arg2, 0); + + /* man name_to_handle_at(2): + * Other than the use of the handle_bytes field, the caller should treat + * the file_handle structure as an opaque data type + */ + if (!is_error(ret)) { + memcpy(target_fh, fh, total_size); + target_fh->handle_bytes = tswap32(fh->handle_bytes); + target_fh->handle_type = tswap32(fh->handle_type); + g_free(fh); + unlock_user(target_fh, arg3, total_size); + + if (put_user_s32(mid, arg4)) { + return -TARGET_EFAULT; + } + } + return ret; +} +SYSCALL_DEF(name_to_handle_at, + ARG_ATDIRFD, ARG_STR, ARG_PTR, ARG_PTR, ARG_ATFLAG); + +SYSCALL_IMPL(open_by_handle_at) +{ + abi_long mount_fd = arg1; + abi_long handle = arg2; + int host_flags = target_to_host_bitmask(arg3, fcntl_flags_tbl); + struct file_handle *target_fh; + struct file_handle *fh; + unsigned int size, total_size; + abi_long ret; + + if (get_user_s32(size, handle)) { + return -TARGET_EFAULT; + } + total_size = sizeof(struct file_handle) + size; + target_fh = lock_user(VERIFY_READ, handle, total_size, 1); + if (!target_fh) { + return -TARGET_EFAULT; + } + + fh = g_memdup(target_fh, total_size); + fh->handle_bytes = size; + fh->handle_type = tswap32(target_fh->handle_type); + + ret = get_errno(safe_open_by_handle_at(mount_fd, fh, host_flags)); + + g_free(fh); + unlock_user(target_fh, handle, total_size); + + fd_trans_unregister(ret); + return ret; +} +SYSCALL_DEF(open_by_handle_at, ARG_DEC, ARG_PTR, ARG_OPENFLAG); + static int open_self_cmdline(void *cpu_env, int fd) { CPUState *cpu = ENV_GET_CPU((CPUArchState *)cpu_env); diff --git a/linux-user/gen_syscall_list.py b/linux-user/gen_syscall_list.py index 7481d030ee..cebf111660 100644 --- a/linux-user/gen_syscall_list.py +++ b/linux-user/gen_syscall_list.py @@ -26,7 +26,9 @@ import sys # Avoiding ifdefs for these can diagnose typos in $cpu/syscall_nr.h unconditional_syscalls = [ "close", + "name_to_handle_at", "openat", + "open_by_handle_at", "pread64", "preadv", "pwrite64", diff --git a/linux-user/strace.list b/linux-user/strace.list index d978cefa31..d7880665a4 100644 --- a/linux-user/strace.list +++ b/linux-user/strace.list @@ -635,9 +635,6 @@ #ifdef TARGET_NR_munmap { TARGET_NR_munmap, "munmap" , NULL, print_munmap, NULL }, #endif -#ifdef TARGET_NR_name_to_handle_at -{ TARGET_NR_name_to_handle_at, "name_to_handle_at" , NULL, NULL, NULL }, -#endif #ifdef TARGET_NR_nanosleep { TARGET_NR_nanosleep, "nanosleep" , NULL, NULL, NULL }, #endif