Skip to content

Commit 6cf9ac7

Browse files
committed
driver: do not assume aligned addresses when allocating MDLs
IoAllocateMdl allocates a different size structure depending on the bottom in-page bits of the address. By passing null, it assumes that the address is aligned within the page, which it might not be. Fix this by passing the eventual virtual address to the allocation function so that the right amount is always allocated. Reported-by: Oleksandr Muzychuk <[email protected]> Signed-off-by: Jason A. Donenfeld <[email protected]>
1 parent f19945b commit 6cf9ac7

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

driver/wintun.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,13 +517,15 @@ TunProcessReceiveData(_Inout_ TUN_CTX *Ctx)
517517
break;
518518

519519
RingHead = TUN_RING_WRAP(RingHead + AlignedPacketSize, RingCapacity);
520-
MDL *Mdl = IoAllocateMdl(NULL, PacketSize, FALSE, FALSE, NULL);
520+
VOID *PacketAddr =
521+
(UCHAR *)MmGetMdlVirtualAddress(Ctx->Device.Receive.Mdl) + (ULONG)(Packet->Data - (UCHAR *)Ring);
522+
MDL *Mdl = IoAllocateMdl(PacketAddr, PacketSize, FALSE, FALSE, NULL);
521523
if (!Mdl)
522524
goto skipNbl;
523525
IoBuildPartialMdl(
524526
Ctx->Device.Receive.Mdl,
525527
Mdl,
526-
(UCHAR *)MmGetMdlVirtualAddress(Ctx->Device.Receive.Mdl) + (ULONG)(Packet->Data - (UCHAR *)Ring),
528+
PacketAddr,
527529
PacketSize);
528530
NET_BUFFER_LIST *Nbl = NdisAllocateNetBufferAndNetBufferList(Ctx->NblPool, 0, 0, Mdl, 0, PacketSize);
529531
if (!Nbl)

0 commit comments

Comments
 (0)