From patchwork Fri May 27 14:52:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 9138667 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7BFD96075C for ; Fri, 27 May 2016 15:24:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6EFEE27CCD for ; Fri, 27 May 2016 15:24:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 63B49281A7; Fri, 27 May 2016 15:24:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E007C27CCD for ; Fri, 27 May 2016 15:24:27 +0000 (UTC) Received: from localhost ([::1]:46618 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b6Jch-0003KV-0v for patchwork-qemu-devel@patchwork.kernel.org; Fri, 27 May 2016 11:24:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50194) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b6JBk-0004Rd-2o for qemu-devel@nongnu.org; Fri, 27 May 2016 10:56:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b6JBj-0006YX-5f for qemu-devel@nongnu.org; Fri, 27 May 2016 10:56:36 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:57419) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b6JBi-0006YL-Ur for qemu-devel@nongnu.org; Fri, 27 May 2016 10:56:35 -0400 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.84_2) (envelope-from ) id 1b6J7T-0004n4-GB; Fri, 27 May 2016 15:52:11 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Fri, 27 May 2016 15:52:01 +0100 Message-Id: <1464360721-14359-20-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1464360721-14359-1-git-send-email-peter.maydell@linaro.org> References: <1464360721-14359-1-git-send-email-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PATCH v2 19/19] linux-user: Avoid possible misalignment in target_to_host_siginfo() 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: Riku Voipio , Timothy Edward Baldwin , patches@linaro.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Reimplement target_to_host_siginfo() to use __get_user(), which handles possibly misaligned source guest structures correctly. Signed-off-by: Peter Maydell Reviewed-by: Laurent Vivier --- linux-user/signal.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index 7e2a80f..8417da7 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -409,13 +409,18 @@ void host_to_target_siginfo(target_siginfo_t *tinfo, const siginfo_t *info) /* XXX: find a solution for 64 bit (additional malloced data is needed) */ void target_to_host_siginfo(siginfo_t *info, const target_siginfo_t *tinfo) { - info->si_signo = tswap32(tinfo->si_signo); - info->si_errno = tswap32(tinfo->si_errno); - info->si_code = tswap32(tinfo->si_code); - info->si_pid = tswap32(tinfo->_sifields._rt._pid); - info->si_uid = tswap32(tinfo->_sifields._rt._uid); - info->si_value.sival_ptr = - (void *)(long)tswapal(tinfo->_sifields._rt._sigval.sival_ptr); + /* This conversion is used only for the rt_sigqueueinfo syscall, + * and so we know that the _rt fields are the valid ones. + */ + abi_ulong sival_ptr; + + __get_user(info->si_signo, &tinfo->si_signo); + __get_user(info->si_errno, &tinfo->si_errno); + __get_user(info->si_code, &tinfo->si_code); + __get_user(info->si_pid, &tinfo->_sifields._rt._pid); + __get_user(info->si_uid, &tinfo->_sifields._rt._uid); + __get_user(sival_ptr, &tinfo->_sifields._rt._sigval.sival_ptr); + info->si_value.sival_ptr = (void *)(long)sival_ptr; } static int fatal_signal (int sig)