From patchwork Wed Sep 26 17:12:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Dr. David Alan Gilbert" X-Patchwork-Id: 147604 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp998150lji; Wed, 26 Sep 2018 10:28:39 -0700 (PDT) X-Google-Smtp-Source: ACcGV60nNNxeIs2UH3/BPPYqv5uPJmM9zhX114e1AAEkmgPEwN/t6UH/wjWLlR1V6NpgeVc9N4Ok X-Received: by 2002:aed:36e5:: with SMTP id f92-v6mr5075916qtb.276.1537982919280; Wed, 26 Sep 2018 10:28:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537982919; cv=none; d=google.com; s=arc-20160816; b=ENZICethBxoMjl/9MzwGgN+5EcX1CD5IoiMLJxQn+NSDjHHb9PJpNHxwhg8JDE5X4A TX3Q03KeHdyisdxosUb8Pg3YufvXxFMNQ8M9yFOECbX48EbbsYIKka8eW97jPJH7iOS/ LCRp2Ko3dWgzBeXj0864cWns1K5v3iNJBhXRkF+WCaoQPeFgzdxM5qFAixR/jM+3kWxU o+smDOEVNneIzbMP+gHT2T+fCVV+iiMnC6qT7tS9BV//CxXDupcAzGFGJE/A6nUf3MQw 2wuWhRXlW8oVyNrwG3TKqKp8AZkUhUh/8irvRak+Aywn/JcgOBAWbZhnKUjChSyk+qJH qjxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from; bh=YlOJ39lnysBGFPLdo3ZzWecpcwU/U3M71ce5f6MMr+o=; b=MfwKrkvVhSUaw4p+DBgm6rZVSbJW2JHQ72RXdZTjNQj3x2iTvNchGiTgSdPB5t4QqH xKXrC3mRx6dDc54GZWF9qHModtgG170L2Ns294Pyj+r6f1a3cjw3EjcYdksNjz/6RRf/ PFBZAEA/35Fx8+7a/lgbaL9j0m7bDEY+jmQbaeLgE/ODtd3ov/IgDnrjQAoXcaNwKJv/ tVNlRJPvP1LlrrHHw7WF8eU/+Ig7JSkHSHvZZQ6trlo7TFvCOXGTD45oAChc9htU8DmE XQH6TOWgIx2JwpgMv30IAooM01Ycn/xBNCbzMh6pXxGhzCwo6hwetuM+Qvjhn7hMngUg 5Q7Q== ARC-Authentication-Results: i=1; mx.google.com; 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 sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id v190-v6si4021136qkc.368.2018.09.26.10.28.39 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 26 Sep 2018 10:28:39 -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; 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 sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([::1]:59946 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g5Dc6-0006rM-R2 for patch@linaro.org; Wed, 26 Sep 2018 13:28:38 -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) 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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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 value [-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 value [-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 value [-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 value [-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é Lureau Signed-off-by: Dr. David Alan Gilbert --- migration/ram.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) -- 2.17.1 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, Error **errp) return -1; } - be32_to_cpus(&msg.magic); - be32_to_cpus(&msg.version); + msg.magic = be32_to_cpu(msg.magic); + msg.version = be32_to_cpu(msg.version); if (msg.magic != 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; - be32_to_cpus(&packet->magic); + packet->magic = be32_to_cpu(packet->magic); if (packet->magic != 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; } - be32_to_cpus(&packet->version); + packet->version = be32_to_cpu(packet->version); if (packet->version != 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) p->flags = be32_to_cpu(packet->flags); - be32_to_cpus(&packet->size); + packet->size = 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",