From patchwork Tue Jun 28 19:12:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 71145 Delivered-To: patch@linaro.org Received: by 10.140.28.4 with SMTP id 4csp1761541qgy; Tue, 28 Jun 2016 12:20:25 -0700 (PDT) X-Received: by 10.237.47.228 with SMTP id m91mr4640456qtd.35.1467141625079; Tue, 28 Jun 2016 12:20:25 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id u21si229072qkl.71.2016.06.28.12.20.24 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 28 Jun 2016 12:20:25 -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]:39013 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bHyYa-0000Tl-F3 for patch@linaro.org; Tue, 28 Jun 2016 15:20:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38282) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bHyRX-0001fw-40 for qemu-devel@nongnu.org; Tue, 28 Jun 2016 15:13:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bHyRT-0006oA-JT for qemu-devel@nongnu.org; Tue, 28 Jun 2016 15:13:06 -0400 Received: from mail-lf0-x235.google.com ([2a00:1450:4010:c07::235]:33218) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bHyRT-0006nR-Bc for qemu-devel@nongnu.org; Tue, 28 Jun 2016 15:13:03 -0400 Received: by mail-lf0-x235.google.com with SMTP id f6so18198349lfg.0 for ; Tue, 28 Jun 2016 12:13:03 -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=C55g9nK7YF5D6Yw+60VAGVNLlDfa1T6wdMVi+zReH3J4/1zortVzcbUk3ZlaAJiokt +EtFAvKLq3V4ZXeazAOQquazQLohhYF4z0++vZT8oPCzcOb7VIPyzBm3kCxPEwjcZHLf gDR+1S6YCsgyFwJCRBeJP4P0A34+ZsCzg3+5Y= 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=LIvjoQgC3fnUH0TjZR9/j7UoVy8lJjZvPoaZ5oXw5RghKhUk4SxxY/hcB27u959Lv7 6xqLEf+eWOeblvdXw++UJ08RAtB1A7/lgXstCUA7B+uogPUCQLBmN2vT1Dk5vxED3fnD MvaZ1QU3Ucv69tOcHm7lhysQgnF6yuDuojaXOGP4zdo2bPMjNZcvQwrpdu47vAWBZaOG culTxzxv2H9hlY1y5zgGxcVmvR69NdCmLZIJAJEy5VMfZUGaiNPFAqhhYtOOZlEdEaaZ JTjFLjkVTYVTisCsibyM2V88T9QG93NpkwTR6OyuTZFlsLftlXbPvG1JE+gTxp95UC5O GK0w== X-Gm-Message-State: ALyK8tIMA9JdsadC5kupDHSACi3dEoId0jvB3NMXdda357DvNga+0n3brBWOZvxajAt8PMic X-Received: by 10.25.80.21 with SMTP id e21mr1493579lfb.96.1467141182592; Tue, 28 Jun 2016 12:13:02 -0700 (PDT) Received: from beaming.home (91-157-170-157.elisa-laajakaista.fi. [91.157.170.157]) by smtp.gmail.com with ESMTPSA id h10sm4262823ljh.38.2016.06.28.12.13.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 28 Jun 2016 12:13:01 -0700 (PDT) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Tue, 28 Jun 2016 22:12:35 +0300 Message-Id: <55d72a7eb32858d50ba0777cfde2027d007010b2.1467138806.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::235 Subject: [Qemu-devel] [PULL v2 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. */