Skip to content

Commit 204305a

Browse files
committed
fix unaligned read in OpenVPN UDP probe
1 parent 0f96ed8 commit 204305a

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

Makefile.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ MAN=sslh.8.gz # man page name
2222
# itself
2323

2424
ifneq ($(strip $(ENABLE_SANITIZER)),)
25-
CFLAGS_SAN=-fsanitize=address -fsanitize=leak -fsanitize=undefined
25+
CFLAGS_SAN=-fsanitize=address -fsanitize=leak -fsanitize=undefined -fsanitize=alignment
2626
endif
2727

2828
ifneq ($(strip $(COV_TEST)),)

probe.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ static int is_ssh_protocol(const char *p, ssize_t len, struct sslhcfg_protocols_
147147
#define OVPN_OPCODE_MASK 0xF8
148148
#define OVPN_CONTROL_HARD_RESET_CLIENT_V1 (0x01 << 3)
149149
#define OVPN_CONTROL_HARD_RESET_CLIENT_V2 (0x07 << 3)
150+
#define OVPN_CONTROL_HARD_RESET_CLIENT_V3 (0x0A << 3)
150151
#define OVPN_HMAC_128 16
151152
#define OVPN_HMAC_160 20
152153
#define OVPN_HARD_RESET_PACKET_ID_OFFSET(hmac_size) (9 + hmac_size)
@@ -165,8 +166,12 @@ static int is_openvpn_protocol (const char*p,ssize_t len, struct sslhcfg_protoco
165166
if (len < 1)
166167
return PROBE_NEXT;
167168

169+
printf("opcode: %d\n", (p[0] & OVPN_OPCODE_MASK) >> 3);
170+
168171
if ((p[0] & OVPN_OPCODE_MASK) != OVPN_CONTROL_HARD_RESET_CLIENT_V1 &&
169-
(p[0] & OVPN_OPCODE_MASK) != OVPN_CONTROL_HARD_RESET_CLIENT_V2)
172+
(p[0] & OVPN_OPCODE_MASK) != OVPN_CONTROL_HARD_RESET_CLIENT_V2 &&
173+
(p[0] & OVPN_OPCODE_MASK) != OVPN_CONTROL_HARD_RESET_CLIENT_V3
174+
)
170175
return PROBE_NEXT;
171176

172177
/* The detection pattern above may not be reliable enough.
@@ -177,12 +182,18 @@ static int is_openvpn_protocol (const char*p,ssize_t len, struct sslhcfg_protoco
177182
if (len <= OVPN_HARD_RESET_PACKET_ID_OFFSET(OVPN_HMAC_128) + sizeof(uint32_t))
178183
return PROBE_NEXT;
179184

180-
if (ntohl(*(uint32_t*)(p + OVPN_HARD_RESET_PACKET_ID_OFFSET(OVPN_HMAC_128))) <= 5u)
185+
uint32_t i;
186+
/* OVPN_HMAC_128 is unaligned, which requires special care e.g. on ARM */
187+
memcpy(&i, (p + OVPN_HARD_RESET_PACKET_ID_OFFSET(OVPN_HMAC_128)), sizeof(i));
188+
i = ntohl(i);
189+
if (i <= 5u)
181190
return PROBE_MATCH;
182191

183192
if (len <= OVPN_HARD_RESET_PACKET_ID_OFFSET(OVPN_HMAC_160) + sizeof(uint32_t))
184193
return PROBE_NEXT;
185194

195+
memcpy(&i, (p + OVPN_HARD_RESET_PACKET_ID_OFFSET(OVPN_HMAC_160)), sizeof(i));
196+
i = ntohl(i);
186197
if (ntohl(*(uint32_t*)(p + OVPN_HARD_RESET_PACKET_ID_OFFSET(OVPN_HMAC_160))) <= 5u)
187198
return PROBE_MATCH;
188199

0 commit comments

Comments
 (0)