From patchwork Sun Jun 10 03:01:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 138136 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp2597888lji; Sat, 9 Jun 2018 20:46:41 -0700 (PDT) X-Google-Smtp-Source: ADUXVKL3DovulgV1SON4F+GbmITVOOhrOFa5aOlsVfr4YWEZo5V0TdDvGQ8p9cX5iSKlx3V0cxT2 X-Received: by 2002:aed:3f36:: with SMTP id p51-v6mr11454746qtf.213.1528602401010; Sat, 09 Jun 2018 20:46:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528602401; cv=none; d=google.com; s=arc-20160816; b=SKVXeISk4ChOiyu+VhwarHesnlcz3QE2u+RYNHXma/xjEL7XN7kREKpYPtdthUV3Y4 PSBI4YJkhzyND/f6fTkzA43jxhqt4tJJQSva8iXejsRlPn+MXK4VgmZjtVTgJsRe1U2H rf7anIhOKSYdJTmlpOTTSWbpxwk6bXCgFdUeRPMTbvUPTZJoN+k4Jm21SemGCJtjxRn3 KBVLqw32xDB+rhbOXvyOk7xlR+cWFwo4e0IRaJq+yjdKlcM4bNXwWyOoMhbFfZs1ivkg YZ6ujg2ftQ6I7xyIsUCbW0LJwDgSAwwyb+3bN7AfRXatuLUeDISTLuhNIgK8xwtvAI/Y mong== 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=d9muHfjUp4Bj3UWUzaKvDRlH2aaTiMZ5LFfnfhySqTI=; b=aMkKL+DAETbtvEqOhwk0FuLOcCkzFL19CaO0S9Bwu/zQu5kO5anwYKFnWwKC4HnKip 56McuvyjETcAaTWJi8djTdx2TKC6AjqrO8p08iQ/1yL5Jw+i042jKoW6JdPppFQnxAIf m/GKRjgmVBhI0+Ljbm6u8bObhs2C8kqMJB+rpX7xQXA5mZslrqaDnFk939O8TfGufDus e7Oc3KJKJ5jQvvE3w+O76OfXUQ1qDaroHuinDk+DUgmCeC+Eve6NW9HCOOlc1S0NLRX5 VMZ5t4l15gU0M1+GPBvEgDSu7x2xmYl8wKIv1Gr/vQcTy58tFO6s7qp+0M8/u1ZPgTQ9 UoXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=d8lcKrt8; 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 b44-v6si7573309qtb.263.2018.06.09.20.46.40 for (version=TLS1 cipher=AES128-SHA bits=128/128); Sat, 09 Jun 2018 20:46:40 -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=d8lcKrt8; 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]:42419 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRrJQ-0007wF-BS for patch@linaro.org; Sat, 09 Jun 2018 23:46:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41139) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRqf8-0003nU-S8 for qemu-devel@nongnu.org; Sat, 09 Jun 2018 23:05:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fRqf7-0004H0-Jv for qemu-devel@nongnu.org; Sat, 09 Jun 2018 23:05:02 -0400 Received: from mail-pl0-x241.google.com ([2607:f8b0:400e:c01::241]:41587) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fRqf7-0004FX-CC for qemu-devel@nongnu.org; Sat, 09 Jun 2018 23:05:01 -0400 Received: by mail-pl0-x241.google.com with SMTP id az12-v6so10380824plb.8 for ; Sat, 09 Jun 2018 20:05:01 -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=d9muHfjUp4Bj3UWUzaKvDRlH2aaTiMZ5LFfnfhySqTI=; b=d8lcKrt8PDnMKcoV7/DeUBoS8Rfd4yI8dv70zVvd95e+cGBVlGPL+zBEoffcEBGS05 EQ79tBgZNUTXldAAWPsPoVjMO5CCfbL8yNI8hlsAd/QviHwkuCn77/RwNQ3FxDn0xusv KXaUonT/mZezzO7KT/JifP/4z/+GHqU2AznkY= 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=d9muHfjUp4Bj3UWUzaKvDRlH2aaTiMZ5LFfnfhySqTI=; b=XSBmFTpP4WTZaBNWkKGv8foQIarEp+8x9zChlzsj9QpgrO0UHoCnmCUtpm3wOyok75 RFGUeBNN5VNld4eq5VzPCsBe0TIy+C0vbdkBg88dfhZ8hczzoj5b0YrUGX3QMjEIV5pV RqrEk/ZH1b59Om6kg0jhZwYizWRWmiiKO3YOhSsqw4F5ctyeQcSvwsAlKiR6UdhzRdhy x4VTfOjEQLz6YDzE0xCUu0fKai2uBoxiN8WJbFxdU+kMAX8nYBXreMnJ4tJAJtVl6g9T Lu2U7kDVGQYjlKjxtjQVF63sDvCqoRBhPxEBY2VmWfCKeHR8dSE8LsvW7DQ5+F7yM8ut SH0Q== X-Gm-Message-State: APt69E0lW9exrvCjIB+oSOj5e0GitynLAvd1AjzVfBTtlPk27gKvjwB4 dEq+qyiDbfdW+xq2Tvp8ilpmDcjxoe8= X-Received: by 2002:a17:902:e3:: with SMTP id a90-v6mr3927562pla.227.1528599900257; Sat, 09 Jun 2018 20:05:00 -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.58 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 09 Jun 2018 20:04:59 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Sat, 9 Jun 2018 17:01:45 -1000 Message-Id: <20180610030220.3777-74-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 073/108] linux-user: Split out getgroups, setgroups, setregid, setreuid 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 | 107 +++++++++++++++++++++++++------------------ 1 file changed, 63 insertions(+), 44 deletions(-) -- 2.17.1 diff --git a/linux-user/syscall.c b/linux-user/syscall.c index f8e34d28b1..915e1f1a91 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8462,6 +8462,32 @@ IMPL(getgid) } #endif +IMPL(getgroups) +{ + int gidsetsize = arg1; + gid_t *grouplist; + abi_long ret; + + grouplist = alloca(gidsetsize * sizeof(gid_t)); + ret = get_errno(getgroups(gidsetsize, grouplist)); + + if (!is_error(ret) && gidsetsize != 0) { + target_id *target_gl; + int i; + + target_gl = lock_user(VERIFY_WRITE, arg2, + gidsetsize * sizeof(target_id), 0); + if (!target_gl) { + return -TARGET_EFAULT; + } + for (i = 0; i < ret; i++) { + target_gl[i] = tswapid(high2lowgid(grouplist[i])); + } + unlock_user(target_gl, arg2, gidsetsize * sizeof(target_id)); + } + return ret; +} + IMPL(getitimer) { struct itimerval value; @@ -10441,6 +10467,29 @@ IMPL(setdomainname) return ret; } +IMPL(setgroups) +{ + int gidsetsize = arg1; + gid_t *grouplist = NULL; + + if (gidsetsize) { + target_id *target_gl; + int i; + + grouplist = alloca(gidsetsize * sizeof(gid_t)); + target_gl = lock_user(VERIFY_READ, arg2, + gidsetsize * sizeof(target_id), 1); + if (!target_gl) { + return -TARGET_EFAULT; + } + for (i = 0; i < gidsetsize; i++) { + grouplist[i] = low2highgid(tswapid(target_gl[i])); + } + unlock_user(target_gl, arg2, 0); + } + return get_errno(setgroups(gidsetsize, grouplist)); +} + IMPL(sethostname) { char *p = lock_user_string(arg1); @@ -10486,6 +10535,16 @@ IMPL(setpriority) return get_errno(setpriority(arg1, arg2, arg3)); } +IMPL(setregid) +{ + return get_errno(setregid(low2highgid(arg1), low2highgid(arg2))); +} + +IMPL(setreuid) +{ + return get_errno(setreuid(low2highuid(arg1), low2highuid(arg2))); +} + IMPL(setrlimit) { int resource = target_to_host_resource(arg1); @@ -11453,50 +11512,6 @@ static abi_long do_syscall1(void *cpu_env, unsigned num, abi_long arg1, void *p; switch(num) { - case TARGET_NR_setreuid: - return get_errno(setreuid(low2highuid(arg1), low2highuid(arg2))); - case TARGET_NR_setregid: - return get_errno(setregid(low2highgid(arg1), low2highgid(arg2))); - case TARGET_NR_getgroups: - { - int gidsetsize = arg1; - target_id *target_grouplist; - gid_t *grouplist; - int i; - - grouplist = alloca(gidsetsize * sizeof(gid_t)); - ret = get_errno(getgroups(gidsetsize, grouplist)); - if (gidsetsize == 0) - return ret; - if (!is_error(ret)) { - target_grouplist = lock_user(VERIFY_WRITE, arg2, gidsetsize * sizeof(target_id), 0); - if (!target_grouplist) - return -TARGET_EFAULT; - for(i = 0;i < ret; i++) - target_grouplist[i] = tswapid(high2lowgid(grouplist[i])); - unlock_user(target_grouplist, arg2, gidsetsize * sizeof(target_id)); - } - } - return ret; - case TARGET_NR_setgroups: - { - int gidsetsize = arg1; - target_id *target_grouplist; - gid_t *grouplist = NULL; - int i; - if (gidsetsize) { - grouplist = alloca(gidsetsize * sizeof(gid_t)); - target_grouplist = lock_user(VERIFY_READ, arg2, gidsetsize * sizeof(target_id), 1); - if (!target_grouplist) { - return -TARGET_EFAULT; - } - for (i = 0; i < gidsetsize; i++) { - grouplist[i] = low2highgid(tswapid(target_grouplist[i])); - } - unlock_user(target_grouplist, arg2, 0); - } - return get_errno(setgroups(gidsetsize, grouplist)); - } case TARGET_NR_fchown: return get_errno(fchown(arg1, low2highuid(arg2), low2highgid(arg3))); #if defined(TARGET_NR_fchownat) @@ -13123,6 +13138,7 @@ static impl_fn *syscall_table(unsigned num) #ifdef TARGET_NR_getgid SYSCALL(getgid); #endif + SYSCALL(getgroups); SYSCALL(getitimer); #ifdef TARGET_NR_getpeername SYSCALL(getpeername); @@ -13356,10 +13372,13 @@ static impl_fn *syscall_table(unsigned num) SYSCALL(sendto); #endif SYSCALL(setdomainname); + SYSCALL(setgroups); SYSCALL(sethostname); SYSCALL(setitimer); SYSCALL(setpgid); SYSCALL(setpriority); + SYSCALL(setregid); + SYSCALL(setreuid); SYSCALL(setrlimit); #ifdef TARGET_NR_setsockopt SYSCALL(setsockopt);