From patchwork Fri Jun 24 09:52:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 70806 Delivered-To: patch@linaro.org Received: by 10.140.28.4 with SMTP id 4csp861199qgy; Fri, 24 Jun 2016 02:59:56 -0700 (PDT) X-Received: by 10.237.35.92 with SMTP id i28mr3402892qtc.85.1466762396959; Fri, 24 Jun 2016 02:59:56 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id k76si4288427qkh.258.2016.06.24.02.59.56 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 24 Jun 2016 02:59:56 -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; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:42267 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bGNu0-0007io-EK for patch@linaro.org; Fri, 24 Jun 2016 05:59:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58737) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bGNnm-0000ei-V4 for qemu-devel@nongnu.org; Fri, 24 Jun 2016 05:53:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bGNnh-0003Cp-9V for qemu-devel@nongnu.org; Fri, 24 Jun 2016 05:53:29 -0400 Received: from mail-lf0-x232.google.com ([2a00:1450:4010:c07::232]:32877) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bGNnh-0003CK-1d for qemu-devel@nongnu.org; Fri, 24 Jun 2016 05:53:25 -0400 Received: by mail-lf0-x232.google.com with SMTP id f6so112301795lfg.0 for ; Fri, 24 Jun 2016 02:53:24 -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=JFoGn7IW9zKXcirOZeEW1CSY1jjrK8SqqXrF2n38qpU=; b=Wzq68Hpc2v0EoeLvLrRlSKFmclfdggEwYMg9ZKNfZ9kMABrPG1c3WnUBer5X1ksnOS D2CbmuW+HIp3ZBAdlTqqKxHL54Nm1T3PxhGcMfEoIDOmDOaVjfPdzBF1NVVZP0rIN1dd odx3g/JVTDUVTIRlWgPQMeqZ7Sw5k5a3rZg5U= 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=JFoGn7IW9zKXcirOZeEW1CSY1jjrK8SqqXrF2n38qpU=; b=MCOYzTCi4K01z4ApX0KD7OMmDlT4UGbnn517q5N9nRoH6AJkTcTRCM8DgnOdKJZs1L yHfNouD2gVHs1ku8Qi9doZahD6Fcfy6gJVei4nJj2kBUlTq/yAKmGrG3t7c4hWsSo5Yl e2kY5T5BkT9QbMQaKnag+6MS77uiNG9ISUztgJYZ94qgL6UifGA1DLPFFL2ReoIzQBwz GMs946SPiqozpHRH8bkQROSf7UqC03PaW5+EUxnb7WfDtIL8LTKKpY52UfsmnBz6eo0W mHpDR+8+aDCq9YoByoGBdQARy27bdy8K02mkn9QZN5iFBtu46SAieTrQjduh+iWKzNQW 8MbA== X-Gm-Message-State: ALyK8tKVjWHfC8x1kKq9xFtHQEZpALavb9QX/XJ5AkDNKzHOJEb7LrgeqPMQYxac9emeKM5W X-Received: by 10.25.168.202 with SMTP id r193mr1161866lfe.85.1466762004104; Fri, 24 Jun 2016 02:53:24 -0700 (PDT) Received: from beaming.home (85-76-80-69-nat.elisa-mobile.fi. [85.76.80.69]) by smtp.gmail.com with ESMTPSA id o137sm798203lfe.2.2016.06.24.02.53.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 24 Jun 2016 02:53:23 -0700 (PDT) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Fri, 24 Jun 2016 12:52:56 +0300 Message-Id: <55d72a7eb32858d50ba0777cfde2027d007010b2.1466760944.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::232 Subject: [Qemu-devel] [PULL 01/24] linux-user: Avoid possible misalignment in host_to_target_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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Peter Maydell host_to_target_siginfo() is implemented by a combination of host_to_target_siginfo_noswap() followed by tswap_siginfo(). The first of these two functions assumes that the target_siginfo_t it is writing to is correctly aligned, but the pointer passed into host_to_target_siginfo() is directly from the guest and might be misaligned. Use a local variable to avoid this problem. (tswap_siginfo() does now correctly handle a misaligned destination.) We have to add a memset() to host_to_target_siginfo_noswap() to avoid some false positive "may be used uninitialized" warnings from gcc about subfields of the _sifields union if it chooses to inline both tswap_siginfo() and host_to_target_siginfo_noswap() into host_to_target_siginfo(). Signed-off-by: Peter Maydell Reviewed-by: Laurent Vivier Signed-off-by: Peter Maydell --- linux-user/signal.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) -- 2.1.4 diff --git a/linux-user/signal.c b/linux-user/signal.c index 1dadddf..e2d55ff 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -278,6 +278,14 @@ static inline void host_to_target_siginfo_noswap(target_siginfo_t *tinfo, tinfo->si_errno = 0; tinfo->si_code = info->si_code; + /* This memset serves two purposes: + * (1) ensure we don't leak random junk to the guest later + * (2) placate false positives from gcc about fields + * being used uninitialized if it chooses to inline both this + * function and tswap_siginfo() into host_to_target_siginfo(). + */ + memset(tinfo->_sifields._pad, 0, sizeof(tinfo->_sifields._pad)); + /* This is awkward, because we have to use a combination of * the si_code and si_signo to figure out which of the union's * members are valid. (Within the host kernel it is always possible @@ -397,8 +405,9 @@ static void tswap_siginfo(target_siginfo_t *tinfo, void host_to_target_siginfo(target_siginfo_t *tinfo, const siginfo_t *info) { - host_to_target_siginfo_noswap(tinfo, info); - tswap_siginfo(tinfo, tinfo); + target_siginfo_t tgt_tmp; + host_to_target_siginfo_noswap(&tgt_tmp, info); + tswap_siginfo(tinfo, &tgt_tmp); } /* XXX: we support only POSIX RT signals are used. */