From fb738767a0b4549f8a7301a314942b02d1d05792 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Fri, 5 Jul 2019 14:41:54 +0000 Subject: [PATCH] Remove TunMapIrp Signed-off-by: Jason A. Donenfeld --- wintun.c | 36 ++++++++---------------------------- 1 file changed, 8 insertions(+), 28 deletions(-) diff --git a/wintun.c b/wintun.c index 511defb..fac662e 100644 --- a/wintun.c +++ b/wintun.c @@ -346,32 +346,6 @@ TunUnmapUbuffer(_Inout_ TUN_MAPPED_UBUFFER *MappedBuffer) } } -_IRQL_requires_max_(APC_LEVEL) -_Must_inspect_result_ -static NTSTATUS -TunMapIrp(_In_ IRP *Irp) -{ - ULONG Size; - TUN_MAPPED_UBUFFER *UserBuffer; - IO_STACK_LOCATION *Stack = IoGetCurrentIrpStackLocation(Irp); - TUN_FILE_CTX *FileCtx = (TUN_FILE_CTX *)Stack->FileObject->FsContext; - - switch (Stack->MajorFunction) - { - case IRP_MJ_READ: - Size = Stack->Parameters.Read.Length; - if (Size < TUN_EXCH_MIN_BUFFER_SIZE_READ) - return STATUS_INVALID_USER_BUFFER; - UserBuffer = &FileCtx->ReadBuffer; - break; - default: - return STATUS_INVALID_PARAMETER; - } - if (Size > TUN_EXCH_MAX_BUFFER_SIZE) - return STATUS_INVALID_USER_BUFFER; - return TunMapUbuffer(UserBuffer, Irp->UserBuffer, Size); -} - _IRQL_requires_max_(DISPATCH_LEVEL) _Must_inspect_result_ static _Return_type_success_( @@ -737,8 +711,14 @@ _Must_inspect_result_ static NTSTATUS TunDispatchRead(_Inout_ TUN_CTX *Ctx, _Inout_ IRP *Irp) { - NTSTATUS Status = TunMapIrp(Irp); - if (!NT_SUCCESS(Status)) + IO_STACK_LOCATION *Stack = IoGetCurrentIrpStackLocation(Irp); + ULONG Size = Stack->Parameters.Read.Length; + TUN_MAPPED_UBUFFER *UserBuffer = &((TUN_FILE_CTX *)Stack->FileObject->FsContext)->ReadBuffer; + NTSTATUS Status; + + if (Status = STATUS_INVALID_USER_BUFFER, Size < TUN_EXCH_MIN_BUFFER_SIZE_READ || Size > TUN_EXCH_MAX_BUFFER_SIZE) + goto cleanupCompleteRequest; + if (!NT_SUCCESS(Status = TunMapUbuffer(UserBuffer, Irp->UserBuffer, Size))) goto cleanupCompleteRequest; KIRQL Irql = ExAcquireSpinLockShared(&Ctx->TransitionLock);