[CLASSPNP]

- Make srb volatile, since it's assigned inside SEH and referenced in finally
[NTOSKRNL]
- FsRtlTeardownPerStreamContexts: make IsMutexLocked volatile (SEH)
- IoCreateFile: Make SystemEaBuffer volatile (SEH), save status and information in the caller's IoStatusBlock, cleanup and fail when IoCheckEaBufferValidity failed with PreviousMode == KernelMode, too.
- NtLockFile: Move ExAllocatePoolWithTag out of the SEH block. ExAllocatePoolWithTag does not raise an exception by default (unlike ExAllocatePoolWithQuotaTag). Get rid of this SEH block completely and check the return value instead.
- NtQueryDirectoryFile: make AuxBuffer volatile (SEH), again move ExAllocatePoolWithTag out of the SEH block and check return value instead.
IopCaptureUnicodeString: Make Name volatile (SEH)

svn path=/trunk/; revision=57437
This commit is contained in:
Timo Kreuzer 2012-09-29 22:44:48 +00:00
parent 1692f61539
commit db7101e3ed
5 changed files with 65 additions and 84 deletions

View file

@ -463,7 +463,7 @@ ClasspEjectionControl(
PFILE_OBJECT_EXTENSION fsContext = NULL; PFILE_OBJECT_EXTENSION fsContext = NULL;
NTSTATUS status; NTSTATUS status;
PSCSI_REQUEST_BLOCK srb = NULL; volatile PSCSI_REQUEST_BLOCK srb = NULL;
BOOLEAN countChanged = FALSE; BOOLEAN countChanged = FALSE;
PAGED_CODE(); PAGED_CODE();

View file

@ -368,7 +368,7 @@ NTAPI
FsRtlTeardownPerStreamContexts(IN PFSRTL_ADVANCED_FCB_HEADER AdvFcbHeader) FsRtlTeardownPerStreamContexts(IN PFSRTL_ADVANCED_FCB_HEADER AdvFcbHeader)
{ {
PLIST_ENTRY NextEntry; PLIST_ENTRY NextEntry;
BOOLEAN IsMutexLocked = FALSE; volatile BOOLEAN IsMutexLocked = FALSE;
PFSRTL_PER_STREAM_CONTEXT PerStreamContext; PFSRTL_PER_STREAM_CONTEXT PerStreamContext;
_SEH2_TRY _SEH2_TRY

View file

@ -1700,8 +1700,8 @@ IoCreateFile(OUT PHANDLE FileHandle,
KPROCESSOR_MODE AccessMode; KPROCESSOR_MODE AccessMode;
HANDLE LocalHandle = 0; HANDLE LocalHandle = 0;
LARGE_INTEGER SafeAllocationSize; LARGE_INTEGER SafeAllocationSize;
PVOID SystemEaBuffer = NULL; volatile PVOID SystemEaBuffer = NULL;
NTSTATUS Status; NTSTATUS Status = STATUS_SUCCESS;
OPEN_PACKET OpenPacket; OPEN_PACKET OpenPacket;
ULONG EaErrorOffset; ULONG EaErrorOffset;
@ -1738,9 +1738,7 @@ IoCreateFile(OUT PHANDLE FileHandle,
if ((EaBuffer) && (EaLength)) if ((EaBuffer) && (EaLength))
{ {
ProbeForRead(EaBuffer, ProbeForRead(EaBuffer, EaLength, sizeof(ULONG));
EaLength,
sizeof(ULONG));
/* marshal EaBuffer */ /* marshal EaBuffer */
SystemEaBuffer = ExAllocatePoolWithTag(NonPagedPool, SystemEaBuffer = ExAllocatePoolWithTag(NonPagedPool,
@ -1757,24 +1755,14 @@ IoCreateFile(OUT PHANDLE FileHandle,
Status = IoCheckEaBufferValidity(SystemEaBuffer, Status = IoCheckEaBufferValidity(SystemEaBuffer,
EaLength, EaLength,
&EaErrorOffset); &EaErrorOffset);
if (!NT_SUCCESS(Status)) IoStatusBlock->Status = Status;
{ IoStatusBlock->Information = EaErrorOffset;
DPRINT1("FIXME: IoCheckEaBufferValidity() failed with "
"Status: %lx\n",Status);
/* Free EA Buffer and return the error */
ExFreePoolWithTag(SystemEaBuffer, TAG_EA);
_SEH2_YIELD(return Status);
}
} }
} }
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{ {
/* Free SystemEaBuffer if needed */
if (SystemEaBuffer) ExFreePoolWithTag(SystemEaBuffer, TAG_EA);
/* Return the exception code */ /* Return the exception code */
_SEH2_YIELD(return _SEH2_GetExceptionCode()); Status = _SEH2_GetExceptionCode();
} }
_SEH2_END; _SEH2_END;
} }
@ -1816,12 +1804,19 @@ IoCreateFile(OUT PHANDLE FileHandle,
Status = IoCheckEaBufferValidity(SystemEaBuffer, Status = IoCheckEaBufferValidity(SystemEaBuffer,
EaLength, EaLength,
&EaErrorOffset); &EaErrorOffset);
IoStatusBlock->Status = Status;
IoStatusBlock->Information = EaErrorOffset;
}
}
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT1("FIXME: IoCheckEaBufferValidity() failed with " DPRINT1("FIXME: IoCheckEaBufferValidity() failed with Status: %lx\n",
"Status: %lx\n",Status); Status);
}
} /* Free SystemEaBuffer if needed and return the error */
if (SystemEaBuffer) ExFreePoolWithTag(SystemEaBuffer, TAG_EA);
return Status;
} }
/* Setup the Open Packet */ /* Setup the Open Packet */

View file

@ -1330,29 +1330,21 @@ NtLockFile(IN HANDLE FileHandle,
StackPtr->MinorFunction = IRP_MN_LOCK; StackPtr->MinorFunction = IRP_MN_LOCK;
StackPtr->FileObject = FileObject; StackPtr->FileObject = FileObject;
/* Enter SEH */
_SEH2_TRY
{
/* Allocate local buffer */ /* Allocate local buffer */
LocalLength = ExAllocatePoolWithTag(NonPagedPool, LocalLength = ExAllocatePoolWithTag(NonPagedPool,
sizeof(LARGE_INTEGER), sizeof(LARGE_INTEGER),
TAG_LOCK); TAG_LOCK);
if (!LocalLength)
{
/* Allocating failed, clean up and return failure */
IopCleanupAfterException(FileObject, Irp, Event, NULL);
return STATUS_INSUFFICIENT_RESOURCES;
}
/* Set the length */ /* Set the length */
*LocalLength = CapturedLength; *LocalLength = CapturedLength;
Irp->Tail.Overlay.AuxiliaryBuffer = (PVOID)LocalLength; Irp->Tail.Overlay.AuxiliaryBuffer = (PVOID)LocalLength;
StackPtr->Parameters.LockControl.Length = LocalLength; StackPtr->Parameters.LockControl.Length = LocalLength;
}
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
/* Allocating failed, clean up and return the exception code */
IopCleanupAfterException(FileObject, Irp, Event, NULL);
if (LocalLength) ExFreePoolWithTag(LocalLength, TAG_LOCK);
/* Return the exception code */
_SEH2_YIELD(return _SEH2_GetExceptionCode());
}
_SEH2_END;
/* Set Parameters */ /* Set Parameters */
StackPtr->Parameters.LockControl.ByteOffset = CapturedByteOffset; StackPtr->Parameters.LockControl.ByteOffset = CapturedByteOffset;
@ -1397,7 +1389,7 @@ NtQueryDirectoryFile(IN HANDLE FileHandle,
NTSTATUS Status; NTSTATUS Status;
BOOLEAN LockedForSynch = FALSE; BOOLEAN LockedForSynch = FALSE;
PKEVENT Event = NULL; PKEVENT Event = NULL;
PVOID AuxBuffer = NULL; volatile PVOID AuxBuffer = NULL;
PMDL Mdl; PMDL Mdl;
UNICODE_STRING CapturedFileName; UNICODE_STRING CapturedFileName;
PUNICODE_STRING SearchPattern; PUNICODE_STRING SearchPattern;
@ -1525,26 +1517,20 @@ 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)
{
/* Enter SEH */
_SEH2_TRY
{ {
/* Allocate a buffer */ /* Allocate a buffer */
Irp->AssociatedIrp.SystemBuffer = Irp->AssociatedIrp.SystemBuffer = ExAllocatePoolWithTag(NonPagedPool,
ExAllocatePoolWithTag(NonPagedPool,
Length, Length,
TAG_SYSB); TAG_SYSB);
} if (!Irp->AssociatedIrp.SystemBuffer)
_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 */
_SEH2_YIELD(return _SEH2_GetExceptionCode()); return STATUS_INSUFFICIENT_RESOURCES;
} }
_SEH2_END;
/* Set the buffer and flags */ /* Set the buffer and flags */
Irp->UserBuffer = FileInformation; Irp->UserBuffer = FileInformation;

View file

@ -167,7 +167,7 @@ static NTSTATUS
IopCaptureUnicodeString(PUNICODE_STRING DstName, PUNICODE_STRING SrcName) IopCaptureUnicodeString(PUNICODE_STRING DstName, PUNICODE_STRING SrcName)
{ {
NTSTATUS Status = STATUS_SUCCESS; NTSTATUS Status = STATUS_SUCCESS;
UNICODE_STRING Name; volatile UNICODE_STRING Name;
Name.Buffer = NULL; Name.Buffer = NULL;
_SEH2_TRY _SEH2_TRY