All of lore.kernel.org
 help / color / mirror / Atom feed
From: Samuel Thibault <samuel.thibault@ens-lyon.org>
To: qemu-devel@nongnu.org, peter.maydell@linaro.org
Cc: stefanha@redhat.com, jan.kiszka@siemens.com,
	Eric Blake <eblake@redhat.com>,
	Samuel Thibault <samuel.thibault@ens-lyon.org>
Subject: [Qemu-devel] [PULLv4 02/32] slirp: Avoid marking naturally packed structs as QEMU_PACKED
Date: Thu,  7 Feb 2019 16:02:46 +0200	[thread overview]
Message-ID: <20190207140316.16103-3-samuel.thibault@ens-lyon.org> (raw)
In-Reply-To: <20190207140316.16103-1-samuel.thibault@ens-lyon.org>

From: Peter Maydell <peter.maydell@linaro.org>

Various ipv6 structs in the slirp headers are marked QEMU_PACKED,
but they are actually naturally aligned and will have no padding
in them. Instead of marking them with the 'packed' attribute,
assert at compile time that they are the size we expect. This
allows us to take the address of fields within the structs
without risking undefined behaviour, and suppresses clang
-Waddress-of-packed-member warnings.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
---
 slirp/ip6.h      | 12 ++++++++++--
 slirp/ip6_icmp.h | 20 +++++++++++++++-----
 2 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/slirp/ip6.h b/slirp/ip6.h
index 14e9c78735..1e3e329ce6 100644
--- a/slirp/ip6.h
+++ b/slirp/ip6.h
@@ -133,7 +133,7 @@ struct ip6 {
     uint8_t     ip_nh;               /* next header */
     uint8_t     ip_hl;               /* hop limit */
     struct in6_addr ip_src, ip_dst;  /* source and dest address */
-} QEMU_PACKED;
+};
 
 /*
  * IPv6 pseudo-header used by upper-layer protocols
@@ -145,7 +145,15 @@ struct ip6_pseudohdr {
     uint16_t    ih_zero_hi;       /* zero */
     uint8_t     ih_zero_lo;       /* zero */
     uint8_t     ih_nh;            /* next header */
-} QEMU_PACKED;
+};
 
+/*
+ * We don't want to mark these ip6 structs as packed as they are naturally
+ * correctly aligned; instead assert that there is no stray padding.
+ * If we marked the struct as packed then we would be unable to take
+ * the address of any of the fields in it.
+ */
+QEMU_BUILD_BUG_ON(sizeof(struct ip6) != 40);
+QEMU_BUILD_BUG_ON(sizeof(struct ip6_pseudohdr) != 40);
 
 #endif
diff --git a/slirp/ip6_icmp.h b/slirp/ip6_icmp.h
index 32b0914055..2ad2b75e67 100644
--- a/slirp/ip6_icmp.h
+++ b/slirp/ip6_icmp.h
@@ -48,12 +48,16 @@ struct ndp_ra {     /* Router Advertisement Message */
     uint16_t lifetime;      /* Router Lifetime */
     uint32_t reach_time;    /* Reachable Time */
     uint32_t retrans_time;  /* Retrans Timer */
-} QEMU_PACKED;
+};
+
+QEMU_BUILD_BUG_ON(sizeof(struct ndp_ra) != 12);
 
 struct ndp_ns {     /* Neighbor Solicitation Message */
     uint32_t reserved;
     struct in6_addr target; /* Target Address */
-} QEMU_PACKED;
+};
+
+QEMU_BUILD_BUG_ON(sizeof(struct ndp_ns) != 20);
 
 struct ndp_na {     /* Neighbor Advertisement Message */
 #if G_BYTE_ORDER == G_BIG_ENDIAN
@@ -72,13 +76,17 @@ struct ndp_na {     /* Neighbor Advertisement Message */
         reserved_lo:24;
 #endif
     struct in6_addr target; /* Target Address */
-} QEMU_PACKED;
+};
+
+QEMU_BUILD_BUG_ON(sizeof(struct ndp_na) != 20);
 
 struct ndp_redirect {
     uint32_t reserved;
     struct in6_addr target; /* Target Address */
     struct in6_addr dest;   /* Destination Address */
-} QEMU_PACKED;
+};
+
+QEMU_BUILD_BUG_ON(sizeof(struct ndp_redirect) != 36);
 
 /*
  * Structure of an icmpv6 header.
@@ -103,7 +111,9 @@ struct icmp6 {
 #define icmp6_nns icmp6_body.ndp_ns
 #define icmp6_nna icmp6_body.ndp_na
 #define icmp6_redirect icmp6_body.ndp_redirect
-} QEMU_PACKED;
+};
+
+QEMU_BUILD_BUG_ON(sizeof(struct icmp6) != 40);
 
 #define ICMP6_MINLEN    4
 #define ICMP6_ERROR_MINLEN  8
-- 
2.20.1

  parent reply	other threads:[~2019-02-07 14:03 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-07 14:02 [Qemu-devel] [PULLv4 00/32] More work towards libslirp Samuel Thibault
2019-02-07 14:02 ` [Qemu-devel] [PULLv4 01/32] slirp: Avoid unaligned 16bit memory access Samuel Thibault
2019-02-07 14:02 ` Samuel Thibault [this message]
2019-02-07 14:02 ` [Qemu-devel] [PULLv4 03/32] slirp: Don't mark struct ipq or struct ipasfrag as packed Samuel Thibault
2019-02-07 14:02 ` [Qemu-devel] [PULLv4 04/32] slirp: generalize guestfwd with a callback based approach Samuel Thibault
2019-02-07 14:02 ` [Qemu-devel] [PULLv4 05/32] net/slirp: simplify checking for cmd: prefix Samuel Thibault
2019-02-07 14:02 ` [Qemu-devel] [PULLv4 06/32] net/slirp: free forwarding rules on cleanup Samuel Thibault
2019-02-07 14:02 ` [Qemu-devel] [PULLv4 07/32] net/slirp: fix leaks on forwarding rule registration error Samuel Thibault
2019-02-07 14:02 ` [Qemu-devel] [PULLv4 08/32] slirp: add callbacks for timer Samuel Thibault
2019-02-07 14:02 ` [Qemu-devel] [PULLv4 09/32] slirp: replace trace functions with DEBUG calls Samuel Thibault
2019-02-07 14:02 ` [Qemu-devel] [PULLv4 10/32] slirp: replace QEMU_PACKED with SLIRP_PACKED Samuel Thibault
2019-02-07 14:02 ` [Qemu-devel] [PULLv4 11/32] slirp: replace most qemu socket utilities with slirp own version Samuel Thibault
2019-02-07 14:02 ` [Qemu-devel] [PULLv4 12/32] slirp: replace qemu_set_nonblock() Samuel Thibault
2019-02-07 14:02 ` [Qemu-devel] [PULLv4 13/32] slirp: add unregister_poll_fd() callback Samuel Thibault
2019-02-07 14:02 ` [Qemu-devel] [PULLv4 14/32] slirp: replace qemu_notify_event() with a callback Samuel Thibault
2019-02-07 14:02 ` [Qemu-devel] [PULLv4 15/32] slirp: move QEMU state saving to a separate unit Samuel Thibault
2019-02-07 14:03 ` [Qemu-devel] [PULLv4 16/32] slirp: do not include qemu headers in libslirp.h public API header Samuel Thibault
2019-02-07 14:03 ` [Qemu-devel] [PULLv4 17/32] slirp: improve windows headers inclusion Samuel Thibault
2019-02-07 14:03 ` [Qemu-devel] [PULLv4 18/32] slirp: add slirp own version of pstrcpy Samuel Thibault
2019-02-07 14:03 ` [Qemu-devel] [PULLv4 19/32] slirp: remove qemu timer.h dependency Samuel Thibault
2019-02-07 14:03 ` [Qemu-devel] [PULLv4 20/32] slirp: remove now useless QEMU headers inclusions Samuel Thibault
2019-02-07 14:03 ` [Qemu-devel] [PULLv4 21/32] slirp: replace net/eth.h inclusion with own defines Samuel Thibault
2019-02-07 14:03 ` [Qemu-devel] [PULLv4 22/32] slirp: replace qemu qtailq with slirp own copy Samuel Thibault
2019-02-07 14:03 ` [Qemu-devel] [PULLv4 23/32] slirp: replace QEMU_BUILD_BUG_ON with G_STATIC_ASSERT Samuel Thibault
2019-02-07 14:03 ` [Qemu-devel] [PULLv4 24/32] slirp: Move g_spawn_async_with_fds_qemu compatibility to slirp/ Samuel Thibault
2019-02-07 14:03 ` [Qemu-devel] [PULLv4 25/32] slirp: replace remaining qemu headers dependency Samuel Thibault
2019-02-07 14:03 ` [Qemu-devel] [PULLv4 26/32] slirp: prefer c99 types over BSD kind Samuel Thibault
2019-02-07 14:03 ` [Qemu-devel] [PULLv4 27/32] slirp: improve send_packet() callback Samuel Thibault
2019-02-07 18:31   ` Philippe Mathieu-Daudé
2019-02-07 19:04     ` Samuel Thibault
2019-02-07 14:03 ` [Qemu-devel] [PULLv4 28/32] slirp: replace global polling with per-instance & notifier Samuel Thibault
2019-02-07 14:03 ` [Qemu-devel] [PULLv4 29/32] slirp: remove slirp_instances list Samuel Thibault
2019-02-07 14:03 ` [Qemu-devel] [PULLv4 30/32] slirp: use polling callbacks, drop glib requirement Samuel Thibault
2019-02-07 14:03 ` [Qemu-devel] [PULLv4 31/32] slirp: pass opaque to all callbacks Samuel Thibault
2019-02-07 14:03 ` [Qemu-devel] [PULLv4 32/32] slirp: API is extern C Samuel Thibault
2019-02-07 14:59 ` [Qemu-devel] [PULLv4 00/32] More work towards libslirp no-reply
2019-02-08 10:58 ` Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190207140316.16103-3-samuel.thibault@ens-lyon.org \
    --to=samuel.thibault@ens-lyon.org \
    --cc=eblake@redhat.com \
    --cc=jan.kiszka@siemens.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.