Skip to content

Commit df1cd47

Browse files
authored
Bug fix
1 parent dde4c71 commit df1cd47

7 files changed

Lines changed: 22 additions & 12 deletions

File tree

src/compat/Kbuild.include

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,11 @@ endif
101101
ifneq ($(shell grep -s -F "\#define LINUX_PACKAGE_ID \" Debian " "$(CURDIR)/include/generated/package.h"),)
102102
ccflags-y += -DISDEBIAN
103103
endif
104+
105+
ifeq ($(wildcard $(srctree)/include/linux/kstrtox.h),)
106+
ccflags-y += -I$(kbuild-dir)/compat/kstrtox/include
107+
endif
108+
109+
ifeq ($(wildcard $(srctree)/include/linux/sprintf.h),)
110+
ccflags-y += -I$(kbuild-dir)/compat/sprintf/include
111+
endif
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include <linux/kernel.h>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include <linux/kernel.h>

src/device.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "peerlookup.h"
1313
#include "cookie.h"
1414
#include "magic_header.h"
15+
#include "messages.h"
1516

1617
#include <linux/types.h>
1718
#include <linux/netdevice.h>
@@ -75,4 +76,13 @@ int wg_device_init(void);
7576
void wg_device_uninit(void);
7677
int wg_device_handle_post_config(struct wg_device *wg);
7778

79+
static inline bool client_id_asc_coexist(struct wg_device *wg)
80+
{
81+
return
82+
wg->headers[MSGIDX_HANDSHAKE_INIT].start <= 0xFF &&
83+
wg->headers[MSGIDX_HANDSHAKE_RESPONSE].start <= 0xFF &&
84+
wg->headers[MSGIDX_HANDSHAKE_COOKIE].start <= 0xFF &&
85+
wg->headers[MSGIDX_TRANSPORT].start <= 0xFF;
86+
}
87+
7888
#endif /* _WG_DEVICE_H */

src/magic_header.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ int mh_genspec(struct magic_header *mh, char *desc, size_t buflen);
1313

1414
bool mh_validate(__le32 received, struct magic_header* mh);
1515
u32 mh_genheader(struct magic_header* mh);
16+
u32 wg_get_random_u32_inclusive(u32 floor, u32 ceil);
1617

1718
#endif

src/messages.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
#ifndef _WG_MESSAGES_H
77
#define _WG_MESSAGES_H
88

9-
#include "device.h"
10-
119
#include <zinc/curve25519.h>
1210
#include <zinc/chacha20poly1305.h>
1311
#include <zinc/blake2s.h>
@@ -134,15 +132,6 @@ enum message_size {
134132
MESSAGE_MAX_SIZE = 65535
135133
};
136134

137-
static inline bool client_id_asc_coexist(struct wg_device *wg)
138-
{
139-
return
140-
wg->headers[MSGIDX_HANDSHAKE_INIT].start <= 0xFF &&
141-
wg->headers[MSGIDX_HANDSHAKE_RESPONSE].start <= 0xFF &&
142-
wg->headers[MSGIDX_HANDSHAKE_COOKIE].start <= 0xFF &&
143-
wg->headers[MSGIDX_TRANSPORT].start <= 0xFF;
144-
}
145-
146135
#define SKB_TYPE_LE32(skb, wg) ((((struct message_header *)(skb)->data)->type) & (!client_id_asc_coexist(wg) ? 0xFFFFFFFF : cpu_to_le32(0xFF)))
147136
#define SKB_CLEAR_TYPE(skb, wg) ((((struct message_header *)(skb)->data)->type) &= (!client_id_asc_coexist(wg) ? 0xFFFFFFFF : cpu_to_le32(0xFF)))
148137

src/send.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ static void wg_packet_send_handshake_initiation(struct wg_peer *peer)
7070
buffer = kzalloc(wg->jmax, GFP_KERNEL);
7171

7272
while (junk_packet_count-- > 0) {
73-
junk_packet_size = (u16) get_random_u32_inclusive(wg->jmin, wg->jmax);
73+
junk_packet_size = (u16) wg_get_random_u32_inclusive(wg->jmin, wg->jmax);
7474

7575
get_random_bytes(buffer, junk_packet_size);
7676
get_random_bytes(&ds, 1);

0 commit comments

Comments
 (0)