All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/3] block/qcow*: Don't take address of fields in packed structs
@ 2018-10-09 17:24 Peter Maydell
  2018-10-09 17:24 ` [Qemu-devel] [PATCH 1/3] block/qcow2: " Peter Maydell
                   ` (5 more replies)
  0 siblings, 6 replies; 8+ messages in thread
From: Peter Maydell @ 2018-10-09 17:24 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kevin Wolf, Max Reitz, qemu-block

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 in the affected files where the in-place swap
function is used on something other than a packed struct field; we
convert those anyway, for consistency.

Patches produced mechanically using spatch; in one case I also
did a little hand-editing to wrap overlong lines that checkpatch
would otherwise complain about.

(clang also complains about other files in block: vdi.c, vpc.c,
vhdx.h, vhdx.c, vhdx-endian.c, vhdx-log.c -- I may produce patches
for those later if nobody else gets there first.)

thanks
-- PMM

Peter Maydell (3):
  block/qcow2: Don't take address of fields in packed structs
  block/qcow: Don't take address of fields in packed structs
  block/qcow2-bitmap: Don't take address of fields in packed structs

 block/qcow.c         | 18 ++++++-------
 block/qcow2-bitmap.c | 24 ++++++++---------
 block/qcow2.c        | 64 +++++++++++++++++++++++---------------------
 3 files changed, 55 insertions(+), 51 deletions(-)

-- 
2.19.0

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Qemu-devel] [PATCH 1/3] block/qcow2: Don't take address of fields in packed structs
  2018-10-09 17:24 [Qemu-devel] [PATCH 0/3] block/qcow*: Don't take address of fields in packed structs Peter Maydell
@ 2018-10-09 17:24 ` Peter Maydell
  2018-10-09 17:25 ` [Qemu-devel] [PATCH 2/3] block/qcow: " Peter Maydell
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Peter Maydell @ 2018-10-09 17:24 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kevin Wolf, Max Reitz, qemu-block

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 <peter.maydell@linaro.org>
---
 block/qcow2.c | 64 +++++++++++++++++++++++++++------------------------
 1 file changed, 34 insertions(+), 30 deletions(-)

diff --git a/block/qcow2.c b/block/qcow2.c
index 7277feda135..33e12bbe0fd 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,
@@ -1160,19 +1162,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");
@@ -1208,11 +1211,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");
@@ -1401,7 +1405,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]);
         }
     }
 
@@ -2346,13 +2350,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;
         }
-- 
2.19.0

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [Qemu-devel] [PATCH 2/3] block/qcow: Don't take address of fields in packed structs
  2018-10-09 17:24 [Qemu-devel] [PATCH 0/3] block/qcow*: Don't take address of fields in packed structs Peter Maydell
  2018-10-09 17:24 ` [Qemu-devel] [PATCH 1/3] block/qcow2: " Peter Maydell
@ 2018-10-09 17:25 ` Peter Maydell
  2018-10-09 17:25 ` [Qemu-devel] [PATCH 3/3] block/qcow2-bitmap: " Peter Maydell
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Peter Maydell @ 2018-10-09 17:25 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kevin Wolf, Max Reitz, qemu-block

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 <peter.maydell@linaro.org>
---
 block/qcow.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/block/qcow.c b/block/qcow.c
index 385d935258f..4518cb4c35e 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) */
-- 
2.19.0

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [Qemu-devel] [PATCH 3/3] block/qcow2-bitmap: Don't take address of fields in packed structs
  2018-10-09 17:24 [Qemu-devel] [PATCH 0/3] block/qcow*: Don't take address of fields in packed structs Peter Maydell
  2018-10-09 17:24 ` [Qemu-devel] [PATCH 1/3] block/qcow2: " Peter Maydell
  2018-10-09 17:25 ` [Qemu-devel] [PATCH 2/3] block/qcow: " Peter Maydell
@ 2018-10-09 17:25 ` Peter Maydell
  2018-10-09 17:49 ` [Qemu-devel] [PATCH 0/3] block/qcow*: " Richard Henderson
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Peter Maydell @ 2018-10-09 17:25 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kevin Wolf, Max Reitz, qemu-block

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 <peter.maydell@linaro.org>
---
 block/qcow2-bitmap.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c
index ba978ad2aac..74f7638e03c 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)
-- 
2.19.0

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PATCH 0/3] block/qcow*: Don't take address of fields in packed structs
  2018-10-09 17:24 [Qemu-devel] [PATCH 0/3] block/qcow*: Don't take address of fields in packed structs Peter Maydell
                   ` (2 preceding siblings ...)
  2018-10-09 17:25 ` [Qemu-devel] [PATCH 3/3] block/qcow2-bitmap: " Peter Maydell
@ 2018-10-09 17:49 ` Richard Henderson
  2018-10-09 19:04 ` [Qemu-devel] [Qemu-block] " John Snow
  2018-10-10 10:55 ` [Qemu-devel] " Kevin Wolf
  5 siblings, 0 replies; 8+ messages in thread
From: Richard Henderson @ 2018-10-09 17:49 UTC (permalink / raw)
  To: Peter Maydell, qemu-devel; +Cc: Kevin Wolf, qemu-block, Max Reitz

On 10/9/18 10:24 AM, Peter Maydell wrote:
> Peter Maydell (3):
>   block/qcow2: Don't take address of fields in packed structs
>   block/qcow: Don't take address of fields in packed structs
>   block/qcow2-bitmap: Don't take address of fields in packed structs

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

Although I do think you should put the script you used into
scripts/coccinelle/, so that it may be used for the rest of the files in the
tree.  We can delete the script after those pointer-based functions are removed.


r~

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [Qemu-block] [PATCH 0/3] block/qcow*: Don't take address of fields in packed structs
  2018-10-09 17:24 [Qemu-devel] [PATCH 0/3] block/qcow*: Don't take address of fields in packed structs Peter Maydell
                   ` (3 preceding siblings ...)
  2018-10-09 17:49 ` [Qemu-devel] [PATCH 0/3] block/qcow*: " Richard Henderson
@ 2018-10-09 19:04 ` John Snow
  2018-10-10 10:55 ` [Qemu-devel] " Kevin Wolf
  5 siblings, 0 replies; 8+ messages in thread
From: John Snow @ 2018-10-09 19:04 UTC (permalink / raw)
  To: Peter Maydell, qemu-devel; +Cc: Kevin Wolf, qemu-block, Max Reitz



On 10/09/2018 01:24 PM, Peter Maydell wrote:
> 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 in the affected files where the in-place swap
> function is used on something other than a packed struct field; we
> convert those anyway, for consistency.
> 
> Patches produced mechanically using spatch; in one case I also
> did a little hand-editing to wrap overlong lines that checkpatch
> would otherwise complain about.
> 
> (clang also complains about other files in block: vdi.c, vpc.c,
> vhdx.h, vhdx.c, vhdx-endian.c, vhdx-log.c -- I may produce patches
> for those later if nobody else gets there first.)
> 
> thanks
> -- PMM
> 
> Peter Maydell (3):
>   block/qcow2: Don't take address of fields in packed structs
>   block/qcow: Don't take address of fields in packed structs
>   block/qcow2-bitmap: Don't take address of fields in packed structs
> 
>  block/qcow.c         | 18 ++++++-------
>  block/qcow2-bitmap.c | 24 ++++++++---------
>  block/qcow2.c        | 64 +++++++++++++++++++++++---------------------
>  3 files changed, 55 insertions(+), 51 deletions(-)
> 

Tested-by: John Snow <jsnow@redhat.com>
Reviewed-by: John Snow <jsnow@redhat.com>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PATCH 0/3] block/qcow*: Don't take address of fields in packed structs
  2018-10-09 17:24 [Qemu-devel] [PATCH 0/3] block/qcow*: Don't take address of fields in packed structs Peter Maydell
                   ` (4 preceding siblings ...)
  2018-10-09 19:04 ` [Qemu-devel] [Qemu-block] " John Snow
@ 2018-10-10 10:55 ` Kevin Wolf
  2018-11-05 14:41   ` Peter Maydell
  5 siblings, 1 reply; 8+ messages in thread
From: Kevin Wolf @ 2018-10-10 10:55 UTC (permalink / raw)
  To: Peter Maydell; +Cc: qemu-devel, Max Reitz, qemu-block

Am 09.10.2018 um 19:24 hat Peter Maydell geschrieben:
> 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 in the affected files where the in-place swap
> function is used on something other than a packed struct field; we
> convert those anyway, for consistency.
> 
> Patches produced mechanically using spatch; in one case I also
> did a little hand-editing to wrap overlong lines that checkpatch
> would otherwise complain about.
> 
> (clang also complains about other files in block: vdi.c, vpc.c,
> vhdx.h, vhdx.c, vhdx-endian.c, vhdx-log.c -- I may produce patches
> for those later if nobody else gets there first.)
> 
> thanks
> -- PMM
> 
> Peter Maydell (3):
>   block/qcow2: Don't take address of fields in packed structs
>   block/qcow: Don't take address of fields in packed structs
>   block/qcow2-bitmap: Don't take address of fields in packed structs

Thanks, applied to the block branch.

Kevin

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PATCH 0/3] block/qcow*: Don't take address of fields in packed structs
  2018-10-10 10:55 ` [Qemu-devel] " Kevin Wolf
@ 2018-11-05 14:41   ` Peter Maydell
  0 siblings, 0 replies; 8+ messages in thread
From: Peter Maydell @ 2018-11-05 14:41 UTC (permalink / raw)
  To: Kevin Wolf; +Cc: QEMU Developers, Max Reitz, Qemu-block

On 10 October 2018 at 11:55, Kevin Wolf <kwolf@redhat.com> wrote:
> Am 09.10.2018 um 19:24 hat Peter Maydell geschrieben:
>> 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 in the affected files where the in-place swap
>> function is used on something other than a packed struct field; we
>> convert those anyway, for consistency.
>>
>> Patches produced mechanically using spatch; in one case I also
>> did a little hand-editing to wrap overlong lines that checkpatch
>> would otherwise complain about.
>>
>> (clang also complains about other files in block: vdi.c, vpc.c,
>> vhdx.h, vhdx.c, vhdx-endian.c, vhdx-log.c -- I may produce patches
>> for those later if nobody else gets there first.)
>>
>> thanks
>> -- PMM
>>
>> Peter Maydell (3):
>>   block/qcow2: Don't take address of fields in packed structs
>>   block/qcow: Don't take address of fields in packed structs
>>   block/qcow2-bitmap: Don't take address of fields in packed structs
>
> Thanks, applied to the block branch.

Ping? This doesn't seem to have made it into master, unless
I've missed it...

thanks
-- PMM

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2018-11-05 14:41 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-09 17:24 [Qemu-devel] [PATCH 0/3] block/qcow*: Don't take address of fields in packed structs Peter Maydell
2018-10-09 17:24 ` [Qemu-devel] [PATCH 1/3] block/qcow2: " Peter Maydell
2018-10-09 17:25 ` [Qemu-devel] [PATCH 2/3] block/qcow: " Peter Maydell
2018-10-09 17:25 ` [Qemu-devel] [PATCH 3/3] block/qcow2-bitmap: " Peter Maydell
2018-10-09 17:49 ` [Qemu-devel] [PATCH 0/3] block/qcow*: " Richard Henderson
2018-10-09 19:04 ` [Qemu-devel] [Qemu-block] " John Snow
2018-10-10 10:55 ` [Qemu-devel] " Kevin Wolf
2018-11-05 14:41   ` Peter Maydell

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.