From patchwork Sun Jun 10 03:01:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 138139 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp2599197lji; Sat, 9 Jun 2018 20:49:10 -0700 (PDT) X-Google-Smtp-Source: ADUXVKK/uAEF4FtYcd5txzX8JJIIapGO9bBWAqwNEZRtDBUONHruXQQ9U7FgXQ4UJaNEXO637tNo X-Received: by 2002:aed:24aa:: with SMTP id t39-v6mr11838662qtc.253.1528602550553; Sat, 09 Jun 2018 20:49:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528602550; cv=none; d=google.com; s=arc-20160816; b=C3Td92FWm48Qa4xv9CrxsO46H6CdDOPYSdkxr2/2K0gkSGyofYSbBDlZG+tOIV2/W1 CRkj8y3eFJCjv/A3ITsFPWPS6g4C+BZiJsAjwxF+UtOx6MyOKG7O1NLbwW+FQbH8wsX0 QVdoQa+9hZnjW3Um4TiKAIn2tTpyNc6JiRxdzyQQn3zqfJVsC10z/uAZbPTLV3ykAgnF WoUjxhls6E1A54fN12EOokL7AsnWROILPVAah9lqvrUYXPi6r0yJXJlSVCnk2hcE7A8y HszdxVvrSQn9ZNNO0rnSBKrDvEVM8UFkdTkwYOnhJui7YhMk7gi1d+WaG6PC9byMghx+ PbJA== 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=w08wgPKrKdruduYDw0BSz8pPv8SAxVK5e/RpTln5atg=; b=G8nbgi452wB3a+4DhNDPCgv+gPHlPozJTcBeq4jShw4svc8QVln6xG0SwsSveKy5/e uicainyFCXKwOqiqXqyYi+KYssxPbuXPLAfUa+QqykG2RWVjW5SuZAqWCen8HBH0p7u6 gVV/QKo41gcSwYIYThC6j4bfvvMY7d+6JGiVO7+r0fhPTHxoI0I+JaYvQgoUmcBJBPFo WgqH7pX60igzWGttpHdvkYdhd3u6q7ZfnwsU/mtatlovq4+sJW31kJjEnOK/4Vk0lfEs Ot6xw7k7YWe0CD7TyzN+HLzhn6A8M1Cy0deintYBJ36lZmZCoHZRKuaSQprNlrGfwC1l is6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Q8IYHJ/k; 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 n67-v6si22260247qkc.152.2018.06.09.20.49.10 for (version=TLS1 cipher=AES128-SHA bits=128/128); Sat, 09 Jun 2018 20:49:10 -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=Q8IYHJ/k; 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]:42426 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRrLp-0001Ub-T5 for patch@linaro.org; Sat, 09 Jun 2018 23:49:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41071) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRqez-0003ed-ND for qemu-devel@nongnu.org; Sat, 09 Jun 2018 23:04:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fRqey-00046p-D9 for qemu-devel@nongnu.org; Sat, 09 Jun 2018 23:04:53 -0400 Received: from mail-pl0-x241.google.com ([2607:f8b0:400e:c01::241]:39883) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fRqey-000465-4u for qemu-devel@nongnu.org; Sat, 09 Jun 2018 23:04:52 -0400 Received: by mail-pl0-x241.google.com with SMTP id f1-v6so10400347plt.6 for ; Sat, 09 Jun 2018 20:04:52 -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=w08wgPKrKdruduYDw0BSz8pPv8SAxVK5e/RpTln5atg=; b=Q8IYHJ/kkzfhbPVPM9qNQw2pmmj2s5MGofQVtvXDbRcvSI4wcg3t/lmI5NfTGYuoMx nAAWnpOiKkmrHYluoI5kQb4saDfy8UaBym2d4P72rywOs+f2PYGiY2Ho2sNaM6J6Wrpj m8k+kBEeke8+m0efpbG2wAIyahMQZCyCRtGlM= 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=w08wgPKrKdruduYDw0BSz8pPv8SAxVK5e/RpTln5atg=; b=gow8ha7dWdGePB40HEhsziKRXUQAMc1SbD1Kr+2QK12DUSEhnpYfbsRJ+hkdALQq0/ aYbP/Q+x7wsyTHra5sLXzwGfZdYX/HGJfPonTE1i60Akb6OPqujE3fIsRU+t1dWrqTM2 hcxeOafm3jaPPZq6IiXunKcSlNO/zkuj8Zvo5XaqZI/QBB4lrP1BWabLnY9T4P6kNxe4 Pv5un/YO4yax/6in0TQBr0HPrU4HLfZkUA7GXdq1mFJNgQg/wnA3w+LUJQLkDNdLVcps G8WUWKU2UwJ+09M94BNIC9ZZfbZolI8T5Qzm530D9pSog7eA5PrmhfJjpOWnI1jxYZ/0 pw4A== X-Gm-Message-State: APt69E2m0PNhmpZmSf6pwDMyR3FJj0ljMK88zZQ0yKrJp0QOAgkZO68l biCDyNP1dEJHjHaI6GPB4HPyHaiioOk= X-Received: by 2002:a17:902:9a4b:: with SMTP id x11-v6mr12966032plv.176.1528599890995; Sat, 09 Jun 2018 20:04:50 -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 y17-v6sm31712718pfe.33.2018.06.09.20.04.49 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 09 Jun 2018 20:04:50 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Sat, 9 Jun 2018 17:01:40 -1000 Message-Id: <20180610030220.3777-69-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180610030220.3777-1-richard.henderson@linaro.org> References: <20180610030220.3777-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 v2 068/108] linux-user: Split out capget, capset 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" Signed-off-by: Richard Henderson --- linux-user/syscall.c | 156 ++++++++++++++++++++++++------------------- 1 file changed, 86 insertions(+), 70 deletions(-) -- 2.17.1 diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 1e1ac8defd..c906719152 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -7703,6 +7703,90 @@ IMPL(brk) return do_brk(arg1); } +IMPL(capget) +{ + struct target_user_cap_header *target_header; + struct __user_cap_header_struct header; + struct __user_cap_data_struct data[2]; + int data_items; + abi_long ret; + + if (!lock_user_struct(VERIFY_WRITE, target_header, arg1, 1)) { + return -TARGET_EFAULT; + } + header.version = tswap32(target_header->version); + header.pid = tswap32(target_header->pid); + + /* Version 2 and up takes pointer to two user_data structs */ + data_items = (header.version == _LINUX_CAPABILITY_VERSION ? 1 : 2); + + ret = get_errno(capget(&header, arg2 ? data : NULL)); + + /* 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) { + struct target_user_cap_data *target_data; + int target_datalen = sizeof(*target_data) * data_items; + int i; + + target_data = lock_user(VERIFY_WRITE, arg2, target_datalen, 0); + if (!target_data) { + return -TARGET_EFAULT; + } + 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); + } + return ret; +} + +IMPL(capset) +{ + struct target_user_cap_header *target_header; + struct __user_cap_header_struct header; + struct __user_cap_data_struct data[2]; + abi_long ret; + + if (!lock_user_struct(VERIFY_WRITE, target_header, arg1, 1)) { + return -TARGET_EFAULT; + } + header.version = tswap32(target_header->version); + header.pid = tswap32(target_header->pid); + + if (arg2) { + /* Version 2 and up takes pointer to two user_data structs */ + int data_items = (header.version == _LINUX_CAPABILITY_VERSION ? 1 : 2); + struct target_user_cap_data *target_data; + int target_datalen = sizeof(*target_data) * data_items; + int i; + + target_data = lock_user(VERIFY_READ, arg2, target_datalen, 1); + if (!target_data) { + unlock_user_struct(target_header, arg1, 0); + return -TARGET_EFAULT; + } + + 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); + } + unlock_user(target_data, arg2, 0); + } + + ret = get_errno(capset(&header, arg2 ? data : NULL)); + + /* The kernel always updates version for both capget and capset */ + target_header->version = tswap32(header.version); + unlock_user_struct(target_header, arg1, 1); + return ret; +} + IMPL(chdir) { char *p = lock_user_string(arg1); @@ -11181,76 +11265,6 @@ static abi_long do_syscall1(void *cpu_env, unsigned num, abi_long arg1, void *p; switch(num) { - case TARGET_NR_capget: - case TARGET_NR_capset: - { - 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)) { - return -TARGET_EFAULT; - } - header.version = tswap32(target_header->version); - header.pid = tswap32(target_header->pid); - - if (header.version != _LINUX_CAPABILITY_VERSION) { - /* 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); - return -TARGET_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); - } - } - return ret; - } #ifdef CONFIG_SENDFILE case TARGET_NR_sendfile: { @@ -12991,6 +13005,8 @@ static impl_fn *syscall_table(unsigned num) SYSCALL(bind); #endif SYSCALL(brk); + SYSCALL(capget); + SYSCALL(capset); #ifdef CONFIG_CLOCK_ADJTIME SYSCALL(clock_adjtime); #endif