Development discussion of WireGuard
 help / color / mirror / Atom feed
* [PATCH] uapi: add bit-field padding for field alignment
@ 2017-01-10  3:47 James Tucker
  2017-01-10  4:22 ` Jason A. Donenfeld
  0 siblings, 1 reply; 3+ messages in thread
From: James Tucker @ 2017-01-10  3:47 UTC (permalink / raw)
  To: wireguard

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

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

* Re: [PATCH] uapi: add bit-field padding for field alignment
  2017-01-10  3:47 [PATCH] uapi: add bit-field padding for field alignment James Tucker
@ 2017-01-10  4:22 ` Jason A. Donenfeld
  2017-01-10  4:33   ` James Tucker
  0 siblings, 1 reply; 3+ messages in thread
From: Jason A. Donenfeld @ 2017-01-10  4:22 UTC (permalink / raw)
  To: James Tucker; +Cc: WireGuard mailing list

I think I'm going to roll with a flags fix instead, like this:
https://git.zx2c4.com/WireGuard/commit/?id=45bd499f15debb0e2443b15f7ff1d0ef93950acc

This should eliminate all portability issues.

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

* Re: [PATCH] uapi: add bit-field padding for field alignment
  2017-01-10  4:22 ` Jason A. Donenfeld
@ 2017-01-10  4:33   ` James Tucker
  0 siblings, 0 replies; 3+ messages in thread
From: James Tucker @ 2017-01-10  4:33 UTC (permalink / raw)
  To: Jason A. Donenfeld; +Cc: WireGuard mailing list

[-- Attachment #1: Type: text/plain, Size: 298 bytes --]

Thanks Jason!

On Mon, Jan 9, 2017 at 8:22 PM, Jason A. Donenfeld <Jason@zx2c4.com> wrote:

> I think I'm going to roll with a flags fix instead, like this:
> https://git.zx2c4.com/WireGuard/commit/?id=45bd499f15debb0e2443b15f7ff1d0
> ef93950acc
>
> This should eliminate all portability issues.
>

[-- Attachment #2: Type: text/html, Size: 746 bytes --]

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

end of thread, other threads:[~2017-01-10  4:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-10  3:47 [PATCH] uapi: add bit-field padding for field alignment James Tucker
2017-01-10  4:22 ` Jason A. Donenfeld
2017-01-10  4:33   ` James Tucker

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).