Development discussion of WireGuard
 help / color / mirror / Atom feed
From: James Tucker <jftucker@gmail.com>
To: wireguard@lists.zx2c4.com
Subject: [PATCH] uapi: add bit-field padding for field alignment
Date: Mon,  9 Jan 2017 19:47:29 -0800	[thread overview]
Message-ID: <20170110034729.40733-1-jftucker@gmail.com> (raw)

The C language does not specify the layout behavior of bit-fields. As a
consequence, compilers are free to do interesting things with these
fields, including reorder, split, pick size, etc. In this case, it was
observed that on x64, gcc and clang were using only two bytes between
tx_bytes and num_ipmasks in wgpeer, causing interoperability issues.

While non-native clients (i.e. wireguard-go) could be fixed, the problem
will keep on giving, as the layouts can be changed by compiler flags and
architectures, which will make portability for all non-C implementations
extremely difficult. Compilers also do not document their behavior well
in this regard.

Signed-off-by: James Tucker <jftucker@gmail.com>
---
 src/uapi.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/uapi.h b/src/uapi.h
index cd4b86b..bf38f48 100644
--- a/src/uapi.h
+++ b/src/uapi.h
@@ -107,6 +107,7 @@ struct wgpeer {
 
 	__u32 remove_me : 1; /* Set */
 	__u32 replace_ipmasks : 1; /* Set */
+	__u32 : 32-2; /* pad to force portable field size */
 
 	__u16 num_ipmasks; /* Get/Set */
 	__u16 persistent_keepalive_interval; /* Get/Set -- 0 = off, 0xffff = unset */
@@ -124,6 +125,7 @@ struct wgdevice {
 	__u32 replace_peer_list : 1; /* Set */
 	__u32 remove_private_key : 1; /* Set */
 	__u32 remove_preshared_key : 1; /* Set */
+	__u32 : 32-3; /* pad to force portable field size */
 
 	union {
 		__u16 num_peers; /* Get/Set */
-- 
2.11.0

             reply	other threads:[~2017-01-10  3:37 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-10  3:47 James Tucker [this message]
2017-01-10  4:22 ` Jason A. Donenfeld
2017-01-10  4:33   ` James Tucker

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=20170110034729.40733-1-jftucker@gmail.com \
    --to=jftucker@gmail.com \
    --cc=wireguard@lists.zx2c4.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).