On Tue, Sep 14, 2021 at 01:29:05PM +0000, Visa Hankala wrote:
> On Tue, May 04, 2021 at 07:29:20AM +0200, Peter J. Philipp wrote:
[some of my earlier mail cut]
> data->nonce is the (most) offending variable because it needs 8-byte
> alignment.
>
> An alternative to memcpy() is to use tcpdump's EXTRACT_* macros that
> handle unaligned data.
>
> Yet another option is to declare the structs with the "packed" type
> attribute. This makes the compiler emit machine code that is safe with
> unaligned data. This also enables type checking that is better than with
> EXTRACT_* because types are not overridden with explicit type casts.
> However, "packed" makes it non obvious that unaligned accesses
> may happen.
I like this option and I have tested it on my octeon gateway. It works!
I also powercycled the linux wg speaker behind a certain vlan and left
tcpdump running. No segfaults.
eta# sysctl kern.version
kern.version=OpenBSD 6.9 (GENERIC.MP) #551: Sun Apr 18 03:06:59 MDT 2021
[email protected]:/usr/src/sys/arch/octeon/compile/GENERIC.MP
an older version, but the patch applied. Thank you for looking into this Visa!
Best Regards,
-peter
> Index: print-wg.c
> ===================================================================
> RCS file: src/usr.sbin/tcpdump/print-wg.c,v
> retrieving revision 1.6
> diff -u -p -r1.6 print-wg.c
> --- print-wg.c 14 Apr 2021 19:34:56 -0000 1.6
> +++ print-wg.c 14 Sep 2021 12:42:32 -0000
> @@ -34,20 +34,20 @@ struct wg_initiation {
> uint32_t type;
> uint32_t sender;
> uint8_t fill[140]; /* Includes ephemeral + MAC */
> -};
> +} __packed;
>
> struct wg_response {
> uint32_t type;
> uint32_t sender;
> uint32_t receiver;
> uint8_t fill[80]; /* Includes ephemeral + MAC */
> -};
> +} __packed;
>
> struct wg_cookie {
> uint32_t type;
> uint32_t receiver;
> uint8_t fill[56]; /* Includes nonce + encrypted cookie */
> -};
> +} __packed;
>
> struct wg_data {
> uint32_t type;
> @@ -55,7 +55,7 @@ struct wg_data {
> uint64_t nonce;
> /* uint8_t data[variable]; - Variable length data */
> uint8_t mac[16];
> -};
> +} __packed;
>
> /*
> * Check if packet is a WireGuard packet, as WireGuard may run on any port.
>