From patchwork Mon Nov 5 16:37:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 150213 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp2827254ljp; Mon, 5 Nov 2018 08:45:50 -0800 (PST) X-Google-Smtp-Source: AJdET5efwxSUDLDhAx82BPTf1RUci/9SAFPcORVen8eVyNGEMLzja91HoVRK2FqVUdf39h8ts7JT X-Received: by 2002:a37:5108:: with SMTP id f8-v6mr20208219qkb.288.1541436350242; Mon, 05 Nov 2018 08:45:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541436350; cv=none; d=google.com; s=arc-20160816; b=Zjlel6XRwiiMjqUOy5ALUv7C1LuYp1ZdcSfZQNsrL8QZLtV30We0yOwpSLtkq8sCg+ UcQQTMRWYqkpu9DgqWdAJB0Vas2GdGnvXHm3CcKrV3o/9KipFsNnQ5MPpz3Hw0bpoMk4 rMKyIV+JPRPBXfeevgNd6+XQrVPg8kOFvcBKr4Sg34quY2g5XNUVZPzicqfWKy7Glzi4 kePAJ3AtfKhi2xTQ2p1xvzbf8Mx44QlYmOf8n3oupTtGHR0KHvD+kdEqefRz9lNs/kDd kIodJzVSKvS4sDsVbr+euvVxbmMW/EynkYYKaHssgYMIYAjSW3H9w55kZ6ZYgvlvdDre 2J1w== 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=EIgzGSJtbELCvYpUPB63uB1dSMrQB2hpBA1fKHNKGbk=; b=Dh3AJo42Q4WlJPytre5KOn9+3vkSNd8JM4mcJZjy/HHAPtem9rY3NZrl/SU8pw/BRT WfoMJTx2zj/oIjCu+IbUFwLuh8CRZFGOAuGNdi4yuSjKYnsDgj7qpk5MtVCMhiE+oeZV QmDif+auauw02hNsLx+MPmLQdzXyMRfbRR5KzAcccG4p3V2p0viDYL7mEVl8cqqwfg28 yYJs1Tf1lA9DoH/xqTJdABVMYcY8RGRkVDH8g7AhLvntGvX2RcxQ3aGI9tQ/kPI8diZt vCZYQFB3J+QC9hwr815j3sJcMd6+4aPfOAmaFCLaq2q3HsYwSMKgCIs18+ND6fm2ZNpp hF4w== 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 h2-v6si5654180qkd.169.2018.11.05.08.45.50 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 05 Nov 2018 08:45:50 -0800 (PST) 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]:36205 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJi0b-0001Hy-Mv for patch@linaro.org; Mon, 05 Nov 2018 11:45:49 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50373) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJhtJ-0006x5-8P for qemu-devel@nongnu.org; Mon, 05 Nov 2018 11:38:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gJhtH-0003V3-As for qemu-devel@nongnu.org; Mon, 05 Nov 2018 11:38:17 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36318) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gJht2-0002Xx-KB; Mon, 05 Nov 2018 11:38:01 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 86ECB3091751; Mon, 5 Nov 2018 16:37:57 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-198.ams2.redhat.com [10.36.117.198]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6754560C46; Mon, 5 Nov 2018 16:37:56 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Mon, 5 Nov 2018 17:37:12 +0100 Message-Id: <20181105163744.25139-5-kwolf@redhat.com> In-Reply-To: <20181105163744.25139-1-kwolf@redhat.com> References: <20181105163744.25139-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Mon, 05 Nov 2018 16:37:57 +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 04/36] block/qcow2: Don't take address of fields in packed structs 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: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org 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. Avoid the bug by not using the "modify in place" byte swapping functions. There are a few places where the in-place swap function is used on something other than a packed struct field; we convert those anyway, for consistency. This patch was produced with the following spatch script (and hand-editing to fold a few resulting overlength lines): @@ expression E; @@ -be16_to_cpus(&E); +E = be16_to_cpu(E); @@ expression E; @@ -be32_to_cpus(&E); +E = be32_to_cpu(E); @@ expression E; @@ -be64_to_cpus(&E); +E = be64_to_cpu(E); @@ expression E; @@ -cpu_to_be16s(&E); +E = cpu_to_be16(E); @@ expression E; @@ -cpu_to_be32s(&E); +E = cpu_to_be32(E); @@ expression E; @@ -cpu_to_be64s(&E); +E = cpu_to_be64(E); Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Tested-by: John Snow Reviewed-by: John Snow Signed-off-by: Kevin Wolf --- block/qcow2.c | 64 +++++++++++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 30 deletions(-) -- 2.19.1 diff --git a/block/qcow2.c b/block/qcow2.c index 30689b7688..de94b290e6 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -210,8 +210,8 @@ static int qcow2_read_extensions(BlockDriverState *bs, uint64_t start_offset, "pread fail from offset %" PRIu64, offset); return 1; } - be32_to_cpus(&ext.magic); - be32_to_cpus(&ext.len); + ext.magic = be32_to_cpu(ext.magic); + ext.len = be32_to_cpu(ext.len); offset += sizeof(ext); #ifdef DEBUG_EXT printf("ext.magic = 0x%x\n", ext.magic); @@ -279,8 +279,8 @@ static int qcow2_read_extensions(BlockDriverState *bs, uint64_t start_offset, "Unable to read CRYPTO header extension"); return ret; } - be64_to_cpus(&s->crypto_header.offset); - be64_to_cpus(&s->crypto_header.length); + s->crypto_header.offset = be64_to_cpu(s->crypto_header.offset); + s->crypto_header.length = be64_to_cpu(s->crypto_header.length); if ((s->crypto_header.offset % s->cluster_size) != 0) { error_setg(errp, "Encryption header offset '%" PRIu64 "' is " @@ -342,9 +342,11 @@ static int qcow2_read_extensions(BlockDriverState *bs, uint64_t start_offset, return -EINVAL; } - be32_to_cpus(&bitmaps_ext.nb_bitmaps); - be64_to_cpus(&bitmaps_ext.bitmap_directory_size); - be64_to_cpus(&bitmaps_ext.bitmap_directory_offset); + bitmaps_ext.nb_bitmaps = be32_to_cpu(bitmaps_ext.nb_bitmaps); + bitmaps_ext.bitmap_directory_size = + be64_to_cpu(bitmaps_ext.bitmap_directory_size); + bitmaps_ext.bitmap_directory_offset = + be64_to_cpu(bitmaps_ext.bitmap_directory_offset); if (bitmaps_ext.nb_bitmaps > QCOW2_MAX_BITMAPS) { error_setg(errp, @@ -1159,19 +1161,20 @@ static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options, error_setg_errno(errp, -ret, "Could not read qcow2 header"); goto fail; } - be32_to_cpus(&header.magic); - be32_to_cpus(&header.version); - be64_to_cpus(&header.backing_file_offset); - be32_to_cpus(&header.backing_file_size); - be64_to_cpus(&header.size); - be32_to_cpus(&header.cluster_bits); - be32_to_cpus(&header.crypt_method); - be64_to_cpus(&header.l1_table_offset); - be32_to_cpus(&header.l1_size); - be64_to_cpus(&header.refcount_table_offset); - be32_to_cpus(&header.refcount_table_clusters); - be64_to_cpus(&header.snapshots_offset); - be32_to_cpus(&header.nb_snapshots); + header.magic = be32_to_cpu(header.magic); + header.version = be32_to_cpu(header.version); + header.backing_file_offset = be64_to_cpu(header.backing_file_offset); + header.backing_file_size = be32_to_cpu(header.backing_file_size); + header.size = be64_to_cpu(header.size); + header.cluster_bits = be32_to_cpu(header.cluster_bits); + header.crypt_method = be32_to_cpu(header.crypt_method); + header.l1_table_offset = be64_to_cpu(header.l1_table_offset); + header.l1_size = be32_to_cpu(header.l1_size); + header.refcount_table_offset = be64_to_cpu(header.refcount_table_offset); + header.refcount_table_clusters = + be32_to_cpu(header.refcount_table_clusters); + header.snapshots_offset = be64_to_cpu(header.snapshots_offset); + header.nb_snapshots = be32_to_cpu(header.nb_snapshots); if (header.magic != QCOW_MAGIC) { error_setg(errp, "Image is not in qcow2 format"); @@ -1207,11 +1210,12 @@ static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options, header.refcount_order = 4; header.header_length = 72; } else { - be64_to_cpus(&header.incompatible_features); - be64_to_cpus(&header.compatible_features); - be64_to_cpus(&header.autoclear_features); - be32_to_cpus(&header.refcount_order); - be32_to_cpus(&header.header_length); + header.incompatible_features = + be64_to_cpu(header.incompatible_features); + header.compatible_features = be64_to_cpu(header.compatible_features); + header.autoclear_features = be64_to_cpu(header.autoclear_features); + header.refcount_order = be32_to_cpu(header.refcount_order); + header.header_length = be32_to_cpu(header.header_length); if (header.header_length < 104) { error_setg(errp, "qcow2 header too short"); @@ -1400,7 +1404,7 @@ static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options, goto fail; } for(i = 0;i < s->l1_size; i++) { - be64_to_cpus(&s->l1_table[i]); + s->l1_table[i] = be64_to_cpu(s->l1_table[i]); } } @@ -2392,13 +2396,13 @@ int qcow2_update_header(BlockDriverState *bs) /* Full disk encryption header pointer extension */ if (s->crypto_header.offset != 0) { - cpu_to_be64s(&s->crypto_header.offset); - cpu_to_be64s(&s->crypto_header.length); + s->crypto_header.offset = cpu_to_be64(s->crypto_header.offset); + s->crypto_header.length = cpu_to_be64(s->crypto_header.length); ret = header_ext_add(buf, QCOW2_EXT_MAGIC_CRYPTO_HEADER, &s->crypto_header, sizeof(s->crypto_header), buflen); - be64_to_cpus(&s->crypto_header.offset); - be64_to_cpus(&s->crypto_header.length); + s->crypto_header.offset = be64_to_cpu(s->crypto_header.offset); + s->crypto_header.length = be64_to_cpu(s->crypto_header.length); if (ret < 0) { goto fail; } From patchwork Mon Nov 5 16:37:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 150215 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp2828916ljp; Mon, 5 Nov 2018 08:47:17 -0800 (PST) X-Google-Smtp-Source: AJdET5fQ7m1E0FQVivOmeDS6a/+IaMtXN7czak6ePOKU/fpFd3InLTUd3X+icrElN2XjA9uqxr6g X-Received: by 2002:a0c:c611:: with SMTP id v17mr9405647qvi.68.1541436437300; Mon, 05 Nov 2018 08:47:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541436437; cv=none; d=google.com; s=arc-20160816; b=ENGzahhMk8GZKadClv4BfDeu/t/ewFb+vI5NunwwJ7A23Vy1V4BXQDsgvMwacFVls8 PYzysGjcfOOZvXhHB9hnI0mIRo1FvvHvMJbUEn0CmZjXEdXymtcg3Jr46q6wtnHulCsw 6OXZ6DVBUHllqRAr5zre//raLzdWm93v7reytBOgH+WFHryHo8/XjlWouWVUTb2sBW8r Ypoy2oypkQ1qGB5gf6sDoe06jN2qRl2I7jEL6+NUesVIe8lkVtvFwzR1io3Qa5SOhknz +ceEw74nKWqPUaJAoXMc1yALm3udf9BQSuH3+TXzHbT7rE813ktjHuh50y+Y1UXlRhzp lZyw== 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=kp+btyaEsflNZ/yvzkneaUlhSGNgxXjfdN79gcsZh/k=; b=K/qMVHzQNaNs4K2twuUGgVzTBxB3YWCEc9CjLNLOLDZhul+L0KRBopr77mPXrRh/sT xgczo1ufYgDFDae6VSKynIwPRdjq041PjPO/CJOFXACMRn7MmT7PWQMLXvbBAdZR5/jy QpVusmLQsU2soQknzmROoqQTLUDl44KiAFCzlCnPeLCugN7CKon+pXviYziVz2V53rJO CIMazaHJF2NIKJlIfTYsaNahL0Ga/nExtcW+LoBl6zW+r3Wns2bc2o2C8jDt5r3NkmI3 FLUUPNnn5wyKGBNTFLnTw4jrlFsFEZ5UoIb2wRpgMpl7VmVeYqZuQhypHwldiLErOKFO 4NYw== 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 c127-v6si9653326qkf.236.2018.11.05.08.47.17 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 05 Nov 2018 08:47:17 -0800 (PST) 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]:36213 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJi20-0002Lp-KP for patch@linaro.org; Mon, 05 Nov 2018 11:47:16 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50363) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJhtJ-0006wm-13 for qemu-devel@nongnu.org; Mon, 05 Nov 2018 11:38:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gJhtH-0003V2-9z for qemu-devel@nongnu.org; Mon, 05 Nov 2018 11:38:16 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35794) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gJht3-0002bq-Cb; Mon, 05 Nov 2018 11:38:01 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E5FAEC004AB3; Mon, 5 Nov 2018 16:37:58 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-198.ams2.redhat.com [10.36.117.198]) by smtp.corp.redhat.com (Postfix) with ESMTP id D3A5060C46; Mon, 5 Nov 2018 16:37:57 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Mon, 5 Nov 2018 17:37:13 +0100 Message-Id: <20181105163744.25139-6-kwolf@redhat.com> In-Reply-To: <20181105163744.25139-1-kwolf@redhat.com> References: <20181105163744.25139-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 05 Nov 2018 16:37:58 +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 05/36] block/qcow: Don't take address of fields in packed structs 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: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org 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. Avoid the bug by not using the "modify in place" byte swapping functions. There are a few places where the in-place swap function is used on something other than a packed struct field; we convert those anyway, for consistency. This patch was produced with the following spatch script: @@ expression E; @@ -be16_to_cpus(&E); +E = be16_to_cpu(E); @@ expression E; @@ -be32_to_cpus(&E); +E = be32_to_cpu(E); @@ expression E; @@ -be64_to_cpus(&E); +E = be64_to_cpu(E); @@ expression E; @@ -cpu_to_be16s(&E); +E = cpu_to_be16(E); @@ expression E; @@ -cpu_to_be32s(&E); +E = cpu_to_be32(E); @@ expression E; @@ -cpu_to_be64s(&E); +E = cpu_to_be64(E); Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Tested-by: John Snow Reviewed-by: John Snow Signed-off-by: Kevin Wolf --- block/qcow.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) -- 2.19.1 diff --git a/block/qcow.c b/block/qcow.c index 385d935258..4518cb4c35 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -140,14 +140,14 @@ static int qcow_open(BlockDriverState *bs, QDict *options, int flags, if (ret < 0) { goto fail; } - be32_to_cpus(&header.magic); - be32_to_cpus(&header.version); - be64_to_cpus(&header.backing_file_offset); - be32_to_cpus(&header.backing_file_size); - be32_to_cpus(&header.mtime); - be64_to_cpus(&header.size); - be32_to_cpus(&header.crypt_method); - be64_to_cpus(&header.l1_table_offset); + header.magic = be32_to_cpu(header.magic); + header.version = be32_to_cpu(header.version); + header.backing_file_offset = be64_to_cpu(header.backing_file_offset); + header.backing_file_size = be32_to_cpu(header.backing_file_size); + header.mtime = be32_to_cpu(header.mtime); + header.size = be64_to_cpu(header.size); + header.crypt_method = be32_to_cpu(header.crypt_method); + header.l1_table_offset = be64_to_cpu(header.l1_table_offset); if (header.magic != QCOW_MAGIC) { error_setg(errp, "Image not in qcow format"); @@ -270,7 +270,7 @@ static int qcow_open(BlockDriverState *bs, QDict *options, int flags, } for(i = 0;i < s->l1_size; i++) { - be64_to_cpus(&s->l1_table[i]); + s->l1_table[i] = be64_to_cpu(s->l1_table[i]); } /* alloc L2 cache (max. 64k * 16 * 8 = 8 MB) */ From patchwork Mon Nov 5 16:37:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 150214 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp2827763ljp; Mon, 5 Nov 2018 08:46:19 -0800 (PST) X-Google-Smtp-Source: AJdET5dSJp5gmU26PEyQetrI+RngcwNkDencJc0dExCEBiCDYXP09t/8yun6zLG6YZaPwIX4iCXd X-Received: by 2002:a37:73c4:: with SMTP id o187mr18880223qkc.157.1541436379651; Mon, 05 Nov 2018 08:46:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541436379; cv=none; d=google.com; s=arc-20160816; b=rd2j5SrMxbngTMbF6YXq+dHqI21uUcDLNSr+lnx9Z0POX32ou40J9x+LDIUvDjhvrl JZdN00auiPf9YmI75hdz+MoAGECuz2KuGEskWAHiLnt6XqPlGney1WT5k/SUY8Ip1GWb s3IdMcSUqYx8LBY4BwLF32CwA/+DKQc1DcZjSbrB9j6HrNkf+l4kqO/+ZqBf6y+c4wqe VhxqRgCHxafnyOseclhP3wZuYWTq74weFDCj/YPdeldhU+c/fLVQZOQWe9EPtB7PIMTt V2aWG7UTXiuLbMKQ7MZScsNnkaE33S7W81l9B5KbIuwRhpaZ5TQ/rlAPx85ZzmT3hLSW 7GtA== 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=Pvramo0/jaedqppI6rqU+I+k4EtkKmOfq8P+UTEA0Uo=; b=sogfNPV6Ejx4Xvy+U81cii3WPhbwCjcdWFLicYOfVNUmfDcVd45ifxjR1nv2jOZHl2 3uA46AyzZy7igmv4V24pzN/AaBIwSR7ELddlJPD4dTZiLgfcBvnsbiuujhLqYSHCZRgl IeK5TZv5lGI4RF2fnSyVrlZzGiHOYXgXeUno/Ne3vBJRfCpyujU4PmipVzKmjNC5j1UV 8oEwcWM8bOqJhkgo8F/hyr+VemtT69jLE7NlthbYy/v4Dnyz4zUgz5ii07YunAPmLpPY VgeFpXRc8sdxjC/n/+MgnAhQzLvL/M12NR4nr4uJyCB55TjxtJDUYbINtlFngnjoehKD G7xg== 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 e7si1043898qvp.159.2018.11.05.08.46.19 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 05 Nov 2018 08:46:19 -0800 (PST) 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]:36206 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJi15-0001MK-2H for patch@linaro.org; Mon, 05 Nov 2018 11:46:19 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50369) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJhtJ-0006wx-5J for qemu-devel@nongnu.org; Mon, 05 Nov 2018 11:38:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gJhtH-0003VC-A5 for qemu-devel@nongnu.org; Mon, 05 Nov 2018 11:38:16 -0500 Received: from mx1.redhat.com ([209.132.183.28]:40764) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gJht3-0002gL-Um; Mon, 05 Nov 2018 11:38:02 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 56FF981DE3; Mon, 5 Nov 2018 16:38:00 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-198.ams2.redhat.com [10.36.117.198]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3CF1760C5C; Mon, 5 Nov 2018 16:37:59 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Mon, 5 Nov 2018 17:37:14 +0100 Message-Id: <20181105163744.25139-7-kwolf@redhat.com> In-Reply-To: <20181105163744.25139-1-kwolf@redhat.com> References: <20181105163744.25139-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 05 Nov 2018 16:38:00 +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 06/36] block/qcow2-bitmap: Don't take address of fields in packed structs 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: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org 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. Avoid the bug by not using the "modify in place" byte swapping functions. There are a few places where the in-place swap function is used on something other than a packed struct field; we convert those anyway, for consistency. This patch was produced with the following spatch script: @@ expression E; @@ -be16_to_cpus(&E); +E = be16_to_cpu(E); @@ expression E; @@ -be32_to_cpus(&E); +E = be32_to_cpu(E); @@ expression E; @@ -be64_to_cpus(&E); +E = be64_to_cpu(E); @@ expression E; @@ -cpu_to_be16s(&E); +E = cpu_to_be16(E); @@ expression E; @@ -cpu_to_be32s(&E); +E = cpu_to_be32(E); @@ expression E; @@ -cpu_to_be64s(&E); +E = cpu_to_be64(E); Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Tested-by: John Snow Reviewed-by: John Snow Signed-off-by: Kevin Wolf --- block/qcow2-bitmap.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) -- 2.19.1 diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c index b5f1b3563d..accebef4cf 100644 --- a/block/qcow2-bitmap.c +++ b/block/qcow2-bitmap.c @@ -118,7 +118,7 @@ static inline void bitmap_table_to_be(uint64_t *bitmap_table, size_t size) size_t i; for (i = 0; i < size; ++i) { - cpu_to_be64s(&bitmap_table[i]); + bitmap_table[i] = cpu_to_be64(bitmap_table[i]); } } @@ -231,7 +231,7 @@ static int bitmap_table_load(BlockDriverState *bs, Qcow2BitmapTable *tb, } for (i = 0; i < tb->size; ++i) { - be64_to_cpus(&table[i]); + table[i] = be64_to_cpu(table[i]); ret = check_table_entry(table[i], s->cluster_size); if (ret < 0) { goto fail; @@ -394,20 +394,20 @@ fail: static inline void bitmap_dir_entry_to_cpu(Qcow2BitmapDirEntry *entry) { - be64_to_cpus(&entry->bitmap_table_offset); - be32_to_cpus(&entry->bitmap_table_size); - be32_to_cpus(&entry->flags); - be16_to_cpus(&entry->name_size); - be32_to_cpus(&entry->extra_data_size); + entry->bitmap_table_offset = be64_to_cpu(entry->bitmap_table_offset); + entry->bitmap_table_size = be32_to_cpu(entry->bitmap_table_size); + entry->flags = be32_to_cpu(entry->flags); + entry->name_size = be16_to_cpu(entry->name_size); + entry->extra_data_size = be32_to_cpu(entry->extra_data_size); } static inline void bitmap_dir_entry_to_be(Qcow2BitmapDirEntry *entry) { - cpu_to_be64s(&entry->bitmap_table_offset); - cpu_to_be32s(&entry->bitmap_table_size); - cpu_to_be32s(&entry->flags); - cpu_to_be16s(&entry->name_size); - cpu_to_be32s(&entry->extra_data_size); + entry->bitmap_table_offset = cpu_to_be64(entry->bitmap_table_offset); + entry->bitmap_table_size = cpu_to_be32(entry->bitmap_table_size); + entry->flags = cpu_to_be32(entry->flags); + entry->name_size = cpu_to_be16(entry->name_size); + entry->extra_data_size = cpu_to_be32(entry->extra_data_size); } static inline int calc_dir_entry_size(size_t name_size, size_t extra_data_size) From patchwork Mon Nov 5 16:37:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 150216 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp2829203ljp; Mon, 5 Nov 2018 08:47:34 -0800 (PST) X-Google-Smtp-Source: AJdET5coJfGmhLwQmXKWEne5G+GdKPU7v1KSIUfbCa8rrETFK0fa7gKbQCxGVCUGdBSPrthjWVDp X-Received: by 2002:a0c:8264:: with SMTP id h91mr22490826qva.116.1541436454766; Mon, 05 Nov 2018 08:47:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541436454; cv=none; d=google.com; s=arc-20160816; b=v671uIFcjnBT1kQw6t8vk1x7q0NTZDQftaUbpQRyujr+VL/XsXVwwasp8jw+IyQXyY a01dhwJpITcxONpkyaropTT5naracarc9ZosGaDRv0Pk9UE+H+cIy767YzjEGJDJmp/5 5+rHMBUZ3ppQoCM3mXO1yIeCiNYqSG1u1E4vZ8uySGjV650GWEa1ubHf7YpJHJ1nbHcx uZAdEqdrKMSb+sGkc0xCYkWofRtBG7Mm9iVpzxC0uJgtfmAbaA/TuELRcMdygxoF6TZC 7ZgtXA9skl5ZOPvg4FXNx+budNKWiUhzwtnHaPBh2k/NUdz3O8pL1gwhEeGwAFhwKM0j 9hzA== 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=zZSVuIVWpwKlA21JM1L9J6NePRHiQeLP1fk4SB4mrl0=; b=lC8lSIuYxsn07fiICFpLvlT+DlTHOBDHgwPWWGuSmsdOJcqzvOUTVaSr2ARzYRh+kI eznETeZ6TosxPKuLyo1WAMvwXcnJHMihBTqJ2r72Gc9g4UjRZYkrBXGk6shU98bLTdIM uEUgY+As339DLeE4o0KpqfpFht9n6Hoj425B1Jb6EtP9lX+/AOZIvP6KyXKu8TKxVbWE 0ROwKs8Vb++TMfOTyzZGRRzgok1LAJJCeSKrHwR9Ge0aGOBk7c7jmMGbl+tgHD1wAvNv U+s4Rza3ZWuG6Xe1UYyj2cxGuSXw1NHzX6tpsplIYlmVvkcoGb9SlD+ZRZXg2MPF3mIV RCoQ== 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 17si7956355qvj.9.2018.11.05.08.47.34 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 05 Nov 2018 08:47:34 -0800 (PST) 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]:36216 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJi2I-0002XW-6I for patch@linaro.org; Mon, 05 Nov 2018 11:47:34 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50694) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJhuG-0007wP-Sj for qemu-devel@nongnu.org; Mon, 05 Nov 2018 11:39:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gJhuB-0005T6-Jx for qemu-devel@nongnu.org; Mon, 05 Nov 2018 11:39:16 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51374) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gJhto-0003yq-Qr; Mon, 05 Nov 2018 11:38:49 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9A8BC8666F; Mon, 5 Nov 2018 16:38:31 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-198.ams2.redhat.com [10.36.117.198]) by smtp.corp.redhat.com (Postfix) with ESMTP id 591C160C46; Mon, 5 Nov 2018 16:38:28 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Mon, 5 Nov 2018 17:37:20 +0100 Message-Id: <20181105163744.25139-13-kwolf@redhat.com> In-Reply-To: <20181105163744.25139-1-kwolf@redhat.com> References: <20181105163744.25139-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 05 Nov 2018 16:38:31 +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 12/36] block/vhdx: Don't take address of fields in packed structs 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: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org 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. Avoid the bug by not using the "modify in place" byte swapping functions. There are a few places where the in-place swap function is used on something other than a packed struct field; we convert those anyway, for consistency. Patch produced with scripts/coccinelle/inplace-byteswaps.cocci. Signed-off-by: Peter Maydell Reviewed-by: Stefan Hajnoczi Signed-off-by: Kevin Wolf --- block/vhdx.h | 12 ++--- block/vhdx-endian.c | 118 ++++++++++++++++++++++---------------------- block/vhdx-log.c | 4 +- block/vhdx.c | 18 +++---- 4 files changed, 76 insertions(+), 76 deletions(-) -- 2.19.1 diff --git a/block/vhdx.h b/block/vhdx.h index 7003ab7a79..3a5f5293ad 100644 --- a/block/vhdx.h +++ b/block/vhdx.h @@ -420,16 +420,16 @@ int vhdx_log_write_and_flush(BlockDriverState *bs, BDRVVHDXState *s, static inline void leguid_to_cpus(MSGUID *guid) { - le32_to_cpus(&guid->data1); - le16_to_cpus(&guid->data2); - le16_to_cpus(&guid->data3); + guid->data1 = le32_to_cpu(guid->data1); + guid->data2 = le16_to_cpu(guid->data2); + guid->data3 = le16_to_cpu(guid->data3); } static inline void cpu_to_leguids(MSGUID *guid) { - cpu_to_le32s(&guid->data1); - cpu_to_le16s(&guid->data2); - cpu_to_le16s(&guid->data3); + guid->data1 = cpu_to_le32(guid->data1); + guid->data2 = cpu_to_le16(guid->data2); + guid->data3 = cpu_to_le16(guid->data3); } void vhdx_header_le_import(VHDXHeader *h); diff --git a/block/vhdx-endian.c b/block/vhdx-endian.c index 41fbdd2b8f..ebfa33cb8a 100644 --- a/block/vhdx-endian.c +++ b/block/vhdx-endian.c @@ -35,18 +35,18 @@ void vhdx_header_le_import(VHDXHeader *h) { assert(h != NULL); - le32_to_cpus(&h->signature); - le32_to_cpus(&h->checksum); - le64_to_cpus(&h->sequence_number); + h->signature = le32_to_cpu(h->signature); + h->checksum = le32_to_cpu(h->checksum); + h->sequence_number = le64_to_cpu(h->sequence_number); leguid_to_cpus(&h->file_write_guid); leguid_to_cpus(&h->data_write_guid); leguid_to_cpus(&h->log_guid); - le16_to_cpus(&h->log_version); - le16_to_cpus(&h->version); - le32_to_cpus(&h->log_length); - le64_to_cpus(&h->log_offset); + h->log_version = le16_to_cpu(h->log_version); + h->version = le16_to_cpu(h->version); + h->log_length = le32_to_cpu(h->log_length); + h->log_offset = le64_to_cpu(h->log_offset); } void vhdx_header_le_export(VHDXHeader *orig_h, VHDXHeader *new_h) @@ -80,68 +80,68 @@ void vhdx_log_desc_le_import(VHDXLogDescriptor *d) { assert(d != NULL); - le32_to_cpus(&d->signature); - le64_to_cpus(&d->file_offset); - le64_to_cpus(&d->sequence_number); + d->signature = le32_to_cpu(d->signature); + d->file_offset = le64_to_cpu(d->file_offset); + d->sequence_number = le64_to_cpu(d->sequence_number); } void vhdx_log_desc_le_export(VHDXLogDescriptor *d) { assert(d != NULL); - cpu_to_le32s(&d->signature); - cpu_to_le32s(&d->trailing_bytes); - cpu_to_le64s(&d->leading_bytes); - cpu_to_le64s(&d->file_offset); - cpu_to_le64s(&d->sequence_number); + d->signature = cpu_to_le32(d->signature); + d->trailing_bytes = cpu_to_le32(d->trailing_bytes); + d->leading_bytes = cpu_to_le64(d->leading_bytes); + d->file_offset = cpu_to_le64(d->file_offset); + d->sequence_number = cpu_to_le64(d->sequence_number); } void vhdx_log_data_le_import(VHDXLogDataSector *d) { assert(d != NULL); - le32_to_cpus(&d->data_signature); - le32_to_cpus(&d->sequence_high); - le32_to_cpus(&d->sequence_low); + d->data_signature = le32_to_cpu(d->data_signature); + d->sequence_high = le32_to_cpu(d->sequence_high); + d->sequence_low = le32_to_cpu(d->sequence_low); } void vhdx_log_data_le_export(VHDXLogDataSector *d) { assert(d != NULL); - cpu_to_le32s(&d->data_signature); - cpu_to_le32s(&d->sequence_high); - cpu_to_le32s(&d->sequence_low); + d->data_signature = cpu_to_le32(d->data_signature); + d->sequence_high = cpu_to_le32(d->sequence_high); + d->sequence_low = cpu_to_le32(d->sequence_low); } void vhdx_log_entry_hdr_le_import(VHDXLogEntryHeader *hdr) { assert(hdr != NULL); - le32_to_cpus(&hdr->signature); - le32_to_cpus(&hdr->checksum); - le32_to_cpus(&hdr->entry_length); - le32_to_cpus(&hdr->tail); - le64_to_cpus(&hdr->sequence_number); - le32_to_cpus(&hdr->descriptor_count); + hdr->signature = le32_to_cpu(hdr->signature); + hdr->checksum = le32_to_cpu(hdr->checksum); + hdr->entry_length = le32_to_cpu(hdr->entry_length); + hdr->tail = le32_to_cpu(hdr->tail); + hdr->sequence_number = le64_to_cpu(hdr->sequence_number); + hdr->descriptor_count = le32_to_cpu(hdr->descriptor_count); leguid_to_cpus(&hdr->log_guid); - le64_to_cpus(&hdr->flushed_file_offset); - le64_to_cpus(&hdr->last_file_offset); + hdr->flushed_file_offset = le64_to_cpu(hdr->flushed_file_offset); + hdr->last_file_offset = le64_to_cpu(hdr->last_file_offset); } void vhdx_log_entry_hdr_le_export(VHDXLogEntryHeader *hdr) { assert(hdr != NULL); - cpu_to_le32s(&hdr->signature); - cpu_to_le32s(&hdr->checksum); - cpu_to_le32s(&hdr->entry_length); - cpu_to_le32s(&hdr->tail); - cpu_to_le64s(&hdr->sequence_number); - cpu_to_le32s(&hdr->descriptor_count); + hdr->signature = cpu_to_le32(hdr->signature); + hdr->checksum = cpu_to_le32(hdr->checksum); + hdr->entry_length = cpu_to_le32(hdr->entry_length); + hdr->tail = cpu_to_le32(hdr->tail); + hdr->sequence_number = cpu_to_le64(hdr->sequence_number); + hdr->descriptor_count = cpu_to_le32(hdr->descriptor_count); cpu_to_leguids(&hdr->log_guid); - cpu_to_le64s(&hdr->flushed_file_offset); - cpu_to_le64s(&hdr->last_file_offset); + hdr->flushed_file_offset = cpu_to_le64(hdr->flushed_file_offset); + hdr->last_file_offset = cpu_to_le64(hdr->last_file_offset); } @@ -150,18 +150,18 @@ void vhdx_region_header_le_import(VHDXRegionTableHeader *hdr) { assert(hdr != NULL); - le32_to_cpus(&hdr->signature); - le32_to_cpus(&hdr->checksum); - le32_to_cpus(&hdr->entry_count); + hdr->signature = le32_to_cpu(hdr->signature); + hdr->checksum = le32_to_cpu(hdr->checksum); + hdr->entry_count = le32_to_cpu(hdr->entry_count); } void vhdx_region_header_le_export(VHDXRegionTableHeader *hdr) { assert(hdr != NULL); - cpu_to_le32s(&hdr->signature); - cpu_to_le32s(&hdr->checksum); - cpu_to_le32s(&hdr->entry_count); + hdr->signature = cpu_to_le32(hdr->signature); + hdr->checksum = cpu_to_le32(hdr->checksum); + hdr->entry_count = cpu_to_le32(hdr->entry_count); } void vhdx_region_entry_le_import(VHDXRegionTableEntry *e) @@ -169,9 +169,9 @@ void vhdx_region_entry_le_import(VHDXRegionTableEntry *e) assert(e != NULL); leguid_to_cpus(&e->guid); - le64_to_cpus(&e->file_offset); - le32_to_cpus(&e->length); - le32_to_cpus(&e->data_bits); + e->file_offset = le64_to_cpu(e->file_offset); + e->length = le32_to_cpu(e->length); + e->data_bits = le32_to_cpu(e->data_bits); } void vhdx_region_entry_le_export(VHDXRegionTableEntry *e) @@ -179,9 +179,9 @@ void vhdx_region_entry_le_export(VHDXRegionTableEntry *e) assert(e != NULL); cpu_to_leguids(&e->guid); - cpu_to_le64s(&e->file_offset); - cpu_to_le32s(&e->length); - cpu_to_le32s(&e->data_bits); + e->file_offset = cpu_to_le64(e->file_offset); + e->length = cpu_to_le32(e->length); + e->data_bits = cpu_to_le32(e->data_bits); } @@ -190,16 +190,16 @@ void vhdx_metadata_header_le_import(VHDXMetadataTableHeader *hdr) { assert(hdr != NULL); - le64_to_cpus(&hdr->signature); - le16_to_cpus(&hdr->entry_count); + hdr->signature = le64_to_cpu(hdr->signature); + hdr->entry_count = le16_to_cpu(hdr->entry_count); } void vhdx_metadata_header_le_export(VHDXMetadataTableHeader *hdr) { assert(hdr != NULL); - cpu_to_le64s(&hdr->signature); - cpu_to_le16s(&hdr->entry_count); + hdr->signature = cpu_to_le64(hdr->signature); + hdr->entry_count = cpu_to_le16(hdr->entry_count); } void vhdx_metadata_entry_le_import(VHDXMetadataTableEntry *e) @@ -207,16 +207,16 @@ void vhdx_metadata_entry_le_import(VHDXMetadataTableEntry *e) assert(e != NULL); leguid_to_cpus(&e->item_id); - le32_to_cpus(&e->offset); - le32_to_cpus(&e->length); - le32_to_cpus(&e->data_bits); + e->offset = le32_to_cpu(e->offset); + e->length = le32_to_cpu(e->length); + e->data_bits = le32_to_cpu(e->data_bits); } void vhdx_metadata_entry_le_export(VHDXMetadataTableEntry *e) { assert(e != NULL); cpu_to_leguids(&e->item_id); - cpu_to_le32s(&e->offset); - cpu_to_le32s(&e->length); - cpu_to_le32s(&e->data_bits); + e->offset = cpu_to_le32(e->offset); + e->length = cpu_to_le32(e->length); + e->data_bits = cpu_to_le32(e->data_bits); } diff --git a/block/vhdx-log.c b/block/vhdx-log.c index d2f1b98199..ecd64266c5 100644 --- a/block/vhdx-log.c +++ b/block/vhdx-log.c @@ -835,11 +835,11 @@ static void vhdx_log_raw_to_le_sector(VHDXLogDescriptor *desc, /* 8 + 4084 + 4 = 4096, 1 log sector */ memcpy(&desc->leading_bytes, data, 8); data += 8; - cpu_to_le64s(&desc->leading_bytes); + desc->leading_bytes = cpu_to_le64(desc->leading_bytes); memcpy(sector->data, data, 4084); data += 4084; memcpy(&desc->trailing_bytes, data, 4); - cpu_to_le32s(&desc->trailing_bytes); + desc->trailing_bytes = cpu_to_le32(desc->trailing_bytes); data += 4; sector->sequence_high = (uint32_t) (seq >> 32); diff --git a/block/vhdx.c b/block/vhdx.c index 0795ca1985..b785aef4b7 100644 --- a/block/vhdx.c +++ b/block/vhdx.c @@ -156,7 +156,7 @@ uint32_t vhdx_update_checksum(uint8_t *buf, size_t size, int crc_offset) memset(buf + crc_offset, 0, sizeof(crc)); crc = crc32c(0xffffffff, buf, size); - cpu_to_le32s(&crc); + crc = cpu_to_le32(crc); memcpy(buf + crc_offset, &crc, sizeof(crc)); return crc; @@ -753,8 +753,8 @@ static int vhdx_parse_metadata(BlockDriverState *bs, BDRVVHDXState *s) goto exit; } - le32_to_cpus(&s->params.block_size); - le32_to_cpus(&s->params.data_bits); + s->params.block_size = le32_to_cpu(s->params.block_size); + s->params.data_bits = le32_to_cpu(s->params.data_bits); /* We now have the file parameters, so we can tell if this is a @@ -803,9 +803,9 @@ static int vhdx_parse_metadata(BlockDriverState *bs, BDRVVHDXState *s) goto exit; } - le64_to_cpus(&s->virtual_disk_size); - le32_to_cpus(&s->logical_sector_size); - le32_to_cpus(&s->physical_sector_size); + s->virtual_disk_size = le64_to_cpu(s->virtual_disk_size); + s->logical_sector_size = le32_to_cpu(s->logical_sector_size); + s->physical_sector_size = le32_to_cpu(s->physical_sector_size); if (s->params.block_size < VHDX_BLOCK_SIZE_MIN || s->params.block_size > VHDX_BLOCK_SIZE_MAX) { @@ -985,7 +985,7 @@ static int vhdx_open(BlockDriverState *bs, QDict *options, int flags, /* endian convert, and verify populated BAT field file offsets against * region table and log entries */ for (i = 0; i < s->bat_entries; i++) { - le64_to_cpus(&s->bat[i]); + s->bat[i] = le64_to_cpu(s->bat[i]); if (payblocks--) { /* payload bat entries */ if ((s->bat[i] & VHDX_BAT_STATE_BIT_MASK) == @@ -1509,7 +1509,7 @@ static int vhdx_create_new_metadata(BlockBackend *blk, mt_file_params->block_size = cpu_to_le32(block_size); if (type == VHDX_TYPE_FIXED) { mt_file_params->data_bits |= VHDX_PARAMS_LEAVE_BLOCKS_ALLOCED; - cpu_to_le32s(&mt_file_params->data_bits); + mt_file_params->data_bits = cpu_to_le32(mt_file_params->data_bits); } vhdx_guid_generate(&mt_page83->page_83_data); @@ -1656,7 +1656,7 @@ static int vhdx_create_bat(BlockBackend *blk, BDRVVHDXState *s, sinfo.file_offset = ROUND_UP(sinfo.file_offset, MiB); vhdx_update_bat_table_entry(blk_bs(blk), s, &sinfo, &unused, &unused, block_state); - cpu_to_le64s(&s->bat[sinfo.bat_idx]); + s->bat[sinfo.bat_idx] = cpu_to_le64(s->bat[sinfo.bat_idx]); sector_num += s->sectors_per_block; } ret = blk_pwrite(blk, file_offset, s->bat, length, 0); From patchwork Mon Nov 5 16:37:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 150217 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp2854002ljp; Mon, 5 Nov 2018 09:08:51 -0800 (PST) X-Google-Smtp-Source: AJdET5eaezEeoGcy0cmURXghGy+rTQtBMAretwWLGCJdI4skD7ed7BgRgt6L35N9KM/czH2y6jdG X-Received: by 2002:a0c:8ae3:: with SMTP id 32mr22163204qvw.27.1541437731465; Mon, 05 Nov 2018 09:08:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541437731; cv=none; d=google.com; s=arc-20160816; b=yAqmkDveV0ULfpsQ04APYJx0mepvlr19e58iT21d0L9MLGaOWsEwiA7Vr/8HGVQDWM 9AXwXdmjus4d0ekx6y7gBJMFhPZZWsKamluuILfVcbb644C9udcESH4An3cKFV+0RYKa d9I1mFWm8RvFwBXeslXOehbx270uj5bbKDZIOTAeu71INC30X9yvn7IDfb+uKrd0toNf wkMHDWFFiSL/b8Z/y1T2YRZOmC+lPbuf/kj8gWudghcWOopIuKpCfpmLnzjZZhAAmCnB ok5YMGRmcZ1mNGNt+JcG8vn0R4szK8MmA9E/k3p9E02iUjn8vNQn/IzOYIWir/2h7axM Serg== 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=mQE3HMeC7MdNjWo5qwIYOkcslkX6Btzz/zaWI1lnPSo=; b=X1b2KHeae2kVoBpYcdqxnZ/0Y413KD0prGIni7ZSwte9gV3eutoyeDELxnf5eHS2h2 /H2SoeCytrUcgHsT1QHU0rCZ7bMY1TIdUT4DViFRlRzOkQ2WU7HEdwygy53uN9UilLce 7kpM7HIWRr8f3du89VD6R/3AZAIcWOoiSsXOlVmduuqhH+e8sxlypvUtu47Wbf3PkwWs 0eMwGQv6ROaW8Rt1RPPIS5r52IBRz+0Tr4TYC/9cK8HWehrKjhNU9a/fy/bQKg+ZEySp GV2Jv1i8QBDylPtF3ceEpNv5b1oXZcNeeXMCAbJJu6txr07NfiE8O3ybFwEs0abbwOAN 7jrg== 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 a46si1250378qtb.19.2018.11.05.09.08.51 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 05 Nov 2018 09:08:51 -0800 (PST) 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]:36381 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJiMs-00036d-Pe for patch@linaro.org; Mon, 05 Nov 2018 12:08:50 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52961) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJhy9-00051N-C7 for qemu-devel@nongnu.org; Mon, 05 Nov 2018 11:43:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gJhy7-0008Ds-SY for qemu-devel@nongnu.org; Mon, 05 Nov 2018 11:43:17 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35070) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gJhy1-00046p-EZ; Mon, 05 Nov 2018 11:43:09 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A2DE08E5A4; Mon, 5 Nov 2018 16:38:35 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-198.ams2.redhat.com [10.36.117.198]) by smtp.corp.redhat.com (Postfix) with ESMTP id E19AF60C46; Mon, 5 Nov 2018 16:38:31 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Mon, 5 Nov 2018 17:37:21 +0100 Message-Id: <20181105163744.25139-14-kwolf@redhat.com> In-Reply-To: <20181105163744.25139-1-kwolf@redhat.com> References: <20181105163744.25139-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 05 Nov 2018 16:38:35 +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 13/36] block/vdi: Don't take address of fields in packed structs 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: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org 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. Avoid the bug by not using the "modify in place" byte swapping functions. There are a few places where the in-place swap function is used on something other than a packed struct field; we convert those anyway, for consistency. Patch produced with scripts/coccinelle/inplace-byteswaps.cocci. There are other places where we take the address of a packed member in this file for other purposes than passing it to a byteswap function (all the calls to qemu_uuid_*()); we leave those for now. Signed-off-by: Peter Maydell Reviewed-by: Stefan Hajnoczi Signed-off-by: Kevin Wolf --- block/vdi.c | 64 ++++++++++++++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 32 deletions(-) -- 2.19.1 diff --git a/block/vdi.c b/block/vdi.c index 6555cffb88..0ff1ead736 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -187,22 +187,22 @@ typedef struct { static void vdi_header_to_cpu(VdiHeader *header) { - le32_to_cpus(&header->signature); - le32_to_cpus(&header->version); - le32_to_cpus(&header->header_size); - le32_to_cpus(&header->image_type); - le32_to_cpus(&header->image_flags); - le32_to_cpus(&header->offset_bmap); - le32_to_cpus(&header->offset_data); - le32_to_cpus(&header->cylinders); - le32_to_cpus(&header->heads); - le32_to_cpus(&header->sectors); - le32_to_cpus(&header->sector_size); - le64_to_cpus(&header->disk_size); - le32_to_cpus(&header->block_size); - le32_to_cpus(&header->block_extra); - le32_to_cpus(&header->blocks_in_image); - le32_to_cpus(&header->blocks_allocated); + header->signature = le32_to_cpu(header->signature); + header->version = le32_to_cpu(header->version); + header->header_size = le32_to_cpu(header->header_size); + header->image_type = le32_to_cpu(header->image_type); + header->image_flags = le32_to_cpu(header->image_flags); + header->offset_bmap = le32_to_cpu(header->offset_bmap); + header->offset_data = le32_to_cpu(header->offset_data); + header->cylinders = le32_to_cpu(header->cylinders); + header->heads = le32_to_cpu(header->heads); + header->sectors = le32_to_cpu(header->sectors); + header->sector_size = le32_to_cpu(header->sector_size); + header->disk_size = le64_to_cpu(header->disk_size); + header->block_size = le32_to_cpu(header->block_size); + header->block_extra = le32_to_cpu(header->block_extra); + header->blocks_in_image = le32_to_cpu(header->blocks_in_image); + header->blocks_allocated = le32_to_cpu(header->blocks_allocated); qemu_uuid_bswap(&header->uuid_image); qemu_uuid_bswap(&header->uuid_last_snap); qemu_uuid_bswap(&header->uuid_link); @@ -211,22 +211,22 @@ static void vdi_header_to_cpu(VdiHeader *header) static void vdi_header_to_le(VdiHeader *header) { - cpu_to_le32s(&header->signature); - cpu_to_le32s(&header->version); - cpu_to_le32s(&header->header_size); - cpu_to_le32s(&header->image_type); - cpu_to_le32s(&header->image_flags); - cpu_to_le32s(&header->offset_bmap); - cpu_to_le32s(&header->offset_data); - cpu_to_le32s(&header->cylinders); - cpu_to_le32s(&header->heads); - cpu_to_le32s(&header->sectors); - cpu_to_le32s(&header->sector_size); - cpu_to_le64s(&header->disk_size); - cpu_to_le32s(&header->block_size); - cpu_to_le32s(&header->block_extra); - cpu_to_le32s(&header->blocks_in_image); - cpu_to_le32s(&header->blocks_allocated); + header->signature = cpu_to_le32(header->signature); + header->version = cpu_to_le32(header->version); + header->header_size = cpu_to_le32(header->header_size); + header->image_type = cpu_to_le32(header->image_type); + header->image_flags = cpu_to_le32(header->image_flags); + header->offset_bmap = cpu_to_le32(header->offset_bmap); + header->offset_data = cpu_to_le32(header->offset_data); + header->cylinders = cpu_to_le32(header->cylinders); + header->heads = cpu_to_le32(header->heads); + header->sectors = cpu_to_le32(header->sectors); + header->sector_size = cpu_to_le32(header->sector_size); + header->disk_size = cpu_to_le64(header->disk_size); + header->block_size = cpu_to_le32(header->block_size); + header->block_extra = cpu_to_le32(header->block_extra); + header->blocks_in_image = cpu_to_le32(header->blocks_in_image); + header->blocks_allocated = cpu_to_le32(header->blocks_allocated); qemu_uuid_bswap(&header->uuid_image); qemu_uuid_bswap(&header->uuid_last_snap); qemu_uuid_bswap(&header->uuid_link);