Skip to content

Commit

Permalink
Driver.cpp: Add some mode checks to OvpnEvtIoDeviceControl
Browse files Browse the repository at this point in the history
Return an error to a userspace if P2P-only IOCTLs
are used in MP mode.

Signed-off-by: Lev Stipakov <[email protected]>
  • Loading branch information
lstipakov committed Sep 13, 2024
1 parent 41d836e commit cfbe20d
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,27 @@ OvpnSetMode(POVPN_DEVICE device, WDFREQUEST request)
return status;
}

static BOOLEAN
OvpnDeviceCheckMode(OVPN_MODE mode, ULONG code)
{
if (mode == OVPN_MODE_MP)
{
switch (code)
{
// all those IOCTLs are only for P2P mode
case OVPN_IOCTL_NEW_PEER:
case OVPN_IOCTL_DEL_PEER:
case OVPN_IOCTL_NEW_KEY:
case OVPN_IOCTL_NEW_KEY_V2:
case OVPN_IOCTL_SWAP_KEYS:
case OVPN_IOCTL_SET_PEER:
return FALSE;
}
}

return TRUE;
}

static NTSTATUS
OvpnStopVPN(_In_ POVPN_DEVICE device)
{
Expand Down Expand Up @@ -316,6 +337,12 @@ OvpnEvtIoDeviceControl(WDFQUEUE queue, WDFREQUEST request, size_t outputBufferLe

ULONG_PTR bytesReturned = 0;

if (!OvpnDeviceCheckMode(device->Mode, ioControlCode))
{
WdfRequestCompleteWithInformation(request, STATUS_INVALID_DEVICE_STATE, bytesReturned);
return;
}

KIRQL kirql = 0;
switch ((long)ioControlCode) {
case OVPN_IOCTL_GET_STATS:
Expand Down

0 comments on commit cfbe20d

Please sign in to comment.