From patchwork Tue May 26 18:46:32 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 48993 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id E965720502 for ; Tue, 26 May 2015 18:46:37 +0000 (UTC) Received: by wixv7 with SMTP id v7sf24019426wix.0 for ; Tue, 26 May 2015 11:46:37 -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:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=4UUDGmeo087h6oQBUFenaFPaXuK+w7/yYoxUwQ/CbN4=; b=NOUT92e1YLEM5PnQdXR5CIQmOTKYIuSoh70/Wa/4UCsg6CsLilSwggO7+wV4VXEbol +bMpP+Es6J64bENui8sLg7sY1zbrqxGodCIQ9EkVabx8myBaPfJ1HmlzIg4iR4PrkfDE pkabk4MLDHLJNmHKW4Q1Qg8vR1m7js9bic8ShefBR//PJBs3uk6V4BPuCNLVJHhTiaoL aRzjqXxIQ9wkivmI9/RLrzNskGs/M9GeOlbpL9Y5ukOGZkxLpGtT+1LrD1qfafu/sL6I u8OnQbTSGE2IgdxhThnIAFVYpn7YTMLKX93YYA9rPLh73taG/jjfXX5Hm0ihbh2HCpme y87A== X-Gm-Message-State: ALoCoQl2zkZxIpngodDTmJSZNPIOFVp19IhD5yp2l7hHJanXrQBqURH6RTbNl6zEsxpi9ct6P0t3 X-Received: by 10.112.219.200 with SMTP id pq8mr28596812lbc.7.1432665997171; Tue, 26 May 2015 11:46:37 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.239.130 with SMTP id vs2ls776445lac.97.gmail; Tue, 26 May 2015 11:46:37 -0700 (PDT) X-Received: by 10.152.43.168 with SMTP id x8mr24429211lal.79.1432665997030; Tue, 26 May 2015 11:46:37 -0700 (PDT) Received: from mail-la0-f47.google.com (mail-la0-f47.google.com. [209.85.215.47]) by mx.google.com with ESMTPS id eu8si11600457lbc.171.2015.05.26.11.46.37 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 May 2015 11:46:37 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.47 as permitted sender) client-ip=209.85.215.47; Received: by laat2 with SMTP id t2so74162728laa.1 for ; Tue, 26 May 2015 11:46:36 -0700 (PDT) X-Received: by 10.112.140.231 with SMTP id rj7mr23970015lbb.76.1432665996926; Tue, 26 May 2015 11:46:36 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp2751482lbb; Tue, 26 May 2015 11:46:36 -0700 (PDT) X-Received: by 10.112.168.165 with SMTP id zx5mr23901752lbb.111.1432665996121; Tue, 26 May 2015 11:46:36 -0700 (PDT) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id da7si11615292lad.99.2015.05.26.11.46.35 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 26 May 2015 11:46:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::1 as permitted sender) client-ip=2001:8b0:1d0::1; Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1YxJs1-0008Uk-23; Tue, 26 May 2015 19:46:33 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Riku Voipio Subject: [PATCH 2/2] linux-user: use __get_user and __put_user in cmsg conversions Date: Tue, 26 May 2015 19:46:32 +0100 Message-Id: <1432665992-32622-3-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1432665992-32622-1-git-send-email-peter.maydell@linaro.org> References: <1432665992-32622-1-git-send-email-peter.maydell@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: peter.maydell@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.47 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , The target payloads in cmsg conversions may not have the alignment required by the host. Using the get_user and put_user functions is the easiest way to handle this and also do the byte-swapping we require. (Note that prior to this commit target_to_host_cmsg was incorrectly using __put_user() rather than __get_user() for the SCM_CREDENTIALS conversion, which meant it wasn't getting the benefit of the misalignment handling.) Signed-off-by: Peter Maydell --- linux-user/syscall.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 3db6a90..7ef31b7 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -1228,17 +1228,18 @@ static inline abi_long target_to_host_cmsg(struct msghdr *msgh, int *target_fd = (int *)target_data; int i, numfds = len / sizeof(int); - for (i = 0; i < numfds; i++) - fd[i] = tswap32(target_fd[i]); + for (i = 0; i < numfds; i++) { + __get_user(fd[i], target_fd + i); + } } else if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_CREDENTIALS) { struct ucred *cred = (struct ucred *)data; struct target_ucred *target_cred = (struct target_ucred *)target_data; - __put_user(target_cred->pid, &cred->pid); - __put_user(target_cred->uid, &cred->uid); - __put_user(target_cred->gid, &cred->gid); + __get_user(cred->pid, &target_cred->pid); + __get_user(cred->uid, &target_cred->uid); + __get_user(cred->gid, &target_cred->gid); } else { gemu_log("Unsupported ancillary data: %d/%d\n", cmsg->cmsg_level, cmsg->cmsg_type); @@ -1333,8 +1334,9 @@ static inline abi_long host_to_target_cmsg(struct target_msghdr *target_msgh, int *target_fd = (int *)target_data; int i, numfds = tgt_len / sizeof(int); - for (i = 0; i < numfds; i++) - target_fd[i] = tswap32(fd[i]); + for (i = 0; i < numfds; i++) { + __put_user(fd[i], target_fd + i); + } break; } case SO_TIMESTAMP: @@ -1349,8 +1351,8 @@ static inline abi_long host_to_target_cmsg(struct target_msghdr *target_msgh, } /* copy struct timeval to target */ - target_tv->tv_sec = tswapal(tv->tv_sec); - target_tv->tv_usec = tswapal(tv->tv_usec); + __put_user(tv->tv_sec, &target_tv->tv_sec); + __put_user(tv->tv_usec, &target_tv->tv_usec); break; } case SCM_CREDENTIALS: