[NTOS:IO] Fix broken pool allocations

ExAllocatePoolWithTag doesn't raise an exception on failure, only ExAllocatePoolWithQuotaTag does. Use that when quotas are relevant instead of silently continuing with a NULL pointer.
This commit is contained in:
Timo Kreuzer 2024-04-22 11:50:59 +03:00
parent 24a56f89ab
commit c9864da823

View file

@ -2176,19 +2176,23 @@ NtQueryDirectoryFile(IN HANDLE FileHandle,
/* Check if this is buffered I/O */ /* Check if this is buffered I/O */
if (DeviceObject->Flags & DO_BUFFERED_IO) if (DeviceObject->Flags & DO_BUFFERED_IO)
{ {
/* Allocate a buffer */ /* Enter SEH (ExAllocatePoolWithQuotaTag raises on failure!) */
Irp->AssociatedIrp.SystemBuffer = ExAllocatePoolWithTag(NonPagedPool, _SEH2_TRY
Length, {
TAG_SYSB); /* Allocate a buffer */
if (!Irp->AssociatedIrp.SystemBuffer) Irp->AssociatedIrp.SystemBuffer =
ExAllocatePoolWithQuotaTag(NonPagedPool, Length, TAG_SYSB);
}
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{ {
/* Allocating failed, clean up and return the exception code */ /* Allocating failed, clean up and return the exception code */
IopCleanupAfterException(FileObject, Irp, Event, NULL); IopCleanupAfterException(FileObject, Irp, Event, NULL);
if (AuxBuffer) ExFreePoolWithTag(AuxBuffer, TAG_SYSB); if (AuxBuffer) ExFreePoolWithTag(AuxBuffer, TAG_SYSB);
/* Return the exception code */ /* Return the exception code */
return STATUS_INSUFFICIENT_RESOURCES; return _SEH2_GetExceptionCode();
} }
_SEH2_END;
/* Set the buffer and flags */ /* Set the buffer and flags */
Irp->UserBuffer = FileInformation; Irp->UserBuffer = FileInformation;
@ -2508,14 +2512,12 @@ NtQueryInformationFile(IN HANDLE FileHandle,
StackPtr->MajorFunction = IRP_MJ_QUERY_INFORMATION; StackPtr->MajorFunction = IRP_MJ_QUERY_INFORMATION;
StackPtr->FileObject = FileObject; StackPtr->FileObject = FileObject;
/* Enter SEH */ /* Enter SEH (ExAllocatePoolWithQuotaTag raises on failure!) */
_SEH2_TRY _SEH2_TRY
{ {
/* Allocate a buffer */ /* Allocate a buffer */
Irp->AssociatedIrp.SystemBuffer = Irp->AssociatedIrp.SystemBuffer =
ExAllocatePoolWithTag(NonPagedPool, ExAllocatePoolWithQuotaTag(NonPagedPool, Length, TAG_SYSB);
Length,
TAG_SYSB);
} }
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{ {
@ -2978,14 +2980,12 @@ NtReadFile(IN HANDLE FileHandle,
/* Check if we have a buffer length */ /* Check if we have a buffer length */
if (Length) if (Length)
{ {
/* Enter SEH */ /* Enter SEH (ExAllocatePoolWithQuotaTag raises on failure!) */
_SEH2_TRY _SEH2_TRY
{ {
/* Allocate a buffer */ /* Allocate a buffer */
Irp->AssociatedIrp.SystemBuffer = Irp->AssociatedIrp.SystemBuffer =
ExAllocatePoolWithTag(NonPagedPool, ExAllocatePoolWithQuotaTag(NonPagedPool, Length, TAG_SYSB);
Length,
TAG_SYSB);
} }
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{ {
@ -3281,14 +3281,12 @@ NtSetInformationFile(IN HANDLE FileHandle,
StackPtr->MajorFunction = IRP_MJ_SET_INFORMATION; StackPtr->MajorFunction = IRP_MJ_SET_INFORMATION;
StackPtr->FileObject = FileObject; StackPtr->FileObject = FileObject;
/* Enter SEH */ /* Enter SEH (ExAllocatePoolWithQuotaTag raises on failure!) */
_SEH2_TRY _SEH2_TRY
{ {
/* Allocate a buffer */ /* Allocate a buffer */
Irp->AssociatedIrp.SystemBuffer = Irp->AssociatedIrp.SystemBuffer =
ExAllocatePoolWithTag(NonPagedPool, ExAllocatePoolWithQuotaTag(NonPagedPool, Length, TAG_SYSB);
Length,
TAG_SYSB);
/* Copy the data into it */ /* Copy the data into it */
RtlCopyMemory(Irp->AssociatedIrp.SystemBuffer, RtlCopyMemory(Irp->AssociatedIrp.SystemBuffer,
@ -3704,13 +3702,13 @@ NtUnlockFile(IN HANDLE FileHandle,
StackPtr->MinorFunction = IRP_MN_UNLOCK_SINGLE; StackPtr->MinorFunction = IRP_MN_UNLOCK_SINGLE;
StackPtr->FileObject = FileObject; StackPtr->FileObject = FileObject;
/* Enter SEH */ /* Enter SEH (ExAllocatePoolWithQuotaTag raises on failure!) */
_SEH2_TRY _SEH2_TRY
{ {
/* Allocate a buffer */ /* Allocate a buffer */
LocalLength = ExAllocatePoolWithTag(NonPagedPool, LocalLength = ExAllocatePoolWithQuotaTag(NonPagedPool,
sizeof(LARGE_INTEGER), sizeof(LARGE_INTEGER),
TAG_LOCK); TAG_LOCK);
/* Set the length */ /* Set the length */
*LocalLength = CapturedLength; *LocalLength = CapturedLength;
@ -4055,14 +4053,12 @@ NtWriteFile(IN HANDLE FileHandle,
/* Check if we have a buffer length */ /* Check if we have a buffer length */
if (Length) if (Length)
{ {
/* Enter SEH */ /* Enter SEH (ExAllocatePoolWithQuotaTag raises on failure!) */
_SEH2_TRY _SEH2_TRY
{ {
/* Allocate a buffer */ /* Allocate a buffer */
Irp->AssociatedIrp.SystemBuffer = Irp->AssociatedIrp.SystemBuffer =
ExAllocatePoolWithTag(NonPagedPool, ExAllocatePoolWithQuotaTag(NonPagedPool, Length, TAG_SYSB);
Length,
TAG_SYSB);
/* Copy the data into it */ /* Copy the data into it */
RtlCopyMemory(Irp->AssociatedIrp.SystemBuffer, Buffer, Length); RtlCopyMemory(Irp->AssociatedIrp.SystemBuffer, Buffer, Length);
@ -4293,6 +4289,7 @@ NtQueryVolumeInformationFile(IN HANDLE FileHandle,
{ {
_SEH2_VOLATILE PFILE_FS_DRIVER_PATH_INFORMATION DriverPathInfo = NULL; _SEH2_VOLATILE PFILE_FS_DRIVER_PATH_INFORMATION DriverPathInfo = NULL;
/* Enter SEH (ExAllocatePoolWithQuotaTag raises on failure!) */
_SEH2_TRY _SEH2_TRY
{ {
/* Allocate our local structure */ /* Allocate our local structure */
@ -4383,14 +4380,12 @@ NtQueryVolumeInformationFile(IN HANDLE FileHandle,
StackPtr->MajorFunction = IRP_MJ_QUERY_VOLUME_INFORMATION; StackPtr->MajorFunction = IRP_MJ_QUERY_VOLUME_INFORMATION;
StackPtr->FileObject = FileObject; StackPtr->FileObject = FileObject;
/* Enter SEH */ /* Enter SEH (ExAllocatePoolWithQuotaTag raises on failure!) */
_SEH2_TRY _SEH2_TRY
{ {
/* Allocate a buffer */ /* Allocate a buffer */
Irp->AssociatedIrp.SystemBuffer = Irp->AssociatedIrp.SystemBuffer =
ExAllocatePoolWithTag(NonPagedPool, ExAllocatePoolWithQuotaTag(NonPagedPool, Length, TAG_SYSB);
Length,
TAG_SYSB);
} }
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{ {
@ -4566,14 +4561,12 @@ NtSetVolumeInformationFile(IN HANDLE FileHandle,
StackPtr->MajorFunction = IRP_MJ_SET_VOLUME_INFORMATION; StackPtr->MajorFunction = IRP_MJ_SET_VOLUME_INFORMATION;
StackPtr->FileObject = FileObject; StackPtr->FileObject = FileObject;
/* Enter SEH */ /* Enter SEH (ExAllocatePoolWithQuotaTag raises on failure!) */
_SEH2_TRY _SEH2_TRY
{ {
/* Allocate a buffer */ /* Allocate a buffer */
Irp->AssociatedIrp.SystemBuffer = Irp->AssociatedIrp.SystemBuffer =
ExAllocatePoolWithTag(NonPagedPool, ExAllocatePoolWithQuotaTag(NonPagedPool, Length, TAG_SYSB);
Length,
TAG_SYSB);
/* Copy the data into it */ /* Copy the data into it */
RtlCopyMemory(Irp->AssociatedIrp.SystemBuffer, FsInformation, Length); RtlCopyMemory(Irp->AssociatedIrp.SystemBuffer, FsInformation, Length);