From patchwork Wed Jun 8 13:30:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 632287 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 ozlabs.org (Postfix) with ESMTPS id 3rPqxc5kP5z9sDC for ; Thu, 9 Jun 2016 00:07:00 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b=glK9kecv; dkim-atps=neutral Received: from localhost ([::1]:57214 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bAe8I-0004UI-7g for incoming@patchwork.ozlabs.org; Wed, 08 Jun 2016 10:06:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37044) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bAdZS-0004Kj-Gs for qemu-devel@nongnu.org; Wed, 08 Jun 2016 09:31:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bAdZQ-0005nJ-Jp for qemu-devel@nongnu.org; Wed, 08 Jun 2016 09:30:57 -0400 Received: from mail-lf0-x22d.google.com ([2a00:1450:4010:c07::22d]:33921) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bAdZP-0005mx-Qw for qemu-devel@nongnu.org; Wed, 08 Jun 2016 09:30:56 -0400 Received: by mail-lf0-x22d.google.com with SMTP id s186so5873848lfs.1 for ; Wed, 08 Jun 2016 06:30:55 -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=4MxOnsti7KmbY8uEP8vhT98QYhMB7xdjMYFj8udnqbw=; b=glK9kecvZyoLbtuSgg3LllYU0h89X32SNcfy2yC4xl/UA9mT8hNEr0QUiUgISbEA55 FiIynz4BQGckhJDyn2Sf3HpRGJZesB7kyTMtgnAhlPrqcM6or7nD8MoOT1RR5tZcMmES +3Ofctd+d8I5oZCG/ZEHkVaTsP2gNDQv9w6qo= 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=4MxOnsti7KmbY8uEP8vhT98QYhMB7xdjMYFj8udnqbw=; b=mZnaD13A5cYgjggFSFRsUrsAfWl7uKw+xFhB2VIKecPsg47VkB2UPgNvt9UXqa8j7Y 7bBLlKMBw3ZvoF1bt6q/0GkdodXXZsfgaiuLvmCOgDmVTyvT8fpN67sh1Kaj3iRp70Ex eRmtKKTbnpCPDLCziUzfb7uyid6SgosWmDyVg7udBoIOO2NNy157mEgSYWxLDHvytFp1 CQeBZMU2gsyJWIvpgDN2zqY+oVmqGtFtpuC7ucPelypS6Og3Ss6C8llhfYGbAw9WXRmy id+s/UibHwfvieNUrruCCNfrRGRZUoaQYjDJYsJIwVphiKtS0pMEzMBsNdBmGP25sGa/ GMeA== X-Gm-Message-State: ALyK8tLvoi00JqS6trdoKopiCSlpV9b3gHwdhS/rEAKuLek1imi7WoESgVtc4oQzomdV33NK X-Received: by 10.46.5.199 with SMTP id 190mr1387407ljf.10.1465392655132; Wed, 08 Jun 2016 06:30:55 -0700 (PDT) Received: from beaming.home (91-157-170-157.elisa-laajakaista.fi. [91.157.170.157]) by smtp.gmail.com with ESMTPSA id 2sm139854lja.37.2016.06.08.06.30.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 08 Jun 2016 06:30:54 -0700 (PDT) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Wed, 8 Jun 2016 16:30:04 +0300 Message-Id: <90c0f080fe6fdd8b18691e6e38c853c8a996ad92.1465392531.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] X-Received-From: 2a00:1450:4010:c07::22d Subject: [Qemu-devel] [PULL 23/44] 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: Peter Maydell Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Peter Maydell Reimplement target_to_host_siginfo() to use __get_user(), which handles possibly misaligned source guest structures correctly. Reviewed-by: Laurent Vivier Signed-off-by: Peter Maydell Signed-off-by: Riku Voipio --- 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 8ea0cbf..61c1145 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -408,13 +408,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)