From patchwork Wed Mar 19 14:03:02 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 26587 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yh0-f72.google.com (mail-yh0-f72.google.com [209.85.213.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id BA57520534 for ; Wed, 19 Mar 2014 14:08:44 +0000 (UTC) Received: by mail-yh0-f72.google.com with SMTP id f10sf22846069yha.11 for ; Wed, 19 Mar 2014 07:08:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:date :message-id:in-reply-to:references:cc:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=28r6y205NkgEEoe4DTdBq+kwIz/vd3Xh8L5e+3l9qI4=; b=Y6rDILwPFS5pZbuYyuLSIAsyeisO8rZMUIlYK3d3ZV3nZRDgN1IKpha0d0hHPywzlf 61ruwiKj0Wv+6XpdHTYGVLAamwO5WRM+Z737XuBce3UBQRwKk2otwgX0sbV62cbAn0GP 5oNPMaK17DgfNGwG6iZmFI1lT1A5AhOjORt1SCo9AEzkwFfvSOpB8f6LgQHhnXDh30vg oKawTXM+VMeQcG6x6vCgtdevFrnWFEgXWrBQjeCpCizgcT6H0ePSxqoS6iOHDei1n9YA SAcD3DgXefglQdnCyFCZjTpO7WBna1BFTnJnNAQ6eTxPGQPY+Vjc4wiBdUKz8u6RD8pH S6jw== X-Gm-Message-State: ALoCoQmUQ1gamPgwJaiaD0RaFB/Cst0BN3ek3tCNW33crR/mXVXwt5ixLTEG+t8nNFAE8UGJTcJO X-Received: by 10.236.91.107 with SMTP id g71mr7715354yhf.53.1395238124457; Wed, 19 Mar 2014 07:08:44 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.36.45 with SMTP id o42ls2638224qgo.7.gmail; Wed, 19 Mar 2014 07:08:44 -0700 (PDT) X-Received: by 10.52.240.207 with SMTP id wc15mr26309004vdc.14.1395238124231; Wed, 19 Mar 2014 07:08:44 -0700 (PDT) Received: from mail-ve0-f182.google.com (mail-ve0-f182.google.com [209.85.128.182]) by mx.google.com with ESMTPS id m3si7728308vcr.98.2014.03.19.07.08.44 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 19 Mar 2014 07:08:44 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.182 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.182; Received: by mail-ve0-f182.google.com with SMTP id jw12so9067370veb.27 for ; Wed, 19 Mar 2014 07:08:44 -0700 (PDT) X-Received: by 10.52.242.167 with SMTP id wr7mr1312427vdc.32.1395238124121; Wed, 19 Mar 2014 07:08:44 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.78.9 with SMTP id i9csp302662vck; Wed, 19 Mar 2014 07:08:43 -0700 (PDT) X-Received: by 10.15.10.3 with SMTP id f3mr36168966eet.1.1395238122687; Wed, 19 Mar 2014 07:08:42 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [208.118.235.17]) by mx.google.com with ESMTPS id x44si27209177eep.60.2014.03.19.07.08.42 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 19 Mar 2014 07:08:42 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; Received: from localhost ([::1]:41597 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WQHAf-00072I-8P for patch@linaro.org; Wed, 19 Mar 2014 10:08:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54654) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WQH5P-0007ok-8k for qemu-devel@nongnu.org; Wed, 19 Mar 2014 10:03:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WQH5H-00062J-6w for qemu-devel@nongnu.org; Wed, 19 Mar 2014 10:03:15 -0400 Received: from afflict.kos.to ([92.243.29.197]:54525) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WQH5G-0005zf-NX for qemu-devel@nongnu.org; Wed, 19 Mar 2014 10:03:07 -0400 Received: from localhost.localdomain (afflict [92.243.29.197]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by afflict.kos.to (Postfix) with ESMTPSA id 6D6502656A; Wed, 19 Mar 2014 15:03:04 +0100 (CET) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Wed, 19 Mar 2014 16:03:02 +0200 Message-Id: X-Mailer: git-send-email 1.7.2.5 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 92.243.29.197 Cc: Peter Maydell , Anthony Liguori Subject: [Qemu-devel] [PULL for-2.0 7/7] linux-user: Implement capget, capset X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: riku.voipio@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.182 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 From: Peter Maydell Implement the capget and capset syscalls. This is useful because simple programs like 'ls' try to use it in AArch64, and otherwise we emit a lot of noise about it being unimplemented. Signed-off-by: Peter Maydell Signed-off-by: Riku Voipio --- linux-user/syscall.c | 75 +++++++++++++++++++++++++++++++++++++++++++++-- linux-user/syscall_defs.h | 11 +++++++ 2 files changed, 84 insertions(+), 2 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index e404a32..366b695 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -43,6 +43,7 @@ #include #include #include +#include #include #include #ifdef __ia64__ @@ -243,6 +244,10 @@ _syscall3(int, sys_sched_setaffinity, pid_t, pid, unsigned int, len, unsigned long *, user_mask_ptr); _syscall4(int, reboot, int, magic1, int, magic2, unsigned int, cmd, void *, arg); +_syscall2(int, capget, struct __user_cap_header_struct *, header, + struct __user_cap_data_struct *, data); +_syscall2(int, capset, struct __user_cap_header_struct *, header, + struct __user_cap_data_struct *, data); static bitmask_transtbl fcntl_flags_tbl[] = { { TARGET_O_ACCMODE, TARGET_O_WRONLY, O_ACCMODE, O_WRONLY, }, @@ -7677,9 +7682,75 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, unlock_user(p, arg1, ret); break; case TARGET_NR_capget: - goto unimplemented; case TARGET_NR_capset: - goto unimplemented; + { + struct target_user_cap_header *target_header; + struct target_user_cap_data *target_data = NULL; + struct __user_cap_header_struct header; + struct __user_cap_data_struct data[2]; + struct __user_cap_data_struct *dataptr = NULL; + int i, target_datalen; + int data_items = 1; + + if (!lock_user_struct(VERIFY_WRITE, target_header, arg1, 1)) { + goto efault; + } + header.version = tswap32(target_header->version); + header.pid = tswap32(target_header->pid); + + if (header.version != _LINUX_CAPABILITY_VERSION_1) { + /* Version 2 and up takes pointer to two user_data structs */ + data_items = 2; + } + + target_datalen = sizeof(*target_data) * data_items; + + if (arg2) { + if (num == TARGET_NR_capget) { + target_data = lock_user(VERIFY_WRITE, arg2, target_datalen, 0); + } else { + target_data = lock_user(VERIFY_READ, arg2, target_datalen, 1); + } + if (!target_data) { + unlock_user_struct(target_header, arg1, 0); + goto efault; + } + + if (num == TARGET_NR_capset) { + for (i = 0; i < data_items; i++) { + data[i].effective = tswap32(target_data[i].effective); + data[i].permitted = tswap32(target_data[i].permitted); + data[i].inheritable = tswap32(target_data[i].inheritable); + } + } + + dataptr = data; + } + + if (num == TARGET_NR_capget) { + ret = get_errno(capget(&header, dataptr)); + } else { + ret = get_errno(capset(&header, dataptr)); + } + + /* The kernel always updates version for both capget and capset */ + target_header->version = tswap32(header.version); + unlock_user_struct(target_header, arg1, 1); + + if (arg2) { + if (num == TARGET_NR_capget) { + for (i = 0; i < data_items; i++) { + target_data[i].effective = tswap32(data[i].effective); + target_data[i].permitted = tswap32(data[i].permitted); + target_data[i].inheritable = tswap32(data[i].inheritable); + } + unlock_user(target_data, arg2, target_datalen); + } else { + unlock_user(target_data, arg2, 0); + } + } + break; + } case TARGET_NR_sigaltstack: #if defined(TARGET_I386) || defined(TARGET_ARM) || defined(TARGET_MIPS) || \ defined(TARGET_SPARC) || defined(TARGET_PPC) || defined(TARGET_ALPHA) || \ diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h index 2a7d1db..fdf9a47 100644 --- a/linux-user/syscall_defs.h +++ b/linux-user/syscall_defs.h @@ -2566,3 +2566,14 @@ struct target_sigevent { } _sigev_thread; } _sigev_un; }; + +struct target_user_cap_header { + uint32_t version; + int pid; +}; + +struct target_user_cap_data { + uint32_t effective; + uint32_t permitted; + uint32_t inheritable; +};