All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PULL 0/3] slirp updates
@ 2019-01-26 21:20 Samuel Thibault
  2019-01-26 21:20 ` [Qemu-devel] [PULL 1/3] slirp: Avoid unaligned 16bit memory access Samuel Thibault
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Samuel Thibault @ 2019-01-26 21:20 UTC (permalink / raw)
  To: qemu-devel; +Cc: Samuel Thibault, stefanha, jan.kiszka

The following changes since commit ad7a21e81231ae64540310384fb0f87ac8758b02:

  Merge remote-tracking branch 'remotes/ehabkost/tags/python-next-pull-request' into staging (2019-01-25 17:22:20 +0000)

are available in the Git repository at:

  https://people.debian.org/~sthibault/qemu.git tags/samuel-thibault

for you to fetch changes up to 4956f29c43c2105dc37ee9826959b3aa1d3b0b69:

  slirp: Don't mark struct ipq or struct ipasfrag as packed (2019-01-26 22:09:48 +0100)

----------------------------------------------------------------
slirp updates

Peter Maydell (2):
  slirp: Avoid marking naturally packed structs as QEMU_PACKED
  slirp: Don't mark struct ipq or struct ipasfrag as packed

Samuel Thibault (1):
  slirp: Avoid unaligned 16bit memory access

----------------------------------------------------------------
Peter Maydell (2):
      slirp: Avoid marking naturally packed structs as QEMU_PACKED
      slirp: Don't mark struct ipq or struct ipasfrag as packed

Samuel Thibault (1):
      slirp: Avoid unaligned 16bit memory access

 slirp/ip.h       |  7 +++++--
 slirp/ip6.h      | 12 ++++++++++--
 slirp/ip6_icmp.h | 20 +++++++++++++++-----
 slirp/slirp.c    |  2 +-
 4 files changed, 31 insertions(+), 10 deletions(-)

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

* [Qemu-devel] [PULL 1/3] slirp: Avoid unaligned 16bit memory access
  2019-01-26 21:20 [Qemu-devel] [PULL 0/3] slirp updates Samuel Thibault
@ 2019-01-26 21:20 ` Samuel Thibault
  2019-01-26 21:20 ` [Qemu-devel] [PULL 2/3] slirp: Avoid marking naturally packed structs as QEMU_PACKED Samuel Thibault
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Samuel Thibault @ 2019-01-26 21:20 UTC (permalink / raw)
  To: qemu-devel; +Cc: Samuel Thibault, stefanha, jan.kiszka, Richard Henderson

pkt parameter may be unaligned, so we must access it byte-wise.

This fixes sparc64 host SIGBUS during pxe boot.

Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 slirp/slirp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/slirp/slirp.c b/slirp/slirp.c
index a9674ab090..739f364770 100644
--- a/slirp/slirp.c
+++ b/slirp/slirp.c
@@ -829,7 +829,7 @@ void slirp_input(Slirp *slirp, const uint8_t *pkt, int pkt_len)
     if (pkt_len < ETH_HLEN)
         return;
 
-    proto = ntohs(*(uint16_t *)(pkt + 12));
+    proto = (((uint16_t) pkt[12]) << 8) + pkt[13];
     switch(proto) {
     case ETH_P_ARP:
         arp_input(slirp, pkt, pkt_len);
-- 
2.20.1

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

* [Qemu-devel] [PULL 2/3] slirp: Avoid marking naturally packed structs as QEMU_PACKED
  2019-01-26 21:20 [Qemu-devel] [PULL 0/3] slirp updates Samuel Thibault
  2019-01-26 21:20 ` [Qemu-devel] [PULL 1/3] slirp: Avoid unaligned 16bit memory access Samuel Thibault
@ 2019-01-26 21:20 ` Samuel Thibault
  2019-01-26 21:20 ` [Qemu-devel] [PULL 3/3] slirp: Don't mark struct ipq or struct ipasfrag as packed Samuel Thibault
  2019-01-27 12:05 ` [Qemu-devel] [PULL 0/3] slirp updates Samuel Thibault
  3 siblings, 0 replies; 5+ messages in thread
From: Samuel Thibault @ 2019-01-26 21:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, stefanha, jan.kiszka, Eric Blake, Samuel Thibault

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

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

* [Qemu-devel] [PULL 3/3] slirp: Don't mark struct ipq or struct ipasfrag as packed
  2019-01-26 21:20 [Qemu-devel] [PULL 0/3] slirp updates Samuel Thibault
  2019-01-26 21:20 ` [Qemu-devel] [PULL 1/3] slirp: Avoid unaligned 16bit memory access Samuel Thibault
  2019-01-26 21:20 ` [Qemu-devel] [PULL 2/3] slirp: Avoid marking naturally packed structs as QEMU_PACKED Samuel Thibault
@ 2019-01-26 21:20 ` Samuel Thibault
  2019-01-27 12:05 ` [Qemu-devel] [PULL 0/3] slirp updates Samuel Thibault
  3 siblings, 0 replies; 5+ messages in thread
From: Samuel Thibault @ 2019-01-26 21:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, stefanha, jan.kiszka, Eric Blake, Samuel Thibault

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

There is no reason to mark the struct ipq and struct ipasfrag as
packed: they are naturally aligned anyway, and are not representing
any on-the-wire packet format.  Indeed they vary in size depending on
the size of pointers on the host system, because the 'struct qlink'
members include 'void *' fields.

Dropping the 'packed' annotation fixes clang -Waddress-of-packed-member
warnings and probably lets the compiler generate better code too.

The only thing we do care about in the layout of the struct is
that the frag_link matches up with the ipf_link of the struct
ipasfrag, as documented in the comment on that struct; assert
at build time that this is the case.

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/ip.h | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/slirp/ip.h b/slirp/ip.h
index 243b6c8b24..20614f3b53 100644
--- a/slirp/ip.h
+++ b/slirp/ip.h
@@ -217,7 +217,7 @@ struct ipq {
 	uint8_t	ipq_p;			/* protocol of this fragment */
 	uint16_t	ipq_id;			/* sequence id for reassembly */
 	struct	in_addr ipq_src,ipq_dst;
-} QEMU_PACKED;
+};
 
 /*
  * Ip header, when holding a fragment.
@@ -227,7 +227,10 @@ struct ipq {
 struct	ipasfrag {
 	struct qlink ipf_link;
 	struct ip ipf_ip;
-} QEMU_PACKED;
+};
+
+QEMU_BUILD_BUG_ON(offsetof(struct ipq, frag_link) !=
+                  offsetof(struct ipasfrag, ipf_link));
 
 #define ipf_off      ipf_ip.ip_off
 #define ipf_tos      ipf_ip.ip_tos
-- 
2.20.1

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

* Re: [Qemu-devel] [PULL 0/3] slirp updates
  2019-01-26 21:20 [Qemu-devel] [PULL 0/3] slirp updates Samuel Thibault
                   ` (2 preceding siblings ...)
  2019-01-26 21:20 ` [Qemu-devel] [PULL 3/3] slirp: Don't mark struct ipq or struct ipasfrag as packed Samuel Thibault
@ 2019-01-27 12:05 ` Samuel Thibault
  3 siblings, 0 replies; 5+ messages in thread
From: Samuel Thibault @ 2019-01-27 12:05 UTC (permalink / raw)
  To: qemu-devel; +Cc: stefanha, jan.kiszka

This is actually superseded by the complete pull I have just sent.

Samuel

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

end of thread, other threads:[~2019-01-27 12:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-26 21:20 [Qemu-devel] [PULL 0/3] slirp updates Samuel Thibault
2019-01-26 21:20 ` [Qemu-devel] [PULL 1/3] slirp: Avoid unaligned 16bit memory access Samuel Thibault
2019-01-26 21:20 ` [Qemu-devel] [PULL 2/3] slirp: Avoid marking naturally packed structs as QEMU_PACKED Samuel Thibault
2019-01-26 21:20 ` [Qemu-devel] [PULL 3/3] slirp: Don't mark struct ipq or struct ipasfrag as packed Samuel Thibault
2019-01-27 12:05 ` [Qemu-devel] [PULL 0/3] slirp updates Samuel Thibault

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.