From e2904d3baf70f1f9f61f6b5d379e2b31ccd79f84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Poussineau?= Date: Sat, 28 Jun 2025 13:44:55 +0200 Subject: [PATCH] [NDIS] NdisOpenFile: read file contents into buffer when opening it NdisMapFile now returns a non-null buffer. CORE-20259 --- drivers/network/ndis/ndis/misc.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/drivers/network/ndis/ndis/misc.c b/drivers/network/ndis/ndis/misc.c index 5304928fc2b..3fe8109b30f 100644 --- a/drivers/network/ndis/ndis/misc.c +++ b/drivers/network/ndis/ndis/misc.c @@ -207,6 +207,8 @@ NdisCloseFile( if ( FileHandleObject->Mapped ) NdisUnmapFile ( FileHandle ); + if ( FileHandleObject->MapBuffer ) + ExFreePool ( FileHandleObject->MapBuffer ); ZwClose ( FileHandleObject->FileHandle ); @@ -321,6 +323,31 @@ NdisOpenFile( } NtFileLength = StandardInfo.EndOfFile.LowPart; + FileHandleObject->MapBuffer = ExAllocatePool( NonPagedPool, NtFileLength ); + if (!FileHandleObject->MapBuffer) + { + NDIS_DbgPrint(MIN_TRACE, ("ExAllocatePool failed Name %wZ\n", FileName)); + *Status = NDIS_STATUS_ERROR_READING_FILE; + goto cleanup; + } + + NtStatus = ZwReadFile( + NtFileHandle, + NULL, + NULL, + NULL, + &IoStatusBlock, + FileHandleObject->MapBuffer, + NtFileLength, + NULL, + NULL); + if ( !NT_SUCCESS(NtStatus) || IoStatusBlock.Information != NtFileLength ) + { + NDIS_DbgPrint(MIN_TRACE, ("ZwReadFile failed (%x) Name %wZ\n", NtStatus, FileName)); + *Status = NDIS_STATUS_ERROR_READING_FILE; + goto cleanup; + } + cleanup: if ( FullFileName.Buffer != NULL ) { @@ -331,6 +358,8 @@ cleanup: { if ( FileHandleObject ) { + if ( FileHandleObject->MapBuffer ) + ExFreePool( FileHandleObject->MapBuffer ); ExFreePool ( FileHandleObject ); } *FileHandle = NULL;