From: Eric Kohl Date: Wed, 24 Nov 2021 12:34:26 +0000 (+0100) Subject: [NTOS:IO] Fail, if io completion port and an apc routine are used at the same time X-Git-Url: https://git.reactos.org/?p=reactos.git;a=commitdiff_plain;h=07e19a5e093ec444640313baa4a71e5c1940d517 [NTOS:IO] Fail, if io completion port and an apc routine are used at the same time Add checks to NtNotifyChangeDirectoryFile, NtLockFile, NtReadFile and NtWriteFile. This fixes two ntdll tests. --- diff --git a/ntoskrnl/io/iomgr/iofunc.c b/ntoskrnl/io/iomgr/iofunc.c index b9bf75736f5..62fb626fa25 100644 --- a/ntoskrnl/io/iomgr/iofunc.c +++ b/ntoskrnl/io/iomgr/iofunc.c @@ -287,7 +287,7 @@ IopDeviceFsIoControl(IN HANDLE DeviceHandle, &HandleInformation); if (!NT_SUCCESS(Status)) return Status; - /* Can't use an I/O completion port and an APC in the same time */ + /* Can't use an I/O completion port and an APC at the same time */ if ((FileObject->CompletionContext) && (UserApcRoutine)) { /* Fail */ @@ -1675,6 +1675,14 @@ NtNotifyChangeDirectoryFile(IN HANDLE FileHandle, NULL); if (!NT_SUCCESS(Status)) return Status; + /* Can't use an I/O completion port and an APC at the same time */ + if ((FileObject->CompletionContext) && (ApcRoutine)) + { + /* Fail */ + ObDereferenceObject(FileObject); + return STATUS_INVALID_PARAMETER; + } + /* Check if we have an event handle */ if (EventHandle) { @@ -1793,6 +1801,14 @@ NtLockFile(IN HANDLE FileHandle, /* Check if we're called from user mode */ if (PreviousMode != KernelMode) { + /* Can't use an I/O completion port and an APC at the same time */ + if ((FileObject->CompletionContext) && (ApcRoutine)) + { + /* Fail */ + ObDereferenceObject(FileObject); + return STATUS_INVALID_PARAMETER; + } + /* Must have either FILE_READ_DATA or FILE_WRITE_DATA access */ if (!(HandleInformation.GrantedAccess & (FILE_WRITE_DATA | FILE_READ_DATA))) @@ -2743,6 +2759,14 @@ NtReadFile(IN HANDLE FileHandle, CapturedByteOffset = ProbeForReadLargeInteger(ByteOffset); } + /* Can't use an I/O completion port and an APC at the same time */ + if ((FileObject->CompletionContext) && (ApcRoutine)) + { + /* Fail */ + ObDereferenceObject(FileObject); + return STATUS_INVALID_PARAMETER; + } + /* Perform additional checks for non-cached file access */ if (FileObject->Flags & FO_NO_INTERMEDIATE_BUFFERING) { @@ -3796,6 +3820,14 @@ NtWriteFile(IN HANDLE FileHandle, CapturedByteOffset = ProbeForReadLargeInteger(ByteOffset); } + /* Can't use an I/O completion port and an APC at the same time */ + if ((FileObject->CompletionContext) && (ApcRoutine)) + { + /* Fail */ + ObDereferenceObject(FileObject); + return STATUS_INVALID_PARAMETER; + } + /* Perform additional checks for non-cached file access */ if (FileObject->Flags & FO_NO_INTERMEDIATE_BUFFERING) {