From patchwork Tue Jun 16 07:06:30 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 484807 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 38B841401F6 for ; Tue, 16 Jun 2015 17:09:36 +1000 (AEST) Received: from localhost ([::1]:38179 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z4l02-0000by-8B for incoming@patchwork.ozlabs.org; Tue, 16 Jun 2015 03:09:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60932) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z4kxG-0004EB-Lc for qemu-devel@nongnu.org; Tue, 16 Jun 2015 03:06:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z4kxC-0006nU-Ly for qemu-devel@nongnu.org; Tue, 16 Jun 2015 03:06:42 -0400 Received: from mail-la0-f43.google.com ([209.85.215.43]:35111) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z4kxC-0006nN-Fl for qemu-devel@nongnu.org; Tue, 16 Jun 2015 03:06:38 -0400 Received: by labko7 with SMTP id ko7so4809725lab.2 for ; Tue, 16 Jun 2015 00:06: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:from:to:cc:subject:date:message-id:in-reply-to :references; bh=wfFRjqHC+61sHwTIYlwsFOxHoNS8kKJ6u63hs2InhTc=; b=EoLO9PmbHF0vtolX4L/KiRBZFZtw+cIMsKNhYUrM76+Kz4a0OmSBt2EYYpZC9FVku8 jBl1GAp+zDs8jtiVQ7S84DQXUDgLCFyeY2ZvrT4HFO8luNiF8E++p5YAVYRte4WX5QCK IBJuz5jE9r1O0SNG4VhnlZKv8uJ9rc8gSDNWbKk3F2Z2Exu+HOniIQYI6gjQeTkC6qcF r3HIOiUrNvBS9BUoHhbODgatFe3ig5mnVfv+91ULedEIM6dn+kJqkr8Fg1omdgHqnIwv 8y0ioItYCukKGF5hioxnm9BbghX+Eg8yh1er/ogUTWkOXt1om0dbE5O6GdBVYelzhsoe 1i+A== X-Gm-Message-State: ALoCoQli7ZHO13OlkP2lpFbCnQ0i43bWufR9Hag0fmWxQS0c7WqXQDVwpznrLOM6XouaLCJUSt2A X-Received: by 10.152.28.34 with SMTP id y2mr29775767lag.14.1434438397916; Tue, 16 Jun 2015 00:06:37 -0700 (PDT) Received: from localhost.localdomain (91-157-196-38.elisa-laajakaista.fi. [91.157.196.38]) by mx.google.com with ESMTPSA id wc8sm27104lbb.37.2015.06.16.00.06.37 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 16 Jun 2015 00:06:37 -0700 (PDT) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Tue, 16 Jun 2015 10:06:30 +0300 Message-Id: <876e23cb2e545148a0ee4effda5c63c861855941.1434438233.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: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.215.43 Cc: peter.maydell@linaro.org Subject: [Qemu-devel] [PULL v2 4/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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 15b1e81..5cf265c 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: