[KMTESTS:CC] Add tests for CcCopyRead that reproduce CORE-15067

CORE-15067
This commit is contained in:
Pierre Schweitzer 2018-09-21 08:35:38 +02:00
parent 15a3ca08b0
commit 351ae6b2b4
No known key found for this signature in database
GPG key ID: 7545556C3D585B0B
2 changed files with 29 additions and 2 deletions

View file

@ -15,6 +15,7 @@ typedef struct _TEST_FCB
FSRTL_ADVANCED_FCB_HEADER Header; FSRTL_ADVANCED_FCB_HEADER Header;
SECTION_OBJECT_POINTERS SectionObjectPointers; SECTION_OBJECT_POINTERS SectionObjectPointers;
FAST_MUTEX HeaderMutex; FAST_MUTEX HeaderMutex;
BOOLEAN BigFile;
} TEST_FCB, *PTEST_FCB; } TEST_FCB, *PTEST_FCB;
static PFILE_OBJECT TestFileObject; static PFILE_OBJECT TestFileObject;
@ -184,6 +185,7 @@ TestIrpHandler(
RtlZeroMemory(Fcb, sizeof(*Fcb)); RtlZeroMemory(Fcb, sizeof(*Fcb));
ExInitializeFastMutex(&Fcb->HeaderMutex); ExInitializeFastMutex(&Fcb->HeaderMutex);
FsRtlSetupAdvancedHeader(&Fcb->Header, &Fcb->HeaderMutex); FsRtlSetupAdvancedHeader(&Fcb->Header, &Fcb->HeaderMutex);
Fcb->BigFile = FALSE;
if (IoStack->FileObject->FileName.Length >= 2 * sizeof(WCHAR) && if (IoStack->FileObject->FileName.Length >= 2 * sizeof(WCHAR) &&
IoStack->FileObject->FileName.Buffer[1] == 'B') IoStack->FileObject->FileName.Buffer[1] == 'B')
{ {
@ -205,6 +207,14 @@ TestIrpHandler(
Fcb->Header.FileSize.QuadPart = 62; Fcb->Header.FileSize.QuadPart = 62;
Fcb->Header.ValidDataLength.QuadPart = 62; Fcb->Header.ValidDataLength.QuadPart = 62;
} }
else if (IoStack->FileObject->FileName.Length >= 2 * sizeof(WCHAR) &&
IoStack->FileObject->FileName.Buffer[1] == 'F')
{
Fcb->Header.AllocationSize.QuadPart = 4294967296;
Fcb->Header.FileSize.QuadPart = 4294967296;
Fcb->Header.ValidDataLength.QuadPart = 4294967296;
Fcb->BigFile = TRUE;
}
else else
{ {
Fcb->Header.AllocationSize.QuadPart = 512; Fcb->Header.AllocationSize.QuadPart = 512;
@ -239,8 +249,13 @@ TestIrpHandler(
if (!FlagOn(Irp->Flags, IRP_NOCACHE)) if (!FlagOn(Irp->Flags, IRP_NOCACHE))
{ {
ok_irql(PASSIVE_LEVEL); ok_irql(PASSIVE_LEVEL);
ok(Offset.QuadPart % PAGE_SIZE != 0, "Offset is aligned: %I64i\n", Offset.QuadPart);
ok(Length % PAGE_SIZE != 0, "Length is aligned: %I64i\n", Length); /* We don't want to test alignement for big files (not the purpose of the test) */
if (!Fcb->BigFile)
{
ok(Offset.QuadPart % PAGE_SIZE != 0, "Offset is aligned: %I64i\n", Offset.QuadPart);
ok(Length % PAGE_SIZE != 0, "Length is aligned: %I64i\n", Length);
}
Buffer = Irp->AssociatedIrp.SystemBuffer; Buffer = Irp->AssociatedIrp.SystemBuffer;
ok(Buffer != NULL, "Null pointer!\n"); ok(Buffer != NULL, "Null pointer!\n");

View file

@ -18,6 +18,7 @@ START_TEST(CcCopyRead)
UNICODE_STRING BigAlignmentTest = RTL_CONSTANT_STRING(L"\\Device\\Kmtest-CcCopyRead\\BigAlignmentTest"); UNICODE_STRING BigAlignmentTest = RTL_CONSTANT_STRING(L"\\Device\\Kmtest-CcCopyRead\\BigAlignmentTest");
UNICODE_STRING SmallAlignmentTest = RTL_CONSTANT_STRING(L"\\Device\\Kmtest-CcCopyRead\\SmallAlignmentTest"); UNICODE_STRING SmallAlignmentTest = RTL_CONSTANT_STRING(L"\\Device\\Kmtest-CcCopyRead\\SmallAlignmentTest");
UNICODE_STRING ReallySmallAlignmentTest = RTL_CONSTANT_STRING(L"\\Device\\Kmtest-CcCopyRead\\ReallySmallAlignmentTest"); UNICODE_STRING ReallySmallAlignmentTest = RTL_CONSTANT_STRING(L"\\Device\\Kmtest-CcCopyRead\\ReallySmallAlignmentTest");
UNICODE_STRING FileBig = RTL_CONSTANT_STRING(L"\\Device\\Kmtest-CcCopyRead\\FileBig");
KmtLoadDriver(L"CcCopyRead", FALSE); KmtLoadDriver(L"CcCopyRead", FALSE);
KmtOpenDriver(); KmtOpenDriver();
@ -89,6 +90,17 @@ START_TEST(CcCopyRead)
NtClose(Handle); NtClose(Handle);
InitializeObjectAttributes(&ObjectAttributes, &FileBig, OBJ_CASE_INSENSITIVE, NULL, NULL);
Status = NtOpenFile(&Handle, FILE_ALL_ACCESS, &ObjectAttributes, &IoStatusBlock, 0, FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT);
ok_eq_hex(Status, STATUS_SUCCESS);
ByteOffset.QuadPart = 0;
Status = NtReadFile(Handle, NULL, NULL, NULL, &IoStatusBlock, Buffer, 1024, &ByteOffset, NULL);
ok_eq_hex(Status, STATUS_SUCCESS);
ok_eq_hex(((USHORT *)Buffer)[0], 0xBABA);
NtClose(Handle);
RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer); RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
KmtCloseDriver(); KmtCloseDriver();
KmtUnloadDriver(); KmtUnloadDriver();