Skip to content

Commit

Permalink
interactive.c: Fix potential stack overflow issue
Browse files Browse the repository at this point in the history
When reading message from the pipe, we first peek the pipe to get the size
of the message waiting to be read and then read the message. A compromised
OpenVPN process could send an excessively large message, which would result
in a stack-allocated message buffer overflow.

To address this, we terminate the misbehaving process if the peeked message
size exceeds the maximum allowable size.

CVE: 2024-27459
Microsoft case number: 85932

Reported-by: Vladimir Tokarev <[email protected]>
Change-Id: Ib5743cba0741ea11f9ee62c4978b2c6789b81ada
Signed-off-by: Lev Stipakov <[email protected]>
Acked-by: Heiko Hund <[email protected]>
Message-Id: <[email protected]>
URL: https://www.mail-archive.com/[email protected]/msg28420.html
Signed-off-by: Gert Doering <[email protected]>
(cherry picked from commit 989b22c)
  • Loading branch information
lstipakov authored and cron2 committed Mar 19, 2024
1 parent a95e665 commit 9b2693f
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions src/openvpnserv/interactive.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,18 @@ typedef struct {
struct tun_ring *receive_ring;
} ring_buffer_maps_t;

typedef union {
message_header_t header;
address_message_t address;
route_message_t route;
flush_neighbors_message_t flush_neighbors;
block_dns_message_t block_dns;
dns_cfg_message_t dns;
enable_dhcp_message_t dhcp;
register_ring_buffers_message_t rrb;
set_mtu_message_t mtu;
wins_cfg_message_t wins;
} pipe_message_t;

static DWORD
AddListItem(list_item_t **pfirst, LPVOID data)
Expand Down Expand Up @@ -1610,19 +1622,7 @@ static VOID
HandleMessage(HANDLE pipe, HANDLE ovpn_proc,
DWORD bytes, DWORD count, LPHANDLE events, undo_lists_t *lists)
{
DWORD read;
union {
message_header_t header;
address_message_t address;
route_message_t route;
flush_neighbors_message_t flush_neighbors;
block_dns_message_t block_dns;
dns_cfg_message_t dns;
enable_dhcp_message_t dhcp;
register_ring_buffers_message_t rrb;
set_mtu_message_t mtu;
wins_cfg_message_t wins;
} msg;
pipe_message_t msg;
ack_message_t ack = {
.header = {
.type = msg_acknowledgement,
Expand All @@ -1632,7 +1632,7 @@ HandleMessage(HANDLE pipe, HANDLE ovpn_proc,
.error_number = ERROR_MESSAGE_DATA
};

read = ReadPipeAsync(pipe, &msg, bytes, count, events);
DWORD read = ReadPipeAsync(pipe, &msg, bytes, count, events);
if (read != bytes || read < sizeof(msg.header) || read != msg.header.size)
{
goto out;
Expand Down Expand Up @@ -2059,6 +2059,13 @@ RunOpenvpn(LPVOID p)
break;
}

if (bytes > sizeof(pipe_message_t))
{
/* process at the other side of the pipe is misbehaving, shut it down */
MsgToEventLog(MSG_FLAGS_ERROR, TEXT("OpenVPN process sent too large payload length to the pipe (%lu bytes), it will be terminated"), bytes);
break;
}

HandleMessage(ovpn_pipe, proc_info.hProcess, bytes, 1, &exit_event, &undo_lists);
}

Expand Down

0 comments on commit 9b2693f

Please sign in to comment.