From nobody Sun Feb 8 17:47:51 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1537982958851751.0662333099949; Wed, 26 Sep 2018 10:29:18 -0700 (PDT) Received: from localhost ([::1]:59947 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g5Dcj-00079l-Sf for importer@patchew.org; Wed, 26 Sep 2018 13:29:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52875) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g5DNa-0001Ap-Jz for qemu-devel@nongnu.org; Wed, 26 Sep 2018 13:13:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g5DNZ-0008PV-R1 for qemu-devel@nongnu.org; Wed, 26 Sep 2018 13:13:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41486) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g5DNZ-0008Oq-HC for qemu-devel@nongnu.org; Wed, 26 Sep 2018 13:13:37 -0400 Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C65F93097031; Wed, 26 Sep 2018 17:13:36 +0000 (UTC) Received: from dgilbert-t530.redhat.com (unknown [10.36.118.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0C5CCDB561; Wed, 26 Sep 2018 17:13:34 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, xiaoguangrong@tencent.com, joserz@linux.ibm.com, wei@redhat.com, thuth@redhat.com, marcandre.lureau@redhat.com, fli@suse.com Date: Wed, 26 Sep 2018 18:12:36 +0100 Message-Id: <20180926171236.45203-17-dgilbert@redhat.com> In-Reply-To: <20180926171236.45203-1-dgilbert@redhat.com> References: <20180926171236.45203-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Wed, 26 Sep 2018 17:13:36 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 16/16] migration/ram.c: Avoid taking address of fields in packed MultiFDInit_t struct 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: quintela@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Peter Maydell Taking the address of a field in a packed struct is a bad idea, because it might not be actually aligned enough for that pointer type (and thus cause a crash on dereference on some host architectures). Newer versions of clang warn about this: migration/ram.c:651:19: warning: taking address of packed member 'magic' of= class or structure 'MultiFDInit_t' may result in an unaligned pointer valu= e [-Waddress-of-packed-member] migration/ram.c:652:19: warning: taking address of packed member 'version' = of class or structure 'MultiFDInit_t' may result in an unaligned pointer va= lue [-Waddress-of-packed-member] migration/ram.c:737:19: warning: taking address of packed member 'magic' of= class or structure 'MultiFDPacket_t' may result in an unaligned pointer va= lue [-Waddress-of-packed-member] migration/ram.c:745:19: warning: taking address of packed member 'version' = of class or structure 'MultiFDPacket_t' may result in an unaligned pointer = value [-Waddress-of-packed-member] migration/ram.c:755:19: warning: taking address of packed member 'size' of = class or structure 'MultiFDPacket_t' may result in an unaligned pointer val= ue [-Waddress-of-packed-member] Avoid the bug by not using the "modify in place" byteswapping functions. Signed-off-by: Peter Maydell Message-Id: <20180925161924.7832-1-peter.maydell@linaro.org> Reviewed-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Dr. David Alan Gilbert --- migration/ram.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 408d237700..bc38d98cc3 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -651,8 +651,8 @@ static int multifd_recv_initial_packet(QIOChannel *c, E= rror **errp) return -1; } =20 - be32_to_cpus(&msg.magic); - be32_to_cpus(&msg.version); + msg.magic =3D be32_to_cpu(msg.magic); + msg.version =3D be32_to_cpu(msg.version); =20 if (msg.magic !=3D MULTIFD_MAGIC) { error_setg(errp, "multifd: received packet magic %x " @@ -737,7 +737,7 @@ static int multifd_recv_unfill_packet(MultiFDRecvParams= *p, Error **errp) RAMBlock *block; int i; =20 - be32_to_cpus(&packet->magic); + packet->magic =3D be32_to_cpu(packet->magic); if (packet->magic !=3D MULTIFD_MAGIC) { error_setg(errp, "multifd: received packet " "magic %x and expected magic %x", @@ -745,7 +745,7 @@ static int multifd_recv_unfill_packet(MultiFDRecvParams= *p, Error **errp) return -1; } =20 - be32_to_cpus(&packet->version); + packet->version =3D be32_to_cpu(packet->version); if (packet->version !=3D MULTIFD_VERSION) { error_setg(errp, "multifd: received packet " "version %d and expected version %d", @@ -755,7 +755,7 @@ static int multifd_recv_unfill_packet(MultiFDRecvParams= *p, Error **errp) =20 p->flags =3D be32_to_cpu(packet->flags); =20 - be32_to_cpus(&packet->size); + packet->size =3D be32_to_cpu(packet->size); if (packet->size > migrate_multifd_page_count()) { error_setg(errp, "multifd: received packet " "with size %d and expected maximum size %d", --=20 2.17.1