From patchwork Mon Jun 15 12:20:49 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 49859 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f71.google.com (mail-wg0-f71.google.com [74.125.82.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id C6994211FD for ; Mon, 15 Jun 2015 12:21:49 +0000 (UTC) Received: by wgv5 with SMTP id 5sf24457817wgv.0 for ; Mon, 15 Jun 2015 05:21:48 -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=GNmRz8qulTid1MEAwsZeUkTRaIS9UZck3sXaao/3oi8=; b=kHAi4u+alMWIRpJACuUq+r+bofLf1QpsiEh/HPM2IMFjDA9HRliu2GS9Dp+5etBNWq XiltJCW+PNGrUzPX7/B614JVsY4WTN8F8wMaKse+5BaeUMhecdMUbDsX0JaUXWElFfTs jeRmpJVRkugiRPPO1fvlu36+xcBZStosFieMiixHSxB/mwi/yvRfljY99C7IkfvFT0v3 +Ddqi2fMtuM0kjPHVMEdLTUpN5VNBuV/qKnpXXSUwSzhepnlcTo1Gv22Q9ZP/5vbSlUm W3L+rwu98NMcRHRDYm44GCoPU9zfyYnt8JJWt3sW8258QgeJNu+jTaQOuyyanNrJasRn +81g== X-Gm-Message-State: ALoCoQklRZfwXzep0HkRbCsxhN1BhS9hts/HHH5AHoRKXopsLKVJQLhGTnoMXCMVd7BIuQzoBQRJ X-Received: by 10.194.175.36 with SMTP id bx4mr29588137wjc.1.1434370908129; Mon, 15 Jun 2015 05:21:48 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.225.167 with SMTP id rl7ls888301lac.74.gmail; Mon, 15 Jun 2015 05:21:47 -0700 (PDT) X-Received: by 10.152.116.6 with SMTP id js6mr21634759lab.28.1434370907961; Mon, 15 Jun 2015 05:21:47 -0700 (PDT) Received: from mail-lb0-f170.google.com (mail-lb0-f170.google.com. [209.85.217.170]) by mx.google.com with ESMTPS id o2si10374482lbl.51.2015.06.15.05.21.47 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Jun 2015 05:21:47 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.170 as permitted sender) client-ip=209.85.217.170; Received: by lbbwc1 with SMTP id wc1so375890lbb.2 for ; Mon, 15 Jun 2015 05:21:47 -0700 (PDT) X-Received: by 10.112.41.196 with SMTP id h4mr10249lbl.36.1434370907845; Mon, 15 Jun 2015 05:21:47 -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.112.108.230 with SMTP id hn6csp1377837lbb; Mon, 15 Jun 2015 05:21:46 -0700 (PDT) X-Received: by 10.55.25.166 with SMTP id 38mr58020796qkz.52.1434370906442; Mon, 15 Jun 2015 05:21:46 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id i35si12500848qgd.126.2015.06.15.05.21.45 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 15 Jun 2015 05:21:46 -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; Received: from localhost ([::1]:33883 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z4TOb-0000Di-Ii for patch@linaro.org; Mon, 15 Jun 2015 08:21:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46580) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z4TNu-000854-IA for qemu-devel@nongnu.org; Mon, 15 Jun 2015 08:21:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z4TNr-0003CZ-8u for qemu-devel@nongnu.org; Mon, 15 Jun 2015 08:21:02 -0400 Received: from mail-la0-x233.google.com ([2a00:1450:4010:c03::233]:33679) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z4TNq-0003Aq-D4 for qemu-devel@nongnu.org; Mon, 15 Jun 2015 08:20:58 -0400 Received: by laka10 with SMTP id a10so8913937lak.0 for ; Mon, 15 Jun 2015 05:20:57 -0700 (PDT) X-Received: by 10.152.205.67 with SMTP id le3mr26660401lac.50.1434370857441; Mon, 15 Jun 2015 05:20:57 -0700 (PDT) Received: from localhost.localdomain (91-157-196-38.elisa-laajakaista.fi. [91.157.196.38]) by mx.google.com with ESMTPSA id bm5sm2683890lbc.45.2015.06.15.05.20.56 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 15 Jun 2015 05:20:56 -0700 (PDT) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Mon, 15 Jun 2015 15:20:49 +0300 Message-Id: <14d8a6fddc10941088430a71b9ca333a02355967.1434369586.git.riku.voipio@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4010:c03::233 Cc: peter.maydell@linaro.org Subject: [Qemu-devel] [PULL 5/6] linux-user: use __get_user and __put_user in cmsg conversions 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=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.170 as permitted sender) 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 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 Signed-off-by: Riku Voipio --- 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 839ce93..ed99104 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: