2006-11-08 19:47:44 +08:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS Kernel
|
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
2015-05-19 03:47:11 +08:00
|
|
|
* FILE: ntoskrnl/io/iomgr/iofunc.c
|
2006-11-08 19:47:44 +08:00
|
|
|
* PURPOSE: Generic I/O Functions that build IRPs for various operations
|
|
|
|
* PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
|
|
|
|
* Gunnar Dalsnes
|
|
|
|
* Filip Navara (navaraf@reactos.org)
|
2015-05-19 03:47:11 +08:00
|
|
|
* Pierre Schweitzer (pierre@reactos.org)
|
2006-11-08 19:47:44 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES *****************************************************************/
|
|
|
|
|
|
|
|
#include <ntoskrnl.h>
|
2010-08-18 00:04:46 +08:00
|
|
|
#include <ioevent.h>
|
2006-11-08 19:47:44 +08:00
|
|
|
#define NDEBUG
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
#include <debug.h>
|
2006-12-11 06:26:01 +08:00
|
|
|
#include "internal/io_i.h"
|
2006-11-08 19:47:44 +08:00
|
|
|
|
2018-02-24 21:50:23 +08:00
|
|
|
volatile LONG IoPageReadIrpAllocationFailure = 0;
|
|
|
|
volatile LONG IoPageReadNonPagefileIrpAllocationFailure = 0;
|
|
|
|
|
2006-11-08 19:47:44 +08:00
|
|
|
/* PRIVATE FUNCTIONS *********************************************************/
|
|
|
|
|
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
IopCleanupAfterException(IN PFILE_OBJECT FileObject,
|
2016-09-03 23:49:55 +08:00
|
|
|
IN PIRP Irp OPTIONAL,
|
2006-11-08 19:47:44 +08:00
|
|
|
IN PKEVENT Event OPTIONAL,
|
|
|
|
IN PKEVENT LocalEvent OPTIONAL)
|
|
|
|
{
|
|
|
|
PAGED_CODE();
|
2021-09-13 01:49:54 +08:00
|
|
|
IOTRACE(IO_API_DEBUG, "IRP: %p. FO: %p\n", Irp, FileObject);
|
2006-11-08 19:47:44 +08:00
|
|
|
|
2016-09-03 23:49:55 +08:00
|
|
|
if (Irp)
|
2006-11-08 19:47:44 +08:00
|
|
|
{
|
2016-09-03 23:49:55 +08:00
|
|
|
/* Check if we had a buffer */
|
|
|
|
if (Irp->AssociatedIrp.SystemBuffer)
|
|
|
|
{
|
|
|
|
/* Free it */
|
|
|
|
ExFreePool(Irp->AssociatedIrp.SystemBuffer);
|
|
|
|
}
|
2006-11-08 19:47:44 +08:00
|
|
|
|
2016-09-03 23:49:55 +08:00
|
|
|
/* Free the mdl */
|
|
|
|
if (Irp->MdlAddress) IoFreeMdl(Irp->MdlAddress);
|
2006-11-08 19:47:44 +08:00
|
|
|
|
2016-09-03 23:49:55 +08:00
|
|
|
/* Free the IRP */
|
|
|
|
IoFreeIrp(Irp);
|
|
|
|
}
|
2006-11-08 19:47:44 +08:00
|
|
|
|
|
|
|
/* Check if we had a file lock */
|
|
|
|
if (FileObject->Flags & FO_SYNCHRONOUS_IO)
|
|
|
|
{
|
|
|
|
/* Release it */
|
|
|
|
IopUnlockFileObject(FileObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if we had an event */
|
|
|
|
if (Event) ObDereferenceObject(Event);
|
|
|
|
|
|
|
|
/* Check if we had a local event */
|
|
|
|
if (LocalEvent) ExFreePool(LocalEvent);
|
|
|
|
|
|
|
|
/* Derefenrce the FO */
|
|
|
|
ObDereferenceObject(FileObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
IopFinalizeAsynchronousIo(IN NTSTATUS SynchStatus,
|
|
|
|
IN PKEVENT Event,
|
|
|
|
IN PIRP Irp,
|
|
|
|
IN KPROCESSOR_MODE PreviousMode,
|
|
|
|
IN PIO_STATUS_BLOCK KernelIosb,
|
|
|
|
OUT PIO_STATUS_BLOCK IoStatusBlock)
|
|
|
|
{
|
|
|
|
NTSTATUS FinalStatus = SynchStatus;
|
|
|
|
PAGED_CODE();
|
2021-09-13 01:49:54 +08:00
|
|
|
IOTRACE(IO_API_DEBUG, "IRP: %p. Status: %lx\n", Irp, SynchStatus);
|
2006-11-08 19:47:44 +08:00
|
|
|
|
|
|
|
/* Make sure the IRP was completed, but returned pending */
|
|
|
|
if (FinalStatus == STATUS_PENDING)
|
|
|
|
{
|
|
|
|
/* Wait for the IRP */
|
|
|
|
FinalStatus = KeWaitForSingleObject(Event,
|
|
|
|
Executive,
|
|
|
|
PreviousMode,
|
|
|
|
FALSE,
|
|
|
|
NULL);
|
|
|
|
if (FinalStatus == STATUS_USER_APC)
|
|
|
|
{
|
|
|
|
/* Abort the request */
|
|
|
|
IopAbortInterruptedIrp(Event, Irp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the final status */
|
|
|
|
FinalStatus = KernelIosb->Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Wrap potential user-mode write in SEH */
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_TRY
|
2006-11-08 19:47:44 +08:00
|
|
|
{
|
|
|
|
*IoStatusBlock = *KernelIosb;
|
|
|
|
}
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
2006-11-08 19:47:44 +08:00
|
|
|
{
|
|
|
|
/* Get the exception code */
|
2008-11-24 21:40:26 +08:00
|
|
|
FinalStatus = _SEH2_GetExceptionCode();
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_END;
|
2006-11-08 19:47:44 +08:00
|
|
|
|
|
|
|
/* Free the event and return status */
|
|
|
|
ExFreePool(Event);
|
|
|
|
return FinalStatus;
|
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
IopPerformSynchronousRequest(IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp,
|
|
|
|
IN PFILE_OBJECT FileObject,
|
|
|
|
IN BOOLEAN Deferred,
|
|
|
|
IN KPROCESSOR_MODE PreviousMode,
|
|
|
|
IN BOOLEAN SynchIo,
|
|
|
|
IN IOP_TRANSFER_TYPE TransferType)
|
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
|
|
|
PKNORMAL_ROUTINE NormalRoutine;
|
[NTOSKRNL]
Coverity code defects fixes :
- Cache: CID 701441
- Config: CIDs 716570, 716669, 716760
- Dbgk: Kdbg: CIDs 716571, 515128/9, 500432
- Ex: CIDs 500156/7, 515122, 716200/67, 701301, 514669
- Fsrtl: Fstub: CIDs 701341/2, 701288, 716770, 701302, and CIDs 716576/7/8 + 514636 + 716805 thanks to Thomas Faber
- Io: CIDs 514576, 514643, 514672/3, 716203, 716269, 716581, 716591, 716713
- Ke: CIDs 515125, 716592
- Ps: CIDs 716603/4, 701422
- Ob: Po: CIDs 514671/680, 701419/420/421, 716763, 716601/2
All the details are given in the different bug reports.
CORE-6677 CORE-6679 CORE-6680 CORE-6683 CORE-6686 CORE-6692 CORE-6693 CORE-6694 CORE-6695 CORE-6696 #comment Committed in rev.57400 #resolve #close
svn path=/trunk/; revision=57400
2012-09-28 01:16:31 +08:00
|
|
|
PVOID NormalContext = NULL;
|
2006-11-08 19:47:44 +08:00
|
|
|
KIRQL OldIrql;
|
|
|
|
PAGED_CODE();
|
2021-09-13 01:49:54 +08:00
|
|
|
IOTRACE(IO_API_DEBUG, "IRP: %p. DO: %p. FO: %p\n",
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
Irp, DeviceObject, FileObject);
|
2006-11-08 19:47:44 +08:00
|
|
|
|
|
|
|
/* Queue the IRP */
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
IopQueueIrpToThread(Irp);
|
2006-11-08 19:47:44 +08:00
|
|
|
|
|
|
|
/* Update operation counts */
|
|
|
|
IopUpdateOperationCount(TransferType);
|
|
|
|
|
|
|
|
/* Call the driver */
|
|
|
|
Status = IoCallDriver(DeviceObject, Irp);
|
|
|
|
|
|
|
|
/* Check if we're optimizing this case */
|
|
|
|
if (Deferred)
|
|
|
|
{
|
|
|
|
/* We are! Check if the IRP wasn't completed */
|
|
|
|
if (Status != STATUS_PENDING)
|
|
|
|
{
|
|
|
|
/* Complete it ourselves */
|
2021-10-28 23:17:03 +08:00
|
|
|
NormalRoutine = NULL;
|
|
|
|
NormalContext = NULL;
|
2006-11-08 19:47:44 +08:00
|
|
|
ASSERT(!Irp->PendingReturned);
|
|
|
|
KeRaiseIrql(APC_LEVEL, &OldIrql);
|
|
|
|
IopCompleteRequest(&Irp->Tail.Apc,
|
|
|
|
&NormalRoutine,
|
|
|
|
&NormalContext,
|
|
|
|
(PVOID*)&FileObject,
|
|
|
|
&NormalContext);
|
|
|
|
KeLowerIrql(OldIrql);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if this was synch I/O */
|
|
|
|
if (SynchIo)
|
|
|
|
{
|
|
|
|
/* Make sure the IRP was completed, but returned pending */
|
|
|
|
if (Status == STATUS_PENDING)
|
|
|
|
{
|
|
|
|
/* Wait for the IRP */
|
|
|
|
Status = KeWaitForSingleObject(&FileObject->Event,
|
|
|
|
Executive,
|
|
|
|
PreviousMode,
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
(FileObject->Flags &
|
2012-07-24 23:32:06 +08:00
|
|
|
FO_ALERTABLE_IO) != 0,
|
2006-11-08 19:47:44 +08:00
|
|
|
NULL);
|
|
|
|
if ((Status == STATUS_ALERTED) || (Status == STATUS_USER_APC))
|
|
|
|
{
|
|
|
|
/* Abort the request */
|
|
|
|
IopAbortInterruptedIrp(&FileObject->Event, Irp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the final status */
|
|
|
|
Status = FileObject->FinalStatus;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Release the file lock */
|
|
|
|
IopUnlockFileObject(FileObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return status */
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
IopDeviceFsIoControl(IN HANDLE DeviceHandle,
|
|
|
|
IN HANDLE Event OPTIONAL,
|
|
|
|
IN PIO_APC_ROUTINE UserApcRoutine OPTIONAL,
|
|
|
|
IN PVOID UserApcContext OPTIONAL,
|
|
|
|
OUT PIO_STATUS_BLOCK IoStatusBlock,
|
|
|
|
IN ULONG IoControlCode,
|
|
|
|
IN PVOID InputBuffer,
|
|
|
|
IN ULONG InputBufferLength OPTIONAL,
|
|
|
|
OUT PVOID OutputBuffer,
|
|
|
|
IN ULONG OutputBufferLength OPTIONAL,
|
|
|
|
IN BOOLEAN IsDevIoCtl)
|
|
|
|
{
|
2009-08-27 01:31:02 +08:00
|
|
|
NTSTATUS Status;
|
2006-11-08 19:47:44 +08:00
|
|
|
PFILE_OBJECT FileObject;
|
2007-04-02 23:08:54 +08:00
|
|
|
PDEVICE_OBJECT DeviceObject;
|
|
|
|
PIRP Irp;
|
2006-11-08 19:47:44 +08:00
|
|
|
PIO_STACK_LOCATION StackPtr;
|
|
|
|
PKEVENT EventObject = NULL;
|
|
|
|
BOOLEAN LockedForSynch = FALSE;
|
2007-04-02 23:08:54 +08:00
|
|
|
ULONG AccessType;
|
2006-11-08 19:47:44 +08:00
|
|
|
OBJECT_HANDLE_INFORMATION HandleInformation;
|
|
|
|
ACCESS_MASK DesiredAccess;
|
|
|
|
KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
ULONG BufferLength;
|
2017-11-26 20:56:48 +08:00
|
|
|
POOL_TYPE PoolType;
|
2016-09-03 23:02:57 +08:00
|
|
|
|
|
|
|
PAGED_CODE();
|
|
|
|
|
2021-09-13 01:49:54 +08:00
|
|
|
IOTRACE(IO_CTL_DEBUG, "Handle: %p. CTL: %lx. Type: %lx\n",
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
DeviceHandle, IoControlCode, IsDevIoCtl);
|
2006-11-08 19:47:44 +08:00
|
|
|
|
|
|
|
/* Get the access type */
|
|
|
|
AccessType = IO_METHOD_FROM_CTL_CODE(IoControlCode);
|
|
|
|
|
|
|
|
/* Check if we came from user mode */
|
|
|
|
if (PreviousMode != KernelMode)
|
|
|
|
{
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_TRY
|
2006-11-08 19:47:44 +08:00
|
|
|
{
|
|
|
|
/* Probe the status block */
|
|
|
|
ProbeForWriteIoStatusBlock(IoStatusBlock);
|
|
|
|
|
|
|
|
/* Check if this is buffered I/O */
|
|
|
|
if (AccessType == METHOD_BUFFERED)
|
|
|
|
{
|
|
|
|
/* Check if we have an output buffer */
|
|
|
|
if (OutputBuffer)
|
|
|
|
{
|
|
|
|
/* Probe the output buffer */
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
ProbeForWrite(OutputBuffer,
|
|
|
|
OutputBufferLength,
|
|
|
|
sizeof(CHAR));
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Make sure the caller can't fake this as we depend on this */
|
|
|
|
OutputBufferLength = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if we we have an input buffer I/O */
|
|
|
|
if (AccessType != METHOD_NEITHER)
|
|
|
|
{
|
|
|
|
/* Check if we have an input buffer */
|
|
|
|
if (InputBuffer)
|
|
|
|
{
|
|
|
|
/* Probe the input buffer */
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
ProbeForRead(InputBuffer, InputBufferLength, sizeof(CHAR));
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Make sure the caller can't fake this as we depend on this */
|
|
|
|
InputBufferLength = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
2006-11-08 19:47:44 +08:00
|
|
|
{
|
2009-08-27 01:31:02 +08:00
|
|
|
/* Return the exception code */
|
|
|
|
_SEH2_YIELD(return _SEH2_GetExceptionCode());
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_END;
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Don't check for access rights right now, KernelMode can do anything */
|
|
|
|
Status = ObReferenceObjectByHandle(DeviceHandle,
|
|
|
|
0,
|
|
|
|
IoFileObjectType,
|
|
|
|
PreviousMode,
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
(PVOID*)&FileObject,
|
2006-11-08 19:47:44 +08:00
|
|
|
&HandleInformation);
|
|
|
|
if (!NT_SUCCESS(Status)) return Status;
|
|
|
|
|
2021-11-24 20:34:26 +08:00
|
|
|
/* Can't use an I/O completion port and an APC at the same time */
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
if ((FileObject->CompletionContext) && (UserApcRoutine))
|
|
|
|
{
|
|
|
|
/* Fail */
|
|
|
|
ObDereferenceObject(FileObject);
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
2006-11-08 19:47:44 +08:00
|
|
|
/* Check if we from user mode */
|
|
|
|
if (PreviousMode != KernelMode)
|
|
|
|
{
|
|
|
|
/* Get the access mask */
|
|
|
|
DesiredAccess = (ACCESS_MASK)((IoControlCode >> 14) & 3);
|
|
|
|
|
|
|
|
/* Check if we can open it */
|
|
|
|
if ((DesiredAccess != FILE_ANY_ACCESS) &&
|
|
|
|
(HandleInformation.GrantedAccess & DesiredAccess) != DesiredAccess)
|
|
|
|
{
|
|
|
|
/* Dereference the file object and fail */
|
|
|
|
ObDereferenceObject(FileObject);
|
|
|
|
return STATUS_ACCESS_DENIED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for an event */
|
|
|
|
if (Event)
|
|
|
|
{
|
|
|
|
/* Reference it */
|
|
|
|
Status = ObReferenceObjectByHandle(Event,
|
|
|
|
EVENT_MODIFY_STATE,
|
|
|
|
ExEventObjectType,
|
|
|
|
PreviousMode,
|
|
|
|
(PVOID*)&EventObject,
|
|
|
|
NULL);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* Dereference the file object and fail */
|
|
|
|
ObDereferenceObject(FileObject);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear it */
|
|
|
|
KeClearEvent(EventObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if this is a file that was opened for Synch I/O */
|
|
|
|
if (FileObject->Flags & FO_SYNCHRONOUS_IO)
|
|
|
|
{
|
|
|
|
/* Lock it */
|
2018-10-02 15:55:07 +08:00
|
|
|
Status = IopLockFileObject(FileObject, PreviousMode);
|
|
|
|
if (Status != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
if (EventObject) ObDereferenceObject(EventObject);
|
|
|
|
ObDereferenceObject(FileObject);
|
|
|
|
return Status;
|
|
|
|
}
|
2006-11-08 19:47:44 +08:00
|
|
|
|
|
|
|
/* Remember to unlock later */
|
|
|
|
LockedForSynch = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if this is a direct open or not */
|
|
|
|
if (FileObject->Flags & FO_DIRECT_DEVICE_OPEN)
|
|
|
|
{
|
|
|
|
/* It's a direct open, get the attached device */
|
|
|
|
DeviceObject = IoGetAttachedDevice(FileObject->DeviceObject);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Otherwise get the related device */
|
|
|
|
DeviceObject = IoGetRelatedDeviceObject(FileObject);
|
|
|
|
}
|
|
|
|
|
2016-09-04 03:10:09 +08:00
|
|
|
/* If this is a device I/O, try to do it with FastIO path */
|
2016-09-03 23:02:57 +08:00
|
|
|
if (IsDevIoCtl)
|
2015-05-19 03:47:11 +08:00
|
|
|
{
|
|
|
|
PFAST_IO_DISPATCH FastIoDispatch = DeviceObject->DriverObject->FastIoDispatch;
|
|
|
|
|
|
|
|
/* Check whether FSD is FastIO aware and provide an appropriate routine */
|
|
|
|
if (FastIoDispatch != NULL && FastIoDispatch->FastIoDeviceControl != NULL)
|
|
|
|
{
|
|
|
|
IO_STATUS_BLOCK KernelIosb;
|
|
|
|
|
|
|
|
/* If we have an output buffer coming from usermode */
|
|
|
|
if (PreviousMode != KernelMode && OutputBuffer != NULL)
|
|
|
|
{
|
|
|
|
/* Probe it according to its usage */
|
|
|
|
_SEH2_TRY
|
|
|
|
{
|
|
|
|
if (AccessType == METHOD_IN_DIRECT)
|
|
|
|
{
|
|
|
|
ProbeForRead(OutputBuffer, OutputBufferLength, sizeof(CHAR));
|
|
|
|
}
|
|
|
|
else if (AccessType == METHOD_OUT_DIRECT)
|
|
|
|
{
|
|
|
|
ProbeForWrite(OutputBuffer, OutputBufferLength, sizeof(CHAR));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
|
|
|
/* Cleanup after exception and return */
|
|
|
|
IopCleanupAfterException(FileObject, NULL, EventObject, NULL);
|
|
|
|
|
|
|
|
/* Return the exception code */
|
|
|
|
_SEH2_YIELD(return _SEH2_GetExceptionCode());
|
|
|
|
}
|
|
|
|
_SEH2_END;
|
|
|
|
}
|
|
|
|
|
2016-09-04 14:20:53 +08:00
|
|
|
/* If we are dismounting a volume, increase the dismount count */
|
2015-05-19 03:47:11 +08:00
|
|
|
if (IoControlCode == FSCTL_DISMOUNT_VOLUME)
|
|
|
|
{
|
2016-09-04 06:07:53 +08:00
|
|
|
InterlockedIncrement((PLONG)&SharedUserData->DismountCount);
|
2015-05-19 03:47:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Call the FSD */
|
|
|
|
if (FastIoDispatch->FastIoDeviceControl(FileObject,
|
|
|
|
TRUE,
|
|
|
|
InputBuffer,
|
|
|
|
InputBufferLength,
|
|
|
|
OutputBuffer,
|
|
|
|
OutputBufferLength,
|
|
|
|
IoControlCode,
|
|
|
|
&KernelIosb,
|
|
|
|
DeviceObject))
|
|
|
|
{
|
|
|
|
IO_COMPLETION_CONTEXT CompletionInfo = { NULL, NULL };
|
|
|
|
|
|
|
|
/* Write the IOSB back */
|
|
|
|
_SEH2_TRY
|
|
|
|
{
|
|
|
|
*IoStatusBlock = KernelIosb;
|
|
|
|
|
|
|
|
}
|
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
|
|
|
KernelIosb.Status = _SEH2_GetExceptionCode();
|
|
|
|
}
|
|
|
|
_SEH2_END;
|
|
|
|
|
|
|
|
/* Backup our complete context in case it exists */
|
|
|
|
if (FileObject->CompletionContext)
|
|
|
|
{
|
2016-09-04 06:07:53 +08:00
|
|
|
CompletionInfo = *(FileObject->CompletionContext);
|
2015-05-19 03:47:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If we had an event, signal it */
|
|
|
|
if (Event)
|
|
|
|
{
|
|
|
|
KeSetEvent(EventObject, IO_NO_INCREMENT, FALSE);
|
|
|
|
ObDereferenceObject(EventObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If FO was locked, unlock it */
|
|
|
|
if (LockedForSynch)
|
|
|
|
{
|
|
|
|
IopUnlockFileObject(FileObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set completion if required */
|
|
|
|
if (CompletionInfo.Port != NULL && UserApcContext != NULL)
|
|
|
|
{
|
|
|
|
if (!NT_SUCCESS(IoSetIoCompletion(CompletionInfo.Port,
|
|
|
|
CompletionInfo.Key,
|
|
|
|
UserApcContext,
|
|
|
|
KernelIosb.Status,
|
|
|
|
KernelIosb.Information,
|
|
|
|
TRUE)))
|
|
|
|
{
|
|
|
|
KernelIosb.Status = STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We're done with FastIO! */
|
|
|
|
ObDereferenceObject(FileObject);
|
|
|
|
return KernelIosb.Status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-08 19:47:44 +08:00
|
|
|
/* Clear the event */
|
|
|
|
KeClearEvent(&FileObject->Event);
|
|
|
|
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
/* Allocate IRP */
|
|
|
|
Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
|
2015-05-01 20:00:50 +08:00
|
|
|
if (!Irp) return IopCleanupFailedIrp(FileObject, EventObject, NULL);
|
2006-11-08 19:47:44 +08:00
|
|
|
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
/* Setup the IRP */
|
|
|
|
Irp->UserIosb = IoStatusBlock;
|
|
|
|
Irp->UserEvent = EventObject;
|
2006-11-08 19:47:44 +08:00
|
|
|
Irp->Overlay.AsynchronousParameters.UserApcRoutine = UserApcRoutine;
|
|
|
|
Irp->Overlay.AsynchronousParameters.UserApcContext = UserApcContext;
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
Irp->Cancel = FALSE;
|
|
|
|
Irp->CancelRoutine = NULL;
|
|
|
|
Irp->PendingReturned = FALSE;
|
|
|
|
Irp->RequestorMode = PreviousMode;
|
|
|
|
Irp->MdlAddress = NULL;
|
|
|
|
Irp->AssociatedIrp.SystemBuffer = NULL;
|
|
|
|
Irp->Flags = 0;
|
|
|
|
Irp->Tail.Overlay.AuxiliaryBuffer = NULL;
|
|
|
|
Irp->Tail.Overlay.OriginalFileObject = FileObject;
|
|
|
|
Irp->Tail.Overlay.Thread = PsGetCurrentThread();
|
|
|
|
|
|
|
|
/* Set stack location settings */
|
2006-11-08 19:47:44 +08:00
|
|
|
StackPtr = IoGetNextIrpStackLocation(Irp);
|
|
|
|
StackPtr->FileObject = FileObject;
|
|
|
|
StackPtr->MajorFunction = IsDevIoCtl ?
|
|
|
|
IRP_MJ_DEVICE_CONTROL :
|
|
|
|
IRP_MJ_FILE_SYSTEM_CONTROL;
|
2011-06-17 09:07:26 +08:00
|
|
|
StackPtr->MinorFunction = 0; /* Minor function 0 is IRP_MN_USER_FS_REQUEST */
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
StackPtr->Control = 0;
|
|
|
|
StackPtr->Flags = 0;
|
|
|
|
StackPtr->Parameters.DeviceIoControl.Type3InputBuffer = NULL;
|
|
|
|
|
|
|
|
/* Set the IOCTL Data */
|
|
|
|
StackPtr->Parameters.DeviceIoControl.IoControlCode = IoControlCode;
|
|
|
|
StackPtr->Parameters.DeviceIoControl.InputBufferLength = InputBufferLength;
|
|
|
|
StackPtr->Parameters.DeviceIoControl.OutputBufferLength =
|
|
|
|
OutputBufferLength;
|
|
|
|
|
2017-11-26 20:56:48 +08:00
|
|
|
PoolType = IsDevIoCtl ? NonPagedPoolCacheAligned : NonPagedPool;
|
|
|
|
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
/* Handle the Methods */
|
|
|
|
switch (AccessType)
|
|
|
|
{
|
|
|
|
/* Buffered I/O */
|
|
|
|
case METHOD_BUFFERED:
|
|
|
|
|
|
|
|
/* Enter SEH for allocations */
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_TRY
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
{
|
|
|
|
/* Select the right Buffer Length */
|
|
|
|
BufferLength = (InputBufferLength > OutputBufferLength) ?
|
|
|
|
InputBufferLength : OutputBufferLength;
|
|
|
|
|
|
|
|
/* Make sure there is one */
|
|
|
|
if (BufferLength)
|
|
|
|
{
|
|
|
|
/* Allocate the System Buffer */
|
|
|
|
Irp->AssociatedIrp.SystemBuffer =
|
2017-11-26 21:01:04 +08:00
|
|
|
ExAllocatePoolWithQuotaTag(PoolType,
|
|
|
|
BufferLength,
|
|
|
|
TAG_SYS_BUF);
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
|
|
|
|
/* Check if we got a buffer */
|
|
|
|
if (InputBuffer)
|
|
|
|
{
|
|
|
|
/* Copy into the System Buffer */
|
|
|
|
RtlCopyMemory(Irp->AssociatedIrp.SystemBuffer,
|
|
|
|
InputBuffer,
|
|
|
|
InputBufferLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write the flags */
|
|
|
|
Irp->Flags = IRP_BUFFERED_IO | IRP_DEALLOCATE_BUFFER;
|
|
|
|
if (OutputBuffer) Irp->Flags |= IRP_INPUT_OPERATION;
|
|
|
|
|
|
|
|
/* Save the Buffer */
|
|
|
|
Irp->UserBuffer = OutputBuffer;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Clear the Flags and Buffer */
|
|
|
|
Irp->UserBuffer = NULL;
|
|
|
|
}
|
|
|
|
}
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
{
|
2009-08-27 01:31:02 +08:00
|
|
|
/* Cleanup after exception and return */
|
2008-12-22 02:16:12 +08:00
|
|
|
IopCleanupAfterException(FileObject, Irp, EventObject, NULL);
|
2009-08-27 01:31:02 +08:00
|
|
|
_SEH2_YIELD(return _SEH2_GetExceptionCode());
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
}
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_END;
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* Direct I/O */
|
|
|
|
case METHOD_IN_DIRECT:
|
|
|
|
case METHOD_OUT_DIRECT:
|
|
|
|
|
|
|
|
/* Enter SEH */
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_TRY
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
{
|
|
|
|
/* Check if we got an input buffer */
|
|
|
|
if ((InputBufferLength) && (InputBuffer))
|
|
|
|
{
|
|
|
|
/* Allocate the System Buffer */
|
|
|
|
Irp->AssociatedIrp.SystemBuffer =
|
2017-11-26 21:01:04 +08:00
|
|
|
ExAllocatePoolWithQuotaTag(PoolType,
|
|
|
|
InputBufferLength,
|
|
|
|
TAG_SYS_BUF);
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
|
|
|
|
/* Copy into the System Buffer */
|
|
|
|
RtlCopyMemory(Irp->AssociatedIrp.SystemBuffer,
|
|
|
|
InputBuffer,
|
|
|
|
InputBufferLength);
|
|
|
|
|
|
|
|
/* Write the flags */
|
|
|
|
Irp->Flags = IRP_BUFFERED_IO | IRP_DEALLOCATE_BUFFER;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if we got an output buffer */
|
2018-07-29 19:58:30 +08:00
|
|
|
if (OutputBufferLength)
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
{
|
|
|
|
/* Allocate the System Buffer */
|
|
|
|
Irp->MdlAddress = IoAllocateMdl(OutputBuffer,
|
|
|
|
OutputBufferLength,
|
|
|
|
FALSE,
|
|
|
|
FALSE,
|
|
|
|
Irp);
|
|
|
|
if (!Irp->MdlAddress)
|
|
|
|
{
|
|
|
|
/* Raise exception we'll catch */
|
|
|
|
ExRaiseStatus(STATUS_INSUFFICIENT_RESOURCES);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Do the probe */
|
|
|
|
MmProbeAndLockPages(Irp->MdlAddress,
|
|
|
|
PreviousMode,
|
|
|
|
(AccessType == METHOD_IN_DIRECT) ?
|
|
|
|
IoReadAccess : IoWriteAccess);
|
|
|
|
}
|
|
|
|
}
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
{
|
2009-08-27 01:31:02 +08:00
|
|
|
/* Cleanup after exception and return */
|
2008-12-22 02:16:12 +08:00
|
|
|
IopCleanupAfterException(FileObject, Irp, EventObject, NULL);
|
2009-08-27 01:31:02 +08:00
|
|
|
_SEH2_YIELD(return _SEH2_GetExceptionCode());
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
}
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_END;
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case METHOD_NEITHER:
|
|
|
|
|
|
|
|
/* Just save the Buffer */
|
|
|
|
Irp->UserBuffer = OutputBuffer;
|
|
|
|
StackPtr->Parameters.DeviceIoControl.Type3InputBuffer = InputBuffer;
|
|
|
|
}
|
2006-11-08 19:47:44 +08:00
|
|
|
|
|
|
|
/* Use deferred completion for FS I/O */
|
2016-09-04 06:07:53 +08:00
|
|
|
if (!IsDevIoCtl)
|
|
|
|
{
|
|
|
|
Irp->Flags |= IRP_DEFER_IO_COMPLETION;
|
|
|
|
}
|
2006-11-08 19:47:44 +08:00
|
|
|
|
2016-09-04 06:07:53 +08:00
|
|
|
/* If we are dismounting a volume, increaase the dismount count */
|
2016-09-04 03:10:09 +08:00
|
|
|
if (IoControlCode == FSCTL_DISMOUNT_VOLUME)
|
|
|
|
{
|
2016-09-04 06:07:53 +08:00
|
|
|
InterlockedIncrement((PLONG)&SharedUserData->DismountCount);
|
2016-09-04 03:10:09 +08:00
|
|
|
}
|
|
|
|
|
2006-11-08 19:47:44 +08:00
|
|
|
/* Perform the call */
|
|
|
|
return IopPerformSynchronousRequest(DeviceObject,
|
|
|
|
Irp,
|
|
|
|
FileObject,
|
|
|
|
!IsDevIoCtl,
|
|
|
|
PreviousMode,
|
|
|
|
LockedForSynch,
|
|
|
|
IopOtherTransfer);
|
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
IopQueryDeviceInformation(IN PFILE_OBJECT FileObject,
|
|
|
|
IN ULONG InformationClass,
|
|
|
|
IN ULONG Length,
|
|
|
|
OUT PVOID Information,
|
|
|
|
OUT PULONG ReturnedLength,
|
|
|
|
IN BOOLEAN File)
|
|
|
|
{
|
|
|
|
IO_STATUS_BLOCK IoStatusBlock;
|
|
|
|
PIRP Irp;
|
|
|
|
PDEVICE_OBJECT DeviceObject;
|
|
|
|
PIO_STACK_LOCATION StackPtr;
|
|
|
|
BOOLEAN LocalEvent = FALSE;
|
|
|
|
KEVENT Event;
|
|
|
|
NTSTATUS Status;
|
|
|
|
PAGED_CODE();
|
2021-09-13 01:49:54 +08:00
|
|
|
IOTRACE(IO_API_DEBUG, "Handle: %p. CTL: %lx. Type: %lx\n",
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
FileObject, InformationClass, File);
|
2006-11-08 19:47:44 +08:00
|
|
|
|
|
|
|
/* Reference the object */
|
|
|
|
ObReferenceObject(FileObject);
|
|
|
|
|
|
|
|
/* Check if this is a file that was opened for Synch I/O */
|
|
|
|
if (FileObject->Flags & FO_SYNCHRONOUS_IO)
|
|
|
|
{
|
|
|
|
/* Lock it */
|
2018-10-02 15:55:07 +08:00
|
|
|
(void)IopLockFileObject(FileObject, KernelMode);
|
2006-11-08 19:47:44 +08:00
|
|
|
|
|
|
|
/* Use File Object event */
|
|
|
|
KeClearEvent(&FileObject->Event);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Use local event */
|
|
|
|
KeInitializeEvent(&Event, SynchronizationEvent, FALSE);
|
|
|
|
LocalEvent = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the Device Object */
|
|
|
|
DeviceObject = IoGetRelatedDeviceObject(FileObject);
|
|
|
|
|
|
|
|
/* Allocate the IRP */
|
|
|
|
Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
|
|
|
|
if (!Irp) return IopCleanupFailedIrp(FileObject, NULL, NULL);
|
|
|
|
|
|
|
|
/* Set the IRP */
|
|
|
|
Irp->Tail.Overlay.OriginalFileObject = FileObject;
|
|
|
|
Irp->RequestorMode = KernelMode;
|
|
|
|
Irp->Overlay.AsynchronousParameters.UserApcRoutine = NULL;
|
|
|
|
Irp->UserIosb = &IoStatusBlock;
|
|
|
|
Irp->UserEvent = (LocalEvent) ? &Event : NULL;
|
|
|
|
Irp->Flags = (LocalEvent) ? IRP_SYNCHRONOUS_API : 0;
|
|
|
|
Irp->Flags |= IRP_BUFFERED_IO;
|
|
|
|
Irp->AssociatedIrp.SystemBuffer = Information;
|
|
|
|
Irp->Tail.Overlay.Thread = PsGetCurrentThread();
|
|
|
|
|
|
|
|
/* Set the Stack Data */
|
|
|
|
StackPtr = IoGetNextIrpStackLocation(Irp);
|
|
|
|
StackPtr->MajorFunction = File ? IRP_MJ_QUERY_INFORMATION:
|
|
|
|
IRP_MJ_QUERY_VOLUME_INFORMATION;
|
|
|
|
StackPtr->FileObject = FileObject;
|
|
|
|
|
|
|
|
/* Check which type this is */
|
|
|
|
if (File)
|
|
|
|
{
|
|
|
|
/* Set Parameters */
|
|
|
|
StackPtr->Parameters.QueryFile.FileInformationClass = InformationClass;
|
|
|
|
StackPtr->Parameters.QueryFile.Length = Length;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Set Parameters */
|
|
|
|
StackPtr->Parameters.QueryVolume.FsInformationClass = InformationClass;
|
|
|
|
StackPtr->Parameters.QueryVolume.Length = Length;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Queue the IRP */
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
IopQueueIrpToThread(Irp);
|
2006-11-08 19:47:44 +08:00
|
|
|
|
|
|
|
/* Call the Driver */
|
2006-12-01 02:04:22 +08:00
|
|
|
Status = IoCallDriver(DeviceObject, Irp);
|
2006-11-08 19:47:44 +08:00
|
|
|
|
|
|
|
/* Check if this was synch I/O */
|
|
|
|
if (!LocalEvent)
|
|
|
|
{
|
2016-03-18 18:29:46 +08:00
|
|
|
/* Check if the request is pending */
|
2006-11-08 19:47:44 +08:00
|
|
|
if (Status == STATUS_PENDING)
|
|
|
|
{
|
|
|
|
/* Wait on the file object */
|
|
|
|
Status = KeWaitForSingleObject(&FileObject->Event,
|
|
|
|
Executive,
|
|
|
|
KernelMode,
|
2012-07-24 23:32:06 +08:00
|
|
|
(FileObject->Flags &
|
|
|
|
FO_ALERTABLE_IO) != 0,
|
2006-11-08 19:47:44 +08:00
|
|
|
NULL);
|
|
|
|
if (Status == STATUS_ALERTED)
|
|
|
|
{
|
|
|
|
/* Abort the operation */
|
|
|
|
IopAbortInterruptedIrp(&FileObject->Event, Irp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the final status */
|
|
|
|
Status = FileObject->FinalStatus;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Release the file lock */
|
|
|
|
IopUnlockFileObject(FileObject);
|
|
|
|
}
|
|
|
|
else if (Status == STATUS_PENDING)
|
|
|
|
{
|
|
|
|
/* Wait on the local event and get the final status */
|
|
|
|
KeWaitForSingleObject(&Event,
|
|
|
|
Executive,
|
|
|
|
KernelMode,
|
|
|
|
FALSE,
|
|
|
|
NULL);
|
|
|
|
Status = IoStatusBlock.Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the Length and Status. ReturnedLength is NOT optional */
|
[HAL/NDK]
- Make Vector parameter in HalEnableSystemInterrupt, HalDisableSystemInterrupt and HalBeginSystemInterrupt an ULONG, not an UCHAR
[NDK]
- 64bit fixes for HANDLE_TABLE, KPROCESS, SECTION_IMAGE_INFORMATION, MMADDRESS_LIST, MMVAD_FLAGS, MMVAD, MMVAD_LONG, MMVAD_SHORT, MEMORY_DESCRIPTOR, MEMORY_ALLOCATION_DESCRIPTOR, LdrVerifyMappedImageMatchesChecksum
- KDPC_DATA::DpcQueueDepth is signed on amd64, unsigned on x86
[NTOSKRNL]
- Fix hundreds of MSVC and amd64 warnings
- add a pragma message to FstubFixupEfiPartition, since it looks broken
- Move portable Ke constants from <arch>/cpu.c to krnlinit.c
- Fixed a bug in amd64 KiGeneralProtectionFaultHandler
svn path=/trunk/; revision=53734
2011-09-18 21:11:45 +08:00
|
|
|
*ReturnedLength = (ULONG)IoStatusBlock.Information;
|
2006-11-08 19:47:44 +08:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2014-04-27 03:36:51 +08:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
IopGetFileInformation(IN PFILE_OBJECT FileObject,
|
|
|
|
IN ULONG Length,
|
|
|
|
IN FILE_INFORMATION_CLASS FileInfoClass,
|
|
|
|
OUT PVOID Buffer,
|
|
|
|
OUT PULONG ReturnedLength)
|
|
|
|
{
|
|
|
|
PIRP Irp;
|
|
|
|
KEVENT Event;
|
|
|
|
NTSTATUS Status;
|
|
|
|
PIO_STACK_LOCATION Stack;
|
|
|
|
PDEVICE_OBJECT DeviceObject;
|
|
|
|
IO_STATUS_BLOCK IoStatusBlock;
|
|
|
|
|
|
|
|
PAGED_CODE();
|
|
|
|
|
|
|
|
/* Allocate an IRP */
|
|
|
|
ObReferenceObject(FileObject);
|
|
|
|
DeviceObject = IoGetRelatedDeviceObject(FileObject);
|
|
|
|
Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
|
|
|
|
if (Irp == NULL)
|
|
|
|
{
|
|
|
|
ObDereferenceObject(FileObject);
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
}
|
|
|
|
|
2014-04-27 21:46:21 +08:00
|
|
|
/* Init event */
|
|
|
|
KeInitializeEvent(&Event, SynchronizationEvent, FALSE);
|
|
|
|
|
2014-04-27 03:36:51 +08:00
|
|
|
/* Setup the IRP */
|
|
|
|
Irp->UserIosb = &IoStatusBlock;
|
|
|
|
Irp->UserEvent = &Event;
|
|
|
|
Irp->Overlay.AsynchronousParameters.UserApcRoutine = NULL;
|
|
|
|
Irp->RequestorMode = KernelMode;
|
|
|
|
Irp->AssociatedIrp.SystemBuffer = Buffer;
|
|
|
|
Irp->Flags = IRP_SYNCHRONOUS_API | IRP_BUFFERED_IO | IRP_OB_QUERY_NAME;
|
|
|
|
Irp->Tail.Overlay.OriginalFileObject = FileObject;
|
|
|
|
Irp->Tail.Overlay.Thread = PsGetCurrentThread();
|
|
|
|
|
|
|
|
Stack = IoGetNextIrpStackLocation(Irp);
|
|
|
|
Stack->MajorFunction = IRP_MJ_QUERY_INFORMATION;
|
|
|
|
Stack->FileObject = FileObject;
|
|
|
|
Stack->Parameters.QueryFile.FileInformationClass = FileInfoClass;
|
|
|
|
Stack->Parameters.QueryFile.Length = Length;
|
|
|
|
|
|
|
|
|
|
|
|
/* Queue the IRP */
|
|
|
|
IopQueueIrpToThread(Irp);
|
|
|
|
|
|
|
|
/* Call the driver */
|
|
|
|
Status = IoCallDriver(DeviceObject, Irp);
|
|
|
|
if (Status == STATUS_PENDING)
|
|
|
|
{
|
|
|
|
KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
|
|
|
|
Status = IoStatusBlock.Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
*ReturnedLength = IoStatusBlock.Information;
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
IopGetBasicInformationFile(IN PFILE_OBJECT FileObject,
|
|
|
|
OUT PFILE_BASIC_INFORMATION BasicInfo)
|
|
|
|
{
|
|
|
|
ULONG ReturnedLength;
|
|
|
|
PDEVICE_OBJECT DeviceObject;
|
|
|
|
IO_STATUS_BLOCK IoStatusBlock;
|
|
|
|
|
|
|
|
PAGED_CODE();
|
|
|
|
|
|
|
|
/* Try to do it the fast way if possible */
|
|
|
|
DeviceObject = IoGetRelatedDeviceObject(FileObject);
|
|
|
|
if (DeviceObject->DriverObject->FastIoDispatch != NULL &&
|
|
|
|
DeviceObject->DriverObject->FastIoDispatch->FastIoQueryBasicInfo != NULL &&
|
|
|
|
DeviceObject->DriverObject->FastIoDispatch->FastIoQueryBasicInfo(FileObject,
|
2014-04-27 19:14:16 +08:00
|
|
|
((FileObject->Flags & FO_SYNCHRONOUS_IO) != 0),
|
2014-04-27 03:36:51 +08:00
|
|
|
BasicInfo,
|
|
|
|
&IoStatusBlock,
|
|
|
|
DeviceObject))
|
|
|
|
{
|
|
|
|
return IoStatusBlock.Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* In case it failed, fall back to IRP-based method */
|
|
|
|
return IopGetFileInformation(FileObject, sizeof(FILE_BASIC_INFORMATION), FileBasicInformation, BasicInfo, &ReturnedLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
IopOpenLinkOrRenameTarget(OUT PHANDLE Handle,
|
|
|
|
IN PIRP Irp,
|
|
|
|
IN PFILE_RENAME_INFORMATION RenameInfo,
|
|
|
|
IN PFILE_OBJECT FileObject)
|
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
|
|
|
HANDLE TargetHandle;
|
|
|
|
UNICODE_STRING FileName;
|
|
|
|
PIO_STACK_LOCATION Stack;
|
|
|
|
PFILE_OBJECT TargetFileObject;
|
|
|
|
IO_STATUS_BLOCK IoStatusBlock;
|
|
|
|
FILE_BASIC_INFORMATION BasicInfo;
|
|
|
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
|
|
|
OBJECT_HANDLE_INFORMATION HandleInformation;
|
|
|
|
ACCESS_MASK DesiredAccess = FILE_WRITE_DATA;
|
|
|
|
|
|
|
|
PAGED_CODE();
|
|
|
|
|
|
|
|
/* First, establish whether our target is a directory */
|
|
|
|
if (!(FileObject->Flags & FO_DIRECT_DEVICE_OPEN))
|
|
|
|
{
|
|
|
|
Status = IopGetBasicInformationFile(FileObject, &BasicInfo);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (BasicInfo.FileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
|
|
|
|
DesiredAccess = FILE_ADD_SUBDIRECTORY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Setup the string to the target */
|
|
|
|
FileName.Buffer = RenameInfo->FileName;
|
|
|
|
FileName.Length = RenameInfo->FileNameLength;
|
|
|
|
FileName.MaximumLength = RenameInfo->FileNameLength;
|
|
|
|
|
|
|
|
InitializeObjectAttributes(&ObjectAttributes,
|
|
|
|
&FileName,
|
|
|
|
(FileObject->Flags & FO_OPENED_CASE_SENSITIVE ? 0 : OBJ_CASE_INSENSITIVE) | OBJ_KERNEL_HANDLE,
|
|
|
|
RenameInfo->RootDirectory,
|
|
|
|
NULL);
|
|
|
|
|
2018-10-04 03:28:11 +08:00
|
|
|
/* And open its parent directory
|
|
|
|
* Use hint if specified
|
|
|
|
*/
|
2014-04-27 03:36:51 +08:00
|
|
|
if (FileObject->Flags & FO_FILE_OBJECT_HAS_EXTENSION)
|
|
|
|
{
|
2018-10-04 03:28:11 +08:00
|
|
|
PFILE_OBJECT_EXTENSION FileObjectExtension;
|
|
|
|
|
2014-04-27 03:36:51 +08:00
|
|
|
ASSERT(!(FileObject->Flags & FO_DIRECT_DEVICE_OPEN));
|
2018-10-04 03:28:11 +08:00
|
|
|
|
|
|
|
FileObjectExtension = FileObject->FileObjectExtension;
|
2014-04-27 03:36:51 +08:00
|
|
|
Status = IoCreateFileSpecifyDeviceObjectHint(&TargetHandle,
|
|
|
|
DesiredAccess | SYNCHRONIZE,
|
|
|
|
&ObjectAttributes,
|
|
|
|
&IoStatusBlock,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
|
|
|
FILE_OPEN,
|
|
|
|
FILE_OPEN_FOR_BACKUP_INTENT,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
CreateFileTypeNone,
|
|
|
|
NULL,
|
|
|
|
IO_FORCE_ACCESS_CHECK | IO_OPEN_TARGET_DIRECTORY | IO_NO_PARAMETER_CHECKING,
|
2018-10-04 03:28:11 +08:00
|
|
|
FileObjectExtension->TopDeviceObjectHint);
|
2014-04-27 03:36:51 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Status = IoCreateFile(&TargetHandle,
|
|
|
|
DesiredAccess | SYNCHRONIZE,
|
|
|
|
&ObjectAttributes,
|
|
|
|
&IoStatusBlock,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
|
|
|
FILE_OPEN,
|
|
|
|
FILE_OPEN_FOR_BACKUP_INTENT,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
CreateFileTypeNone,
|
|
|
|
NULL,
|
|
|
|
IO_FORCE_ACCESS_CHECK | IO_OPEN_TARGET_DIRECTORY | IO_NO_PARAMETER_CHECKING);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Once open, continue only if:
|
|
|
|
* Target exists and we're allowed to overwrite it
|
|
|
|
*/
|
|
|
|
Stack = IoGetNextIrpStackLocation(Irp);
|
|
|
|
if (Stack->Parameters.SetFile.FileInformationClass == FileLinkInformation &&
|
|
|
|
!RenameInfo->ReplaceIfExists &&
|
|
|
|
IoStatusBlock.Information == FILE_EXISTS)
|
|
|
|
{
|
|
|
|
ObCloseHandle(TargetHandle, KernelMode);
|
|
|
|
return STATUS_OBJECT_NAME_COLLISION;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now, we'll get the associated device of the target, to check for same device location
|
|
|
|
* So, get the FO first
|
|
|
|
*/
|
|
|
|
Status = ObReferenceObjectByHandle(TargetHandle,
|
|
|
|
FILE_WRITE_DATA,
|
|
|
|
IoFileObjectType,
|
|
|
|
KernelMode,
|
|
|
|
(PVOID *)&TargetFileObject,
|
|
|
|
&HandleInformation);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
ObCloseHandle(TargetHandle, KernelMode);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We can dereference, we have the handle */
|
|
|
|
ObDereferenceObject(TargetFileObject);
|
|
|
|
/* If we're not on the same device, error out **/
|
|
|
|
if (IoGetRelatedDeviceObject(TargetFileObject) != IoGetRelatedDeviceObject(FileObject))
|
|
|
|
{
|
|
|
|
ObCloseHandle(TargetHandle, KernelMode);
|
|
|
|
return STATUS_NOT_SAME_DEVICE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return parent directory file object and handle */
|
|
|
|
Stack->Parameters.SetFile.FileObject = TargetFileObject;
|
|
|
|
*Handle = TargetHandle;
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2015-02-16 23:33:34 +08:00
|
|
|
static
|
|
|
|
ULONG
|
|
|
|
IopGetFileMode(IN PFILE_OBJECT FileObject)
|
|
|
|
{
|
|
|
|
ULONG Mode = 0;
|
|
|
|
|
|
|
|
if (FileObject->Flags & FO_WRITE_THROUGH)
|
|
|
|
Mode |= FILE_WRITE_THROUGH;
|
|
|
|
|
|
|
|
if (FileObject->Flags & FO_SEQUENTIAL_ONLY)
|
|
|
|
Mode |= FILE_SEQUENTIAL_ONLY;
|
|
|
|
|
|
|
|
if (FileObject->Flags & FO_NO_INTERMEDIATE_BUFFERING)
|
|
|
|
Mode |= FILE_NO_INTERMEDIATE_BUFFERING;
|
|
|
|
|
|
|
|
if (FileObject->Flags & FO_SYNCHRONOUS_IO)
|
|
|
|
{
|
|
|
|
if (FileObject->Flags & FO_ALERTABLE_IO)
|
|
|
|
Mode |= FILE_SYNCHRONOUS_IO_ALERT;
|
|
|
|
else
|
|
|
|
Mode |= FILE_SYNCHRONOUS_IO_NONALERT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FileObject->Flags & FO_DELETE_ON_CLOSE)
|
|
|
|
Mode |= FILE_DELETE_ON_CLOSE;
|
|
|
|
|
|
|
|
return Mode;
|
|
|
|
}
|
|
|
|
|
2019-03-29 05:29:22 +08:00
|
|
|
static
|
|
|
|
BOOLEAN
|
|
|
|
IopGetMountFlag(IN PDEVICE_OBJECT DeviceObject)
|
|
|
|
{
|
|
|
|
KIRQL OldIrql;
|
|
|
|
PVPB Vpb;
|
|
|
|
BOOLEAN Mounted;
|
|
|
|
|
|
|
|
/* Assume not mounted */
|
|
|
|
Mounted = FALSE;
|
|
|
|
|
|
|
|
/* Check whether we have the mount flag */
|
|
|
|
IoAcquireVpbSpinLock(&OldIrql);
|
|
|
|
|
|
|
|
Vpb = DeviceObject->Vpb;
|
|
|
|
if (Vpb != NULL &&
|
|
|
|
BooleanFlagOn(Vpb->Flags, VPB_MOUNTED))
|
|
|
|
{
|
|
|
|
Mounted = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
IoReleaseVpbSpinLock(OldIrql);
|
|
|
|
|
|
|
|
return Mounted;
|
|
|
|
}
|
|
|
|
|
2019-03-30 04:42:42 +08:00
|
|
|
static
|
|
|
|
BOOLEAN
|
|
|
|
IopVerifyDriverObjectOnStack(IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PDRIVER_OBJECT DriverObject)
|
|
|
|
{
|
|
|
|
PDEVICE_OBJECT StackDO;
|
|
|
|
|
|
|
|
/* Browse our whole device stack, trying to find the appropriate driver */
|
|
|
|
StackDO = IopGetDeviceAttachmentBase(DeviceObject);
|
|
|
|
while (StackDO != NULL)
|
|
|
|
{
|
|
|
|
/* We've found the driver, return success */
|
|
|
|
if (StackDO->DriverObject == DriverObject)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Move to the next */
|
|
|
|
StackDO = StackDO->AttachedDevice;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We only reach there if driver was not found */
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
NTSTATUS
|
|
|
|
IopGetDriverPathInformation(IN PFILE_OBJECT FileObject,
|
|
|
|
IN PFILE_FS_DRIVER_PATH_INFORMATION DriverPathInfo,
|
|
|
|
IN ULONG Length)
|
|
|
|
{
|
|
|
|
KIRQL OldIrql;
|
|
|
|
NTSTATUS Status;
|
|
|
|
UNICODE_STRING DriverName;
|
|
|
|
PDRIVER_OBJECT DriverObject;
|
|
|
|
|
|
|
|
/* Make sure the structure is consistent (ie, driver name fits into the buffer) */
|
|
|
|
if (Length - FIELD_OFFSET(FILE_FS_DRIVER_PATH_INFORMATION, DriverName) < DriverPathInfo->DriverNameLength)
|
|
|
|
{
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Setup the whole driver name */
|
|
|
|
DriverName.Length = DriverPathInfo->DriverNameLength;
|
|
|
|
DriverName.MaximumLength = DriverPathInfo->DriverNameLength;
|
|
|
|
DriverName.Buffer = &DriverPathInfo->DriverName[0];
|
|
|
|
|
|
|
|
/* Ask Ob for such driver */
|
|
|
|
Status = ObReferenceObjectByName(&DriverName,
|
|
|
|
OBJ_CASE_INSENSITIVE,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
IoDriverObjectType,
|
|
|
|
KernelMode,
|
|
|
|
NULL,
|
|
|
|
(PVOID*)&DriverObject);
|
|
|
|
/* No such driver, bail out */
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Lock the devices database, we'll browse it */
|
|
|
|
OldIrql = KeAcquireQueuedSpinLock(LockQueueIoDatabaseLock);
|
|
|
|
/* If we have a VPB, browse the stack from the volume */
|
|
|
|
if (FileObject->Vpb != NULL && FileObject->Vpb->DeviceObject != NULL)
|
|
|
|
{
|
|
|
|
DriverPathInfo->DriverInPath = IopVerifyDriverObjectOnStack(FileObject->Vpb->DeviceObject, DriverObject);
|
|
|
|
}
|
|
|
|
/* Otherwise, do it from the normal device */
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DriverPathInfo->DriverInPath = IopVerifyDriverObjectOnStack(FileObject->DeviceObject, DriverObject);
|
|
|
|
}
|
|
|
|
KeReleaseQueuedSpinLock(LockQueueIoDatabaseLock, OldIrql);
|
|
|
|
|
|
|
|
/* No longer needed */
|
|
|
|
ObDereferenceObject(DriverObject);
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2006-11-08 19:47:44 +08:00
|
|
|
/* PUBLIC FUNCTIONS **********************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
IoSynchronousPageWrite(IN PFILE_OBJECT FileObject,
|
|
|
|
IN PMDL Mdl,
|
|
|
|
IN PLARGE_INTEGER Offset,
|
|
|
|
IN PKEVENT Event,
|
|
|
|
IN PIO_STATUS_BLOCK StatusBlock)
|
|
|
|
{
|
|
|
|
PIRP Irp;
|
|
|
|
PIO_STACK_LOCATION StackPtr;
|
|
|
|
PDEVICE_OBJECT DeviceObject;
|
2021-09-13 01:49:54 +08:00
|
|
|
IOTRACE(IO_API_DEBUG, "FileObject: %p. Mdl: %p. Offset: %p\n",
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
FileObject, Mdl, Offset);
|
2006-11-08 19:47:44 +08:00
|
|
|
|
2018-02-24 21:02:33 +08:00
|
|
|
/* Is the write originating from Cc? */
|
|
|
|
if (FileObject->SectionObjectPointer != NULL &&
|
|
|
|
FileObject->SectionObjectPointer->SharedCacheMap != NULL)
|
|
|
|
{
|
|
|
|
++CcDataFlushes;
|
|
|
|
CcDataPages += BYTES_TO_PAGES(MmGetMdlByteCount(Mdl));
|
|
|
|
}
|
|
|
|
|
2006-11-08 19:47:44 +08:00
|
|
|
/* Get the Device Object */
|
|
|
|
DeviceObject = IoGetRelatedDeviceObject(FileObject);
|
|
|
|
|
|
|
|
/* Allocate IRP */
|
|
|
|
Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
|
|
|
|
if (!Irp) return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
|
|
|
|
/* Get the Stack */
|
|
|
|
StackPtr = IoGetNextIrpStackLocation(Irp);
|
|
|
|
|
|
|
|
/* Create the IRP Settings */
|
|
|
|
Irp->MdlAddress = Mdl;
|
|
|
|
Irp->UserBuffer = MmGetMdlVirtualAddress(Mdl);
|
|
|
|
Irp->UserIosb = StatusBlock;
|
|
|
|
Irp->UserEvent = Event;
|
|
|
|
Irp->RequestorMode = KernelMode;
|
|
|
|
Irp->Flags = IRP_PAGING_IO | IRP_NOCACHE | IRP_SYNCHRONOUS_PAGING_IO;
|
|
|
|
Irp->Tail.Overlay.OriginalFileObject = FileObject;
|
|
|
|
Irp->Tail.Overlay.Thread = PsGetCurrentThread();
|
|
|
|
|
|
|
|
/* Set the Stack Settings */
|
|
|
|
StackPtr->Parameters.Write.Length = MmGetMdlByteCount(Mdl);
|
|
|
|
StackPtr->Parameters.Write.ByteOffset = *Offset;
|
|
|
|
StackPtr->MajorFunction = IRP_MJ_WRITE;
|
|
|
|
StackPtr->FileObject = FileObject;
|
|
|
|
|
|
|
|
/* Call the Driver */
|
2008-08-24 00:30:14 +08:00
|
|
|
return IoCallDriver(DeviceObject, Irp);
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
IoPageRead(IN PFILE_OBJECT FileObject,
|
|
|
|
IN PMDL Mdl,
|
|
|
|
IN PLARGE_INTEGER Offset,
|
|
|
|
IN PKEVENT Event,
|
|
|
|
IN PIO_STATUS_BLOCK StatusBlock)
|
|
|
|
{
|
|
|
|
PIRP Irp;
|
|
|
|
PIO_STACK_LOCATION StackPtr;
|
|
|
|
PDEVICE_OBJECT DeviceObject;
|
2021-09-13 01:49:54 +08:00
|
|
|
IOTRACE(IO_API_DEBUG, "FileObject: %p. Mdl: %p. Offset: %p\n",
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
FileObject, Mdl, Offset);
|
2006-11-08 19:47:44 +08:00
|
|
|
|
|
|
|
/* Get the Device Object */
|
|
|
|
DeviceObject = IoGetRelatedDeviceObject(FileObject);
|
|
|
|
|
|
|
|
/* Allocate IRP */
|
|
|
|
Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
|
2018-02-24 21:50:23 +08:00
|
|
|
/* If allocation failed, try to see whether we can use
|
|
|
|
* the reserve IRP
|
|
|
|
*/
|
|
|
|
if (Irp == NULL)
|
|
|
|
{
|
|
|
|
/* We will use it only for paging file */
|
|
|
|
if (MmIsFileObjectAPagingFile(FileObject))
|
|
|
|
{
|
|
|
|
InterlockedExchangeAdd(&IoPageReadIrpAllocationFailure, 1);
|
|
|
|
Irp = IopAllocateReserveIrp(DeviceObject->StackSize);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
InterlockedExchangeAdd(&IoPageReadNonPagefileIrpAllocationFailure, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If allocation failed (not a paging file or too big stack size)
|
|
|
|
* Fail for real
|
|
|
|
*/
|
|
|
|
if (Irp == NULL)
|
|
|
|
{
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
}
|
|
|
|
}
|
2006-11-08 19:47:44 +08:00
|
|
|
|
|
|
|
/* Get the Stack */
|
|
|
|
StackPtr = IoGetNextIrpStackLocation(Irp);
|
|
|
|
|
|
|
|
/* Create the IRP Settings */
|
|
|
|
Irp->MdlAddress = Mdl;
|
|
|
|
Irp->UserBuffer = MmGetMdlVirtualAddress(Mdl);
|
|
|
|
Irp->UserIosb = StatusBlock;
|
|
|
|
Irp->UserEvent = Event;
|
|
|
|
Irp->RequestorMode = KernelMode;
|
|
|
|
Irp->Flags = IRP_PAGING_IO |
|
|
|
|
IRP_NOCACHE |
|
|
|
|
IRP_SYNCHRONOUS_PAGING_IO |
|
|
|
|
IRP_INPUT_OPERATION;
|
|
|
|
Irp->Tail.Overlay.OriginalFileObject = FileObject;
|
|
|
|
Irp->Tail.Overlay.Thread = PsGetCurrentThread();
|
|
|
|
|
|
|
|
/* Set the Stack Settings */
|
|
|
|
StackPtr->Parameters.Read.Length = MmGetMdlByteCount(Mdl);
|
|
|
|
StackPtr->Parameters.Read.ByteOffset = *Offset;
|
|
|
|
StackPtr->MajorFunction = IRP_MJ_READ;
|
|
|
|
StackPtr->FileObject = FileObject;
|
|
|
|
|
|
|
|
/* Call the Driver */
|
2008-08-24 00:30:14 +08:00
|
|
|
return IoCallDriver(DeviceObject, Irp);
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
IoQueryFileInformation(IN PFILE_OBJECT FileObject,
|
|
|
|
IN FILE_INFORMATION_CLASS FileInformationClass,
|
|
|
|
IN ULONG Length,
|
|
|
|
OUT PVOID FileInformation,
|
|
|
|
OUT PULONG ReturnedLength)
|
|
|
|
{
|
|
|
|
/* Call the shared routine */
|
|
|
|
return IopQueryDeviceInformation(FileObject,
|
|
|
|
FileInformationClass,
|
|
|
|
Length,
|
|
|
|
FileInformation,
|
|
|
|
ReturnedLength,
|
|
|
|
TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
IoQueryVolumeInformation(IN PFILE_OBJECT FileObject,
|
|
|
|
IN FS_INFORMATION_CLASS FsInformationClass,
|
|
|
|
IN ULONG Length,
|
|
|
|
OUT PVOID FsInformation,
|
|
|
|
OUT PULONG ReturnedLength)
|
|
|
|
{
|
|
|
|
/* Call the shared routine */
|
|
|
|
return IopQueryDeviceInformation(FileObject,
|
|
|
|
FsInformationClass,
|
|
|
|
Length,
|
|
|
|
FsInformation,
|
|
|
|
ReturnedLength,
|
|
|
|
FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2008-08-24 00:30:14 +08:00
|
|
|
* @implemented
|
2006-11-08 19:47:44 +08:00
|
|
|
*/
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
IoSetInformation(IN PFILE_OBJECT FileObject,
|
|
|
|
IN FILE_INFORMATION_CLASS FileInformationClass,
|
|
|
|
IN ULONG Length,
|
|
|
|
IN PVOID FileInformation)
|
|
|
|
{
|
|
|
|
IO_STATUS_BLOCK IoStatusBlock;
|
|
|
|
PIRP Irp;
|
|
|
|
PDEVICE_OBJECT DeviceObject;
|
|
|
|
PIO_STACK_LOCATION StackPtr;
|
|
|
|
BOOLEAN LocalEvent = FALSE;
|
|
|
|
KEVENT Event;
|
|
|
|
NTSTATUS Status;
|
|
|
|
PAGED_CODE();
|
2021-09-13 01:49:54 +08:00
|
|
|
IOTRACE(IO_API_DEBUG, "FileObject: %p. Class: %lx. Length: %lx\n",
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
FileObject, FileInformationClass, Length);
|
2006-11-08 19:47:44 +08:00
|
|
|
|
|
|
|
/* Reference the object */
|
|
|
|
ObReferenceObject(FileObject);
|
|
|
|
|
|
|
|
/* Check if this is a file that was opened for Synch I/O */
|
|
|
|
if (FileObject->Flags & FO_SYNCHRONOUS_IO)
|
|
|
|
{
|
|
|
|
/* Lock it */
|
2018-10-02 15:55:07 +08:00
|
|
|
(void)IopLockFileObject(FileObject, KernelMode);
|
2006-11-08 19:47:44 +08:00
|
|
|
|
|
|
|
/* Use File Object event */
|
|
|
|
KeClearEvent(&FileObject->Event);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Use local event */
|
|
|
|
KeInitializeEvent(&Event, SynchronizationEvent, FALSE);
|
|
|
|
LocalEvent = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the Device Object */
|
|
|
|
DeviceObject = IoGetRelatedDeviceObject(FileObject);
|
|
|
|
|
|
|
|
/* Allocate the IRP */
|
|
|
|
Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
|
|
|
|
if (!Irp) return IopCleanupFailedIrp(FileObject, NULL, NULL);
|
|
|
|
|
|
|
|
/* Set the IRP */
|
|
|
|
Irp->Tail.Overlay.OriginalFileObject = FileObject;
|
|
|
|
Irp->RequestorMode = KernelMode;
|
|
|
|
Irp->Overlay.AsynchronousParameters.UserApcRoutine = NULL;
|
|
|
|
Irp->UserIosb = &IoStatusBlock;
|
|
|
|
Irp->UserEvent = (LocalEvent) ? &Event : NULL;
|
|
|
|
Irp->Flags = (LocalEvent) ? IRP_SYNCHRONOUS_API : 0;
|
|
|
|
Irp->Flags |= IRP_BUFFERED_IO;
|
|
|
|
Irp->AssociatedIrp.SystemBuffer = FileInformation;
|
|
|
|
Irp->Tail.Overlay.Thread = PsGetCurrentThread();
|
|
|
|
|
|
|
|
/* Set the Stack Data */
|
|
|
|
StackPtr = IoGetNextIrpStackLocation(Irp);
|
|
|
|
StackPtr->MajorFunction = IRP_MJ_SET_INFORMATION;
|
|
|
|
StackPtr->FileObject = FileObject;
|
|
|
|
|
|
|
|
/* Set Parameters */
|
|
|
|
StackPtr->Parameters.SetFile.FileInformationClass = FileInformationClass;
|
|
|
|
StackPtr->Parameters.SetFile.Length = Length;
|
|
|
|
|
|
|
|
/* Queue the IRP */
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
IopQueueIrpToThread(Irp);
|
2006-11-08 19:47:44 +08:00
|
|
|
|
|
|
|
/* Call the Driver */
|
2006-12-04 02:04:32 +08:00
|
|
|
Status = IoCallDriver(DeviceObject, Irp);
|
2006-11-08 19:47:44 +08:00
|
|
|
|
|
|
|
/* Check if this was synch I/O */
|
|
|
|
if (!LocalEvent)
|
|
|
|
{
|
2016-03-18 18:29:46 +08:00
|
|
|
/* Check if the request is pending */
|
2006-11-08 19:47:44 +08:00
|
|
|
if (Status == STATUS_PENDING)
|
|
|
|
{
|
|
|
|
/* Wait on the file object */
|
|
|
|
Status = KeWaitForSingleObject(&FileObject->Event,
|
|
|
|
Executive,
|
|
|
|
KernelMode,
|
2012-07-24 23:32:06 +08:00
|
|
|
(FileObject->Flags &
|
|
|
|
FO_ALERTABLE_IO) != 0,
|
2006-11-08 19:47:44 +08:00
|
|
|
NULL);
|
|
|
|
if (Status == STATUS_ALERTED)
|
|
|
|
{
|
|
|
|
/* Abort the operation */
|
|
|
|
IopAbortInterruptedIrp(&FileObject->Event, Irp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the final status */
|
|
|
|
Status = FileObject->FinalStatus;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Release the file lock */
|
|
|
|
IopUnlockFileObject(FileObject);
|
|
|
|
}
|
|
|
|
else if (Status == STATUS_PENDING)
|
|
|
|
{
|
|
|
|
/* Wait on the local event and get the final status */
|
|
|
|
KeWaitForSingleObject(&Event,
|
|
|
|
Executive,
|
|
|
|
KernelMode,
|
|
|
|
FALSE,
|
|
|
|
NULL);
|
|
|
|
Status = IoStatusBlock.Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the status */
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* NATIVE SERVICES ***********************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2007-10-20 07:21:45 +08:00
|
|
|
NTSTATUS
|
2006-11-08 19:47:44 +08:00
|
|
|
NTAPI
|
|
|
|
NtDeviceIoControlFile(IN HANDLE DeviceHandle,
|
|
|
|
IN HANDLE Event OPTIONAL,
|
|
|
|
IN PIO_APC_ROUTINE UserApcRoutine OPTIONAL,
|
|
|
|
IN PVOID UserApcContext OPTIONAL,
|
|
|
|
OUT PIO_STATUS_BLOCK IoStatusBlock,
|
|
|
|
IN ULONG IoControlCode,
|
|
|
|
IN PVOID InputBuffer,
|
|
|
|
IN ULONG InputBufferLength OPTIONAL,
|
|
|
|
OUT PVOID OutputBuffer,
|
|
|
|
IN ULONG OutputBufferLength OPTIONAL)
|
|
|
|
{
|
|
|
|
/* Call the Generic Function */
|
|
|
|
return IopDeviceFsIoControl(DeviceHandle,
|
|
|
|
Event,
|
|
|
|
UserApcRoutine,
|
|
|
|
UserApcContext,
|
|
|
|
IoStatusBlock,
|
|
|
|
IoControlCode,
|
|
|
|
InputBuffer,
|
|
|
|
InputBufferLength,
|
|
|
|
OutputBuffer,
|
|
|
|
OutputBufferLength,
|
|
|
|
TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
NtFsControlFile(IN HANDLE DeviceHandle,
|
|
|
|
IN HANDLE Event OPTIONAL,
|
|
|
|
IN PIO_APC_ROUTINE UserApcRoutine OPTIONAL,
|
|
|
|
IN PVOID UserApcContext OPTIONAL,
|
|
|
|
OUT PIO_STATUS_BLOCK IoStatusBlock,
|
|
|
|
IN ULONG IoControlCode,
|
|
|
|
IN PVOID InputBuffer,
|
|
|
|
IN ULONG InputBufferLength OPTIONAL,
|
|
|
|
OUT PVOID OutputBuffer,
|
|
|
|
IN ULONG OutputBufferLength OPTIONAL)
|
|
|
|
{
|
|
|
|
/* Call the Generic Function */
|
|
|
|
return IopDeviceFsIoControl(DeviceHandle,
|
|
|
|
Event,
|
|
|
|
UserApcRoutine,
|
|
|
|
UserApcContext,
|
|
|
|
IoStatusBlock,
|
|
|
|
IoControlCode,
|
|
|
|
InputBuffer,
|
|
|
|
InputBufferLength,
|
|
|
|
OutputBuffer,
|
|
|
|
OutputBufferLength,
|
|
|
|
FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
NtFlushBuffersFile(IN HANDLE FileHandle,
|
|
|
|
OUT PIO_STATUS_BLOCK IoStatusBlock)
|
|
|
|
{
|
|
|
|
PFILE_OBJECT FileObject;
|
|
|
|
PIRP Irp;
|
|
|
|
PIO_STACK_LOCATION StackPtr;
|
2009-08-27 01:31:02 +08:00
|
|
|
NTSTATUS Status;
|
2006-11-08 19:47:44 +08:00
|
|
|
PDEVICE_OBJECT DeviceObject;
|
|
|
|
PKEVENT Event = NULL;
|
|
|
|
BOOLEAN LocalEvent = FALSE;
|
|
|
|
OBJECT_HANDLE_INFORMATION ObjectHandleInfo;
|
|
|
|
KPROCESSOR_MODE PreviousMode = KeGetPreviousMode();
|
|
|
|
IO_STATUS_BLOCK KernelIosb;
|
|
|
|
PAGED_CODE();
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
IOTRACE(IO_API_DEBUG, "FileHandle: %p\n", FileHandle);
|
2006-11-08 19:47:44 +08:00
|
|
|
|
|
|
|
if (PreviousMode != KernelMode)
|
|
|
|
{
|
|
|
|
/* Protect probes */
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_TRY
|
2006-11-08 19:47:44 +08:00
|
|
|
{
|
|
|
|
/* Probe the I/O Status block */
|
|
|
|
ProbeForWriteIoStatusBlock(IoStatusBlock);
|
|
|
|
}
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
2006-11-08 19:47:44 +08:00
|
|
|
{
|
2009-08-27 01:31:02 +08:00
|
|
|
/* Return the exception code */
|
|
|
|
_SEH2_YIELD(return _SEH2_GetExceptionCode());
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_END;
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the File Object */
|
|
|
|
Status = ObReferenceObjectByHandle(FileHandle,
|
|
|
|
0,
|
|
|
|
IoFileObjectType,
|
|
|
|
PreviousMode,
|
|
|
|
(PVOID*)&FileObject,
|
|
|
|
&ObjectHandleInfo);
|
|
|
|
if (!NT_SUCCESS(Status)) return Status;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if the handle has either FILE_WRITE_DATA or FILE_APPEND_DATA was
|
|
|
|
* granted. However, if this is a named pipe, make sure we don't ask for
|
|
|
|
* FILE_APPEND_DATA as it interferes with the FILE_CREATE_PIPE_INSTANCE
|
|
|
|
* access right!
|
|
|
|
*/
|
|
|
|
if (!(ObjectHandleInfo.GrantedAccess &
|
|
|
|
((!(FileObject->Flags & FO_NAMED_PIPE) ? FILE_APPEND_DATA : 0) |
|
|
|
|
FILE_WRITE_DATA)))
|
|
|
|
{
|
|
|
|
/* We failed */
|
|
|
|
ObDereferenceObject(FileObject);
|
|
|
|
return STATUS_ACCESS_DENIED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if we should use Sync IO or not */
|
|
|
|
if (FileObject->Flags & FO_SYNCHRONOUS_IO)
|
|
|
|
{
|
|
|
|
/* Lock it */
|
2018-10-02 15:55:07 +08:00
|
|
|
Status = IopLockFileObject(FileObject, PreviousMode);
|
|
|
|
if (Status != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
ObDereferenceObject(FileObject);
|
|
|
|
return Status;
|
|
|
|
}
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Use local event */
|
|
|
|
Event = ExAllocatePoolWithTag(NonPagedPool, sizeof(KEVENT), TAG_IO);
|
2009-09-02 21:02:30 +08:00
|
|
|
if (!Event)
|
|
|
|
{
|
|
|
|
/* We failed */
|
|
|
|
ObDereferenceObject(FileObject);
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
}
|
2006-11-08 19:47:44 +08:00
|
|
|
KeInitializeEvent(Event, SynchronizationEvent, FALSE);
|
|
|
|
LocalEvent = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the Device Object */
|
|
|
|
DeviceObject = IoGetRelatedDeviceObject(FileObject);
|
|
|
|
|
|
|
|
/* Clear the event */
|
|
|
|
KeClearEvent(&FileObject->Event);
|
|
|
|
|
|
|
|
/* Allocate the IRP */
|
|
|
|
Irp = IoAllocateIrp(DeviceObject->StackSize, TRUE);
|
|
|
|
if (!Irp) return IopCleanupFailedIrp(FileObject, NULL, Event);
|
|
|
|
|
|
|
|
/* Set up the IRP */
|
|
|
|
Irp->Flags = (LocalEvent) ? IRP_SYNCHRONOUS_API : 0;
|
|
|
|
Irp->UserIosb = (LocalEvent) ? &KernelIosb : IoStatusBlock;
|
|
|
|
Irp->UserEvent = (LocalEvent) ? Event : NULL;
|
|
|
|
Irp->RequestorMode = PreviousMode;
|
|
|
|
Irp->Tail.Overlay.Thread = PsGetCurrentThread();
|
|
|
|
Irp->Tail.Overlay.OriginalFileObject = FileObject;
|
|
|
|
Irp->Overlay.AsynchronousParameters.UserApcRoutine = NULL;
|
|
|
|
|
|
|
|
/* Set up Stack Data */
|
|
|
|
StackPtr = IoGetNextIrpStackLocation(Irp);
|
|
|
|
StackPtr->MajorFunction = IRP_MJ_FLUSH_BUFFERS;
|
|
|
|
StackPtr->FileObject = FileObject;
|
|
|
|
|
|
|
|
/* Call the Driver */
|
|
|
|
Status = IopPerformSynchronousRequest(DeviceObject,
|
|
|
|
Irp,
|
|
|
|
FileObject,
|
|
|
|
FALSE,
|
|
|
|
PreviousMode,
|
|
|
|
!LocalEvent,
|
|
|
|
IopOtherTransfer);
|
|
|
|
|
|
|
|
/* Check if this was async I/O */
|
|
|
|
if (LocalEvent)
|
|
|
|
{
|
|
|
|
/* It was, finalize this request */
|
|
|
|
Status = IopFinalizeAsynchronousIo(Status,
|
|
|
|
Event,
|
|
|
|
Irp,
|
|
|
|
PreviousMode,
|
|
|
|
&KernelIosb,
|
|
|
|
IoStatusBlock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the Status */
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
NtNotifyChangeDirectoryFile(IN HANDLE FileHandle,
|
|
|
|
IN HANDLE EventHandle OPTIONAL,
|
|
|
|
IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
|
|
|
|
IN PVOID ApcContext OPTIONAL,
|
|
|
|
OUT PIO_STATUS_BLOCK IoStatusBlock,
|
|
|
|
OUT PVOID Buffer,
|
|
|
|
IN ULONG BufferSize,
|
|
|
|
IN ULONG CompletionFilter,
|
|
|
|
IN BOOLEAN WatchTree)
|
|
|
|
{
|
|
|
|
PIRP Irp;
|
|
|
|
PKEVENT Event = NULL;
|
|
|
|
PDEVICE_OBJECT DeviceObject;
|
|
|
|
PFILE_OBJECT FileObject;
|
|
|
|
PIO_STACK_LOCATION IoStack;
|
|
|
|
KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
|
2009-08-27 01:31:02 +08:00
|
|
|
NTSTATUS Status;
|
2006-11-08 19:47:44 +08:00
|
|
|
BOOLEAN LockedForSync = FALSE;
|
|
|
|
PAGED_CODE();
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
IOTRACE(IO_API_DEBUG, "FileHandle: %p\n", FileHandle);
|
2006-11-08 19:47:44 +08:00
|
|
|
|
|
|
|
/* Check if we're called from user mode */
|
|
|
|
if (PreviousMode != KernelMode)
|
|
|
|
{
|
|
|
|
/* Enter SEH for probing */
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_TRY
|
2006-11-08 19:47:44 +08:00
|
|
|
{
|
|
|
|
/* Probe the I/O STatus block */
|
|
|
|
ProbeForWriteIoStatusBlock(IoStatusBlock);
|
|
|
|
|
|
|
|
/* Probe the buffer */
|
|
|
|
if (BufferSize) ProbeForWrite(Buffer, BufferSize, sizeof(ULONG));
|
|
|
|
}
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
2006-11-08 19:47:44 +08:00
|
|
|
{
|
2009-08-27 01:31:02 +08:00
|
|
|
/* Return the exception code */
|
|
|
|
_SEH2_YIELD(return _SEH2_GetExceptionCode());
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_END;
|
2006-11-08 19:47:44 +08:00
|
|
|
|
2009-01-03 20:42:29 +08:00
|
|
|
/* Check if CompletionFilter is valid */
|
|
|
|
if (!CompletionFilter || (CompletionFilter & ~FILE_NOTIFY_VALID_MASK))
|
2009-01-03 20:22:14 +08:00
|
|
|
{
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get File Object */
|
|
|
|
Status = ObReferenceObjectByHandle(FileHandle,
|
|
|
|
FILE_LIST_DIRECTORY,
|
|
|
|
IoFileObjectType,
|
|
|
|
PreviousMode,
|
|
|
|
(PVOID*)&FileObject,
|
|
|
|
NULL);
|
|
|
|
if (!NT_SUCCESS(Status)) return Status;
|
|
|
|
|
2021-11-24 20:34:26 +08:00
|
|
|
/* 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;
|
|
|
|
}
|
|
|
|
|
2006-11-08 19:47:44 +08:00
|
|
|
/* Check if we have an event handle */
|
|
|
|
if (EventHandle)
|
|
|
|
{
|
|
|
|
/* Reference it */
|
|
|
|
Status = ObReferenceObjectByHandle(EventHandle,
|
|
|
|
EVENT_MODIFY_STATE,
|
|
|
|
ExEventObjectType,
|
|
|
|
PreviousMode,
|
|
|
|
(PVOID *)&Event,
|
|
|
|
NULL);
|
2009-01-03 21:23:44 +08:00
|
|
|
if (Status != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
ObDereferenceObject(FileObject);
|
|
|
|
return Status;
|
|
|
|
}
|
2006-11-08 19:47:44 +08:00
|
|
|
KeClearEvent(Event);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if we should use Sync IO or not */
|
|
|
|
if (FileObject->Flags & FO_SYNCHRONOUS_IO)
|
|
|
|
{
|
|
|
|
/* Lock it */
|
2018-10-02 15:55:07 +08:00
|
|
|
Status = IopLockFileObject(FileObject, PreviousMode);
|
|
|
|
if (Status != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
if (Event) ObDereferenceObject(Event);
|
|
|
|
ObDereferenceObject(FileObject);
|
|
|
|
return Status;
|
|
|
|
}
|
2006-11-08 19:47:44 +08:00
|
|
|
LockedForSync = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear File Object event */
|
|
|
|
KeClearEvent(&FileObject->Event);
|
|
|
|
|
|
|
|
/* Get the device object */
|
|
|
|
DeviceObject = IoGetRelatedDeviceObject(FileObject);
|
|
|
|
|
|
|
|
/* Allocate the IRP */
|
|
|
|
Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
|
|
|
|
if (!Irp) return IopCleanupFailedIrp(FileObject, Event, NULL);
|
|
|
|
|
|
|
|
/* Set up the IRP */
|
|
|
|
Irp->RequestorMode = PreviousMode;
|
|
|
|
Irp->UserIosb = IoStatusBlock;
|
|
|
|
Irp->UserEvent = Event;
|
2010-08-17 04:18:25 +08:00
|
|
|
Irp->UserBuffer = Buffer;
|
2006-11-08 19:47:44 +08:00
|
|
|
Irp->Tail.Overlay.Thread = PsGetCurrentThread();
|
|
|
|
Irp->Tail.Overlay.OriginalFileObject = FileObject;
|
|
|
|
Irp->Overlay.AsynchronousParameters.UserApcRoutine = ApcRoutine;
|
|
|
|
Irp->Overlay.AsynchronousParameters.UserApcContext = ApcContext;
|
|
|
|
|
|
|
|
/* Set up Stack Data */
|
|
|
|
IoStack = IoGetNextIrpStackLocation(Irp);
|
|
|
|
IoStack->MajorFunction = IRP_MJ_DIRECTORY_CONTROL;
|
|
|
|
IoStack->MinorFunction = IRP_MN_NOTIFY_CHANGE_DIRECTORY;
|
|
|
|
IoStack->FileObject = FileObject;
|
|
|
|
|
|
|
|
/* Set parameters */
|
|
|
|
IoStack->Parameters.NotifyDirectory.CompletionFilter = CompletionFilter;
|
|
|
|
IoStack->Parameters.NotifyDirectory.Length = BufferSize;
|
|
|
|
if (WatchTree) IoStack->Flags = SL_WATCH_TREE;
|
|
|
|
|
|
|
|
/* Perform the call */
|
|
|
|
return IopPerformSynchronousRequest(DeviceObject,
|
|
|
|
Irp,
|
|
|
|
FileObject,
|
|
|
|
FALSE,
|
|
|
|
PreviousMode,
|
|
|
|
LockedForSync,
|
|
|
|
IopOtherTransfer);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
NtLockFile(IN HANDLE FileHandle,
|
|
|
|
IN HANDLE EventHandle OPTIONAL,
|
|
|
|
IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
|
|
|
|
IN PVOID ApcContext OPTIONAL,
|
|
|
|
OUT PIO_STATUS_BLOCK IoStatusBlock,
|
|
|
|
IN PLARGE_INTEGER ByteOffset,
|
|
|
|
IN PLARGE_INTEGER Length,
|
|
|
|
IN ULONG Key,
|
|
|
|
IN BOOLEAN FailImmediately,
|
|
|
|
IN BOOLEAN ExclusiveLock)
|
|
|
|
{
|
|
|
|
PFILE_OBJECT FileObject;
|
|
|
|
PLARGE_INTEGER LocalLength = NULL;
|
2007-04-02 23:08:54 +08:00
|
|
|
PIRP Irp;
|
|
|
|
PIO_STACK_LOCATION StackPtr;
|
|
|
|
PDEVICE_OBJECT DeviceObject;
|
2006-11-08 19:47:44 +08:00
|
|
|
PKEVENT Event = NULL;
|
|
|
|
BOOLEAN LockedForSync = FALSE;
|
|
|
|
KPROCESSOR_MODE PreviousMode = KeGetPreviousMode();
|
|
|
|
LARGE_INTEGER CapturedByteOffset, CapturedLength;
|
2009-08-27 01:31:02 +08:00
|
|
|
NTSTATUS Status;
|
2006-11-08 19:47:44 +08:00
|
|
|
OBJECT_HANDLE_INFORMATION HandleInformation;
|
2015-05-19 03:47:11 +08:00
|
|
|
PFAST_IO_DISPATCH FastIoDispatch;
|
2006-11-08 19:47:44 +08:00
|
|
|
PAGED_CODE();
|
|
|
|
CapturedByteOffset.QuadPart = 0;
|
|
|
|
CapturedLength.QuadPart = 0;
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
IOTRACE(IO_API_DEBUG, "FileHandle: %p\n", FileHandle);
|
2006-11-08 19:47:44 +08:00
|
|
|
|
|
|
|
/* Get File Object */
|
|
|
|
Status = ObReferenceObjectByHandle(FileHandle,
|
|
|
|
0,
|
|
|
|
IoFileObjectType,
|
|
|
|
PreviousMode,
|
|
|
|
(PVOID*)&FileObject,
|
|
|
|
&HandleInformation);
|
|
|
|
if (!NT_SUCCESS(Status)) return Status;
|
|
|
|
|
|
|
|
/* Check if we're called from user mode */
|
|
|
|
if (PreviousMode != KernelMode)
|
|
|
|
{
|
2021-11-24 20:34:26 +08:00
|
|
|
/* 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;
|
|
|
|
}
|
|
|
|
|
2006-11-08 19:47:44 +08:00
|
|
|
/* Must have either FILE_READ_DATA or FILE_WRITE_DATA access */
|
|
|
|
if (!(HandleInformation.GrantedAccess &
|
|
|
|
(FILE_WRITE_DATA | FILE_READ_DATA)))
|
|
|
|
{
|
|
|
|
ObDereferenceObject(FileObject);
|
|
|
|
return STATUS_ACCESS_DENIED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Enter SEH for probing */
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_TRY
|
2006-11-08 19:47:44 +08:00
|
|
|
{
|
|
|
|
/* Probe the I/O STatus block */
|
|
|
|
ProbeForWriteIoStatusBlock(IoStatusBlock);
|
|
|
|
|
|
|
|
/* Probe and capture the large integers */
|
|
|
|
CapturedByteOffset = ProbeForReadLargeInteger(ByteOffset);
|
|
|
|
CapturedLength = ProbeForReadLargeInteger(Length);
|
|
|
|
}
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
2006-11-08 19:47:44 +08:00
|
|
|
{
|
|
|
|
/* Dereference the object and return exception code */
|
|
|
|
ObDereferenceObject(FileObject);
|
2009-08-27 01:31:02 +08:00
|
|
|
_SEH2_YIELD(return _SEH2_GetExceptionCode());
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
2009-08-27 01:31:02 +08:00
|
|
|
_SEH2_END;
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Otherwise, capture them directly */
|
|
|
|
CapturedByteOffset = *ByteOffset;
|
|
|
|
CapturedLength = *Length;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if we have an event handle */
|
|
|
|
if (EventHandle)
|
|
|
|
{
|
|
|
|
/* Reference it */
|
|
|
|
Status = ObReferenceObjectByHandle(EventHandle,
|
|
|
|
EVENT_MODIFY_STATE,
|
|
|
|
ExEventObjectType,
|
|
|
|
PreviousMode,
|
|
|
|
(PVOID *)&Event,
|
|
|
|
NULL);
|
|
|
|
if (Status != STATUS_SUCCESS) return Status;
|
|
|
|
KeClearEvent(Event);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the device object */
|
|
|
|
DeviceObject = IoGetRelatedDeviceObject(FileObject);
|
|
|
|
|
2015-05-19 03:47:11 +08:00
|
|
|
/* Try to do it the FastIO way if possible */
|
|
|
|
FastIoDispatch = DeviceObject->DriverObject->FastIoDispatch;
|
|
|
|
if (FastIoDispatch != NULL && FastIoDispatch->FastIoLock != NULL)
|
|
|
|
{
|
|
|
|
IO_STATUS_BLOCK KernelIosb;
|
|
|
|
|
|
|
|
if (FastIoDispatch->FastIoLock(FileObject,
|
|
|
|
&CapturedByteOffset,
|
|
|
|
&CapturedLength,
|
|
|
|
PsGetCurrentProcess(),
|
|
|
|
Key,
|
|
|
|
FailImmediately,
|
|
|
|
ExclusiveLock,
|
|
|
|
&KernelIosb,
|
|
|
|
DeviceObject))
|
|
|
|
{
|
|
|
|
/* Write the IOSB back */
|
|
|
|
_SEH2_TRY
|
|
|
|
{
|
|
|
|
*IoStatusBlock = KernelIosb;
|
|
|
|
}
|
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
|
|
|
KernelIosb.Status = _SEH2_GetExceptionCode();
|
|
|
|
}
|
|
|
|
_SEH2_END;
|
|
|
|
|
|
|
|
/* If we had an event, signal it */
|
|
|
|
if (EventHandle)
|
|
|
|
{
|
|
|
|
KeSetEvent(Event, IO_NO_INCREMENT, FALSE);
|
|
|
|
ObDereferenceObject(Event);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set completion if required */
|
|
|
|
if (FileObject->CompletionContext != NULL && ApcContext != NULL)
|
|
|
|
{
|
|
|
|
if (!NT_SUCCESS(IoSetIoCompletion(FileObject->CompletionContext->Port,
|
|
|
|
FileObject->CompletionContext->Key,
|
|
|
|
ApcContext,
|
|
|
|
KernelIosb.Status,
|
|
|
|
KernelIosb.Information,
|
|
|
|
TRUE)))
|
|
|
|
{
|
|
|
|
KernelIosb.Status = STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FileObject->LockOperation = TRUE;
|
|
|
|
|
|
|
|
/* We're done with FastIO! */
|
|
|
|
ObDereferenceObject(FileObject);
|
|
|
|
return KernelIosb.Status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-08 19:47:44 +08:00
|
|
|
/* Check if we should use Sync IO or not */
|
|
|
|
if (FileObject->Flags & FO_SYNCHRONOUS_IO)
|
|
|
|
{
|
|
|
|
/* Lock it */
|
2018-10-02 15:55:07 +08:00
|
|
|
Status = IopLockFileObject(FileObject, PreviousMode);
|
|
|
|
if (Status != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
if (Event) ObDereferenceObject(Event);
|
|
|
|
ObDereferenceObject(FileObject);
|
|
|
|
return Status;
|
|
|
|
}
|
2006-11-08 19:47:44 +08:00
|
|
|
LockedForSync = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear File Object event */
|
|
|
|
KeClearEvent(&FileObject->Event);
|
|
|
|
FileObject->LockOperation = TRUE;
|
|
|
|
|
|
|
|
/* Allocate the IRP */
|
|
|
|
Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
|
|
|
|
if (!Irp) return IopCleanupFailedIrp(FileObject, Event, NULL);
|
|
|
|
|
|
|
|
/* Set up the IRP */
|
|
|
|
Irp->RequestorMode = PreviousMode;
|
|
|
|
Irp->UserIosb = IoStatusBlock;
|
|
|
|
Irp->UserEvent = Event;
|
|
|
|
Irp->Tail.Overlay.Thread = PsGetCurrentThread();
|
|
|
|
Irp->Tail.Overlay.OriginalFileObject = FileObject;
|
|
|
|
Irp->Overlay.AsynchronousParameters.UserApcRoutine = ApcRoutine;
|
|
|
|
Irp->Overlay.AsynchronousParameters.UserApcContext = ApcContext;
|
|
|
|
|
|
|
|
/* Set up Stack Data */
|
|
|
|
StackPtr = IoGetNextIrpStackLocation(Irp);
|
|
|
|
StackPtr->MajorFunction = IRP_MJ_LOCK_CONTROL;
|
|
|
|
StackPtr->MinorFunction = IRP_MN_LOCK;
|
|
|
|
StackPtr->FileObject = FileObject;
|
|
|
|
|
2012-09-30 06:44:48 +08:00
|
|
|
/* Allocate local buffer */
|
|
|
|
LocalLength = ExAllocatePoolWithTag(NonPagedPool,
|
|
|
|
sizeof(LARGE_INTEGER),
|
|
|
|
TAG_LOCK);
|
|
|
|
if (!LocalLength)
|
2006-11-08 19:47:44 +08:00
|
|
|
{
|
2012-09-30 06:44:48 +08:00
|
|
|
/* Allocating failed, clean up and return failure */
|
2006-11-08 19:47:44 +08:00
|
|
|
IopCleanupAfterException(FileObject, Irp, Event, NULL);
|
2012-09-30 06:44:48 +08:00
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
2012-09-30 06:44:48 +08:00
|
|
|
|
|
|
|
/* Set the length */
|
|
|
|
*LocalLength = CapturedLength;
|
|
|
|
Irp->Tail.Overlay.AuxiliaryBuffer = (PVOID)LocalLength;
|
|
|
|
StackPtr->Parameters.LockControl.Length = LocalLength;
|
2006-11-08 19:47:44 +08:00
|
|
|
|
|
|
|
/* Set Parameters */
|
|
|
|
StackPtr->Parameters.LockControl.ByteOffset = CapturedByteOffset;
|
|
|
|
StackPtr->Parameters.LockControl.Key = Key;
|
|
|
|
|
|
|
|
/* Set Flags */
|
|
|
|
if (FailImmediately) StackPtr->Flags = SL_FAIL_IMMEDIATELY;
|
|
|
|
if (ExclusiveLock) StackPtr->Flags |= SL_EXCLUSIVE_LOCK;
|
|
|
|
|
|
|
|
/* Perform the call */
|
|
|
|
return IopPerformSynchronousRequest(DeviceObject,
|
|
|
|
Irp,
|
|
|
|
FileObject,
|
|
|
|
FALSE,
|
|
|
|
PreviousMode,
|
|
|
|
LockedForSync,
|
|
|
|
IopOtherTransfer);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
NtQueryDirectoryFile(IN HANDLE FileHandle,
|
|
|
|
IN HANDLE EventHandle OPTIONAL,
|
|
|
|
IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
|
|
|
|
IN PVOID ApcContext OPTIONAL,
|
|
|
|
OUT PIO_STATUS_BLOCK IoStatusBlock,
|
|
|
|
OUT PVOID FileInformation,
|
|
|
|
IN ULONG Length,
|
|
|
|
IN FILE_INFORMATION_CLASS FileInformationClass,
|
|
|
|
IN BOOLEAN ReturnSingleEntry,
|
|
|
|
IN PUNICODE_STRING FileName OPTIONAL,
|
|
|
|
IN BOOLEAN RestartScan)
|
|
|
|
{
|
2007-04-02 23:08:54 +08:00
|
|
|
PIRP Irp;
|
|
|
|
PDEVICE_OBJECT DeviceObject;
|
2006-11-08 19:47:44 +08:00
|
|
|
PFILE_OBJECT FileObject;
|
|
|
|
PIO_STACK_LOCATION StackPtr;
|
|
|
|
KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
|
2009-08-27 01:31:02 +08:00
|
|
|
NTSTATUS Status;
|
2006-11-08 19:47:44 +08:00
|
|
|
BOOLEAN LockedForSynch = FALSE;
|
|
|
|
PKEVENT Event = NULL;
|
2012-09-30 06:44:48 +08:00
|
|
|
volatile PVOID AuxBuffer = NULL;
|
2006-11-08 19:47:44 +08:00
|
|
|
PMDL Mdl;
|
|
|
|
UNICODE_STRING CapturedFileName;
|
|
|
|
PUNICODE_STRING SearchPattern;
|
|
|
|
PAGED_CODE();
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
IOTRACE(IO_API_DEBUG, "FileHandle: %p\n", FileHandle);
|
2006-11-08 19:47:44 +08:00
|
|
|
|
|
|
|
/* Check if we came from user mode */
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
if (PreviousMode != KernelMode)
|
2006-11-08 19:47:44 +08:00
|
|
|
{
|
|
|
|
/* Enter SEH for probing */
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_TRY
|
2006-11-08 19:47:44 +08:00
|
|
|
{
|
|
|
|
/* Probe the I/O Status Block */
|
|
|
|
ProbeForWriteIoStatusBlock(IoStatusBlock);
|
|
|
|
|
|
|
|
/* Probe the file information */
|
|
|
|
ProbeForWrite(FileInformation, Length, sizeof(ULONG));
|
|
|
|
|
|
|
|
/* Check if we have a file name */
|
|
|
|
if (FileName)
|
|
|
|
{
|
|
|
|
/* Capture it */
|
|
|
|
CapturedFileName = ProbeForReadUnicodeString(FileName);
|
|
|
|
if (CapturedFileName.Length)
|
|
|
|
{
|
|
|
|
/* Probe its buffer */
|
|
|
|
ProbeForRead(CapturedFileName.Buffer,
|
|
|
|
CapturedFileName.Length,
|
|
|
|
1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate the auxiliary buffer */
|
|
|
|
AuxBuffer = ExAllocatePoolWithTag(NonPagedPool,
|
|
|
|
CapturedFileName.Length +
|
|
|
|
sizeof(UNICODE_STRING),
|
|
|
|
TAG_SYSB);
|
|
|
|
RtlCopyMemory((PVOID)((ULONG_PTR)AuxBuffer +
|
|
|
|
sizeof(UNICODE_STRING)),
|
|
|
|
CapturedFileName.Buffer,
|
|
|
|
CapturedFileName.Length);
|
|
|
|
|
|
|
|
/* Setup the search pattern */
|
|
|
|
SearchPattern = (PUNICODE_STRING)AuxBuffer;
|
|
|
|
SearchPattern->Buffer = (PWCHAR)((ULONG_PTR)AuxBuffer +
|
|
|
|
sizeof(UNICODE_STRING));
|
|
|
|
SearchPattern->Length = CapturedFileName.Length;
|
|
|
|
SearchPattern->MaximumLength = CapturedFileName.Length;
|
|
|
|
}
|
|
|
|
}
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
2006-11-08 19:47:44 +08:00
|
|
|
{
|
2009-08-27 01:31:02 +08:00
|
|
|
/* Free buffer and return the exception code */
|
2012-09-28 20:17:23 +08:00
|
|
|
if (AuxBuffer) ExFreePoolWithTag(AuxBuffer, TAG_SYSB);
|
2009-08-27 01:31:02 +08:00
|
|
|
_SEH2_YIELD(return _SEH2_GetExceptionCode());
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_END;
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
|
|
|
|
2020-12-10 18:30:01 +08:00
|
|
|
/* Check input parameters */
|
|
|
|
|
|
|
|
switch (FileInformationClass)
|
|
|
|
{
|
|
|
|
#define CHECK_LENGTH(class, struct) \
|
|
|
|
case class: \
|
|
|
|
if (Length < sizeof(struct)) \
|
|
|
|
return STATUS_INFO_LENGTH_MISMATCH; \
|
|
|
|
break
|
|
|
|
CHECK_LENGTH(FileDirectoryInformation, FILE_DIRECTORY_INFORMATION);
|
|
|
|
CHECK_LENGTH(FileFullDirectoryInformation, FILE_FULL_DIR_INFORMATION);
|
|
|
|
CHECK_LENGTH(FileIdFullDirectoryInformation, FILE_ID_FULL_DIR_INFORMATION);
|
|
|
|
CHECK_LENGTH(FileNamesInformation, FILE_NAMES_INFORMATION);
|
|
|
|
CHECK_LENGTH(FileBothDirectoryInformation, FILE_BOTH_DIR_INFORMATION);
|
|
|
|
CHECK_LENGTH(FileIdBothDirectoryInformation, FILE_ID_BOTH_DIR_INFORMATION);
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
#undef CHECK_LENGTH
|
|
|
|
}
|
|
|
|
|
2006-11-08 19:47:44 +08:00
|
|
|
/* Get File Object */
|
|
|
|
Status = ObReferenceObjectByHandle(FileHandle,
|
|
|
|
FILE_LIST_DIRECTORY,
|
|
|
|
IoFileObjectType,
|
|
|
|
PreviousMode,
|
|
|
|
(PVOID *)&FileObject,
|
|
|
|
NULL);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* Fail */
|
2012-09-28 20:17:23 +08:00
|
|
|
if (AuxBuffer) ExFreePoolWithTag(AuxBuffer, TAG_SYSB);
|
2006-11-08 19:47:44 +08:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2017-05-03 05:32:20 +08:00
|
|
|
/* Are there two associated completion routines? */
|
|
|
|
if (FileObject->CompletionContext != NULL && ApcRoutine != NULL)
|
|
|
|
{
|
|
|
|
ObDereferenceObject(FileObject);
|
|
|
|
if (AuxBuffer) ExFreePoolWithTag(AuxBuffer, TAG_SYSB);
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
2006-11-08 19:47:44 +08:00
|
|
|
/* Check if we have an even handle */
|
|
|
|
if (EventHandle)
|
|
|
|
{
|
|
|
|
/* Get its pointer */
|
|
|
|
Status = ObReferenceObjectByHandle(EventHandle,
|
|
|
|
EVENT_MODIFY_STATE,
|
|
|
|
ExEventObjectType,
|
|
|
|
PreviousMode,
|
|
|
|
(PVOID *)&Event,
|
|
|
|
NULL);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* Fail */
|
2017-05-03 05:32:20 +08:00
|
|
|
if (AuxBuffer) ExFreePoolWithTag(AuxBuffer, TAG_SYSB);
|
2006-11-08 19:47:44 +08:00
|
|
|
ObDereferenceObject(FileObject);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear it */
|
|
|
|
KeClearEvent(Event);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if this is a file that was opened for Synch I/O */
|
|
|
|
if (FileObject->Flags & FO_SYNCHRONOUS_IO)
|
|
|
|
{
|
|
|
|
/* Lock it */
|
2018-10-02 15:55:07 +08:00
|
|
|
Status = IopLockFileObject(FileObject, PreviousMode);
|
|
|
|
if (Status != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
if (Event) ObDereferenceObject(Event);
|
|
|
|
ObDereferenceObject(FileObject);
|
|
|
|
if (AuxBuffer) ExFreePoolWithTag(AuxBuffer, TAG_SYSB);
|
|
|
|
return Status;
|
|
|
|
}
|
2006-11-08 19:47:44 +08:00
|
|
|
|
|
|
|
/* Remember to unlock later */
|
|
|
|
LockedForSynch = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the device object */
|
|
|
|
DeviceObject = IoGetRelatedDeviceObject(FileObject);
|
|
|
|
|
|
|
|
/* Clear the File Object's event */
|
|
|
|
KeClearEvent(&FileObject->Event);
|
|
|
|
|
|
|
|
/* Allocate the IRP */
|
|
|
|
Irp = IoAllocateIrp(DeviceObject->StackSize, TRUE);
|
|
|
|
if (!Irp) return IopCleanupFailedIrp(FileObject, EventHandle, AuxBuffer);
|
|
|
|
|
|
|
|
/* Set up the IRP */
|
|
|
|
Irp->RequestorMode = PreviousMode;
|
|
|
|
Irp->UserIosb = IoStatusBlock;
|
|
|
|
Irp->UserEvent = Event;
|
|
|
|
Irp->Tail.Overlay.Thread = PsGetCurrentThread();
|
|
|
|
Irp->Tail.Overlay.OriginalFileObject = FileObject;
|
|
|
|
Irp->Overlay.AsynchronousParameters.UserApcRoutine = ApcRoutine;
|
|
|
|
Irp->Overlay.AsynchronousParameters.UserApcContext = ApcContext;
|
|
|
|
Irp->MdlAddress = NULL;
|
|
|
|
Irp->Tail.Overlay.AuxiliaryBuffer = AuxBuffer;
|
|
|
|
Irp->AssociatedIrp.SystemBuffer = NULL;
|
|
|
|
|
|
|
|
/* Check if this is buffered I/O */
|
|
|
|
if (DeviceObject->Flags & DO_BUFFERED_IO)
|
|
|
|
{
|
2024-04-22 16:50:59 +08:00
|
|
|
/* Enter SEH (ExAllocatePoolWithQuotaTag raises on failure!) */
|
|
|
|
_SEH2_TRY
|
|
|
|
{
|
|
|
|
/* Allocate a buffer */
|
|
|
|
Irp->AssociatedIrp.SystemBuffer =
|
|
|
|
ExAllocatePoolWithQuotaTag(NonPagedPool, Length, TAG_SYSB);
|
|
|
|
}
|
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
2006-11-08 19:47:44 +08:00
|
|
|
{
|
2009-08-27 01:31:02 +08:00
|
|
|
/* Allocating failed, clean up and return the exception code */
|
2006-11-08 19:47:44 +08:00
|
|
|
IopCleanupAfterException(FileObject, Irp, Event, NULL);
|
2012-09-28 20:17:23 +08:00
|
|
|
if (AuxBuffer) ExFreePoolWithTag(AuxBuffer, TAG_SYSB);
|
2006-11-08 19:47:44 +08:00
|
|
|
|
2009-08-27 01:31:02 +08:00
|
|
|
/* Return the exception code */
|
2024-04-22 16:50:59 +08:00
|
|
|
return _SEH2_GetExceptionCode();
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
2024-04-22 16:50:59 +08:00
|
|
|
_SEH2_END;
|
2006-11-08 19:47:44 +08:00
|
|
|
|
|
|
|
/* Set the buffer and flags */
|
|
|
|
Irp->UserBuffer = FileInformation;
|
|
|
|
Irp->Flags = (IRP_BUFFERED_IO |
|
|
|
|
IRP_DEALLOCATE_BUFFER |
|
|
|
|
IRP_INPUT_OPERATION);
|
|
|
|
}
|
|
|
|
else if (DeviceObject->Flags & DO_DIRECT_IO)
|
|
|
|
{
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_TRY
|
2008-01-30 21:33:16 +08:00
|
|
|
{
|
|
|
|
/* Allocate an MDL */
|
|
|
|
Mdl = IoAllocateMdl(FileInformation, Length, FALSE, TRUE, Irp);
|
2009-09-02 21:02:30 +08:00
|
|
|
if (!Mdl) ExRaiseStatus(STATUS_INSUFFICIENT_RESOURCES);
|
2008-01-30 21:33:16 +08:00
|
|
|
MmProbeAndLockPages(Mdl, PreviousMode, IoWriteAccess);
|
|
|
|
}
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
2008-01-30 21:33:16 +08:00
|
|
|
{
|
2009-08-27 01:31:02 +08:00
|
|
|
/* Allocating failed, clean up and return the exception code */
|
2008-01-30 21:33:16 +08:00
|
|
|
IopCleanupAfterException(FileObject, Irp, Event, NULL);
|
2009-08-27 01:31:02 +08:00
|
|
|
_SEH2_YIELD(return _SEH2_GetExceptionCode());
|
2008-01-30 21:33:16 +08:00
|
|
|
}
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_END;
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* No allocation flags, and use the buffer directly */
|
|
|
|
Irp->UserBuffer = FileInformation;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set up Stack Data */
|
|
|
|
StackPtr = IoGetNextIrpStackLocation(Irp);
|
|
|
|
StackPtr->FileObject = FileObject;
|
|
|
|
StackPtr->MajorFunction = IRP_MJ_DIRECTORY_CONTROL;
|
|
|
|
StackPtr->MinorFunction = IRP_MN_QUERY_DIRECTORY;
|
|
|
|
|
|
|
|
/* Set Parameters */
|
|
|
|
StackPtr->Parameters.QueryDirectory.FileInformationClass =
|
|
|
|
FileInformationClass;
|
|
|
|
StackPtr->Parameters.QueryDirectory.FileName = AuxBuffer;
|
|
|
|
StackPtr->Parameters.QueryDirectory.FileIndex = 0;
|
|
|
|
StackPtr->Parameters.QueryDirectory.Length = Length;
|
|
|
|
StackPtr->Flags = 0;
|
|
|
|
if (RestartScan) StackPtr->Flags = SL_RESTART_SCAN;
|
|
|
|
if (ReturnSingleEntry) StackPtr->Flags |= SL_RETURN_SINGLE_ENTRY;
|
|
|
|
|
|
|
|
/* Set deferred I/O */
|
|
|
|
Irp->Flags |= IRP_DEFER_IO_COMPLETION;
|
|
|
|
|
|
|
|
/* Perform the call */
|
|
|
|
return IopPerformSynchronousRequest(DeviceObject,
|
|
|
|
Irp,
|
|
|
|
FileObject,
|
|
|
|
TRUE,
|
|
|
|
PreviousMode,
|
|
|
|
LockedForSynch,
|
|
|
|
IopOtherTransfer);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @unimplemented
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
NtQueryEaFile(IN HANDLE FileHandle,
|
|
|
|
OUT PIO_STATUS_BLOCK IoStatusBlock,
|
|
|
|
OUT PVOID Buffer,
|
|
|
|
IN ULONG Length,
|
|
|
|
IN BOOLEAN ReturnSingleEntry,
|
|
|
|
IN PVOID EaList OPTIONAL,
|
|
|
|
IN ULONG EaListLength,
|
|
|
|
IN PULONG EaIndex OPTIONAL,
|
|
|
|
IN BOOLEAN RestartScan)
|
|
|
|
{
|
|
|
|
UNIMPLEMENTED;
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
NtQueryInformationFile(IN HANDLE FileHandle,
|
|
|
|
OUT PIO_STATUS_BLOCK IoStatusBlock,
|
|
|
|
IN PVOID FileInformation,
|
|
|
|
IN ULONG Length,
|
|
|
|
IN FILE_INFORMATION_CLASS FileInformationClass)
|
|
|
|
{
|
|
|
|
OBJECT_HANDLE_INFORMATION HandleInformation;
|
|
|
|
PFILE_OBJECT FileObject;
|
2009-08-27 01:31:02 +08:00
|
|
|
NTSTATUS Status;
|
2007-04-02 23:08:54 +08:00
|
|
|
PIRP Irp;
|
|
|
|
PDEVICE_OBJECT DeviceObject;
|
|
|
|
PIO_STACK_LOCATION StackPtr;
|
2006-11-08 19:47:44 +08:00
|
|
|
KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
|
|
|
|
PKEVENT Event = NULL;
|
|
|
|
BOOLEAN LocalEvent = FALSE;
|
|
|
|
PKNORMAL_ROUTINE NormalRoutine;
|
|
|
|
PVOID NormalContext;
|
|
|
|
KIRQL OldIrql;
|
|
|
|
IO_STATUS_BLOCK KernelIosb;
|
2015-02-16 07:06:30 +08:00
|
|
|
BOOLEAN CallDriver = TRUE;
|
|
|
|
PFILE_ACCESS_INFORMATION AccessBuffer;
|
2015-02-16 23:33:34 +08:00
|
|
|
PFILE_MODE_INFORMATION ModeBuffer;
|
2015-02-16 07:06:30 +08:00
|
|
|
PFILE_ALIGNMENT_INFORMATION AlignmentBuffer;
|
2015-02-21 22:19:16 +08:00
|
|
|
PFILE_ALL_INFORMATION AllBuffer;
|
2015-05-19 03:47:11 +08:00
|
|
|
PFAST_IO_DISPATCH FastIoDispatch;
|
2009-09-02 21:02:30 +08:00
|
|
|
PAGED_CODE();
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
IOTRACE(IO_API_DEBUG, "FileHandle: %p\n", FileHandle);
|
2006-11-08 19:47:44 +08:00
|
|
|
|
|
|
|
/* Check if we're called from user mode */
|
|
|
|
if (PreviousMode != KernelMode)
|
|
|
|
{
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
/* Validate the information class */
|
2019-01-19 18:35:18 +08:00
|
|
|
if ((FileInformationClass < 0) ||
|
|
|
|
(FileInformationClass >= FileMaximumInformation) ||
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
!(IopQueryOperationLength[FileInformationClass]))
|
|
|
|
{
|
|
|
|
/* Invalid class */
|
|
|
|
return STATUS_INVALID_INFO_CLASS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Validate the length */
|
|
|
|
if (Length < IopQueryOperationLength[FileInformationClass])
|
|
|
|
{
|
|
|
|
/* Invalid length */
|
|
|
|
return STATUS_INFO_LENGTH_MISMATCH;
|
|
|
|
}
|
|
|
|
|
2006-11-08 19:47:44 +08:00
|
|
|
/* Enter SEH for probing */
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_TRY
|
2006-11-08 19:47:44 +08:00
|
|
|
{
|
|
|
|
/* Probe the I/O Status block */
|
|
|
|
ProbeForWriteIoStatusBlock(IoStatusBlock);
|
|
|
|
|
|
|
|
/* Probe the information */
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
ProbeForWrite(FileInformation, Length, sizeof(ULONG));
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
2006-11-08 19:47:44 +08:00
|
|
|
{
|
2009-08-27 01:31:02 +08:00
|
|
|
/* Return the exception code */
|
|
|
|
_SEH2_YIELD(return _SEH2_GetExceptionCode());
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_END;
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
2017-02-26 19:27:24 +08:00
|
|
|
#if DBG
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Validate the information class */
|
2019-01-19 18:35:18 +08:00
|
|
|
if ((FileInformationClass < 0) ||
|
|
|
|
(FileInformationClass >= FileMaximumInformation) ||
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
!(IopQueryOperationLength[FileInformationClass]))
|
|
|
|
{
|
|
|
|
/* Invalid class */
|
|
|
|
return STATUS_INVALID_INFO_CLASS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Validate the length */
|
|
|
|
if (Length < IopQueryOperationLength[FileInformationClass])
|
|
|
|
{
|
|
|
|
/* Invalid length */
|
|
|
|
return STATUS_INFO_LENGTH_MISMATCH;
|
|
|
|
}
|
|
|
|
}
|
2017-02-26 19:27:24 +08:00
|
|
|
#endif
|
2006-11-08 19:47:44 +08:00
|
|
|
|
|
|
|
/* Reference the Handle */
|
|
|
|
Status = ObReferenceObjectByHandle(FileHandle,
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
IopQueryOperationAccess
|
|
|
|
[FileInformationClass],
|
2006-11-08 19:47:44 +08:00
|
|
|
IoFileObjectType,
|
|
|
|
PreviousMode,
|
|
|
|
(PVOID *)&FileObject,
|
|
|
|
&HandleInformation);
|
|
|
|
if (!NT_SUCCESS(Status)) return Status;
|
|
|
|
|
|
|
|
/* Check if this is a direct open or not */
|
|
|
|
if (FileObject->Flags & FO_DIRECT_DEVICE_OPEN)
|
|
|
|
{
|
|
|
|
/* Get the device object */
|
|
|
|
DeviceObject = IoGetAttachedDevice(FileObject->DeviceObject);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Get the device object */
|
|
|
|
DeviceObject = IoGetRelatedDeviceObject(FileObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if this is a file that was opened for Synch I/O */
|
|
|
|
if (FileObject->Flags & FO_SYNCHRONOUS_IO)
|
|
|
|
{
|
|
|
|
/* Lock it */
|
2018-10-02 15:55:07 +08:00
|
|
|
Status = IopLockFileObject(FileObject, PreviousMode);
|
|
|
|
if (Status != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
ObDereferenceObject(FileObject);
|
|
|
|
return Status;
|
|
|
|
}
|
2006-11-08 19:47:44 +08:00
|
|
|
|
|
|
|
/* Check if the caller just wants the position */
|
|
|
|
if (FileInformationClass == FilePositionInformation)
|
|
|
|
{
|
|
|
|
/* Protect write in SEH */
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_TRY
|
2006-11-08 19:47:44 +08:00
|
|
|
{
|
|
|
|
/* Write the offset */
|
|
|
|
((PFILE_POSITION_INFORMATION)FileInformation)->
|
|
|
|
CurrentByteOffset = FileObject->CurrentByteOffset;
|
|
|
|
|
|
|
|
/* Fill out the I/O Status Block */
|
|
|
|
IoStatusBlock->Information = sizeof(FILE_POSITION_INFORMATION);
|
|
|
|
Status = IoStatusBlock->Status = STATUS_SUCCESS;
|
|
|
|
}
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
2006-11-08 19:47:44 +08:00
|
|
|
{
|
|
|
|
/* Get the exception code */
|
2008-11-24 21:40:26 +08:00
|
|
|
Status = _SEH2_GetExceptionCode();
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_END;
|
2006-11-08 19:47:44 +08:00
|
|
|
|
|
|
|
/* Release the file lock, dereference the file and return */
|
|
|
|
IopUnlockFileObject(FileObject);
|
|
|
|
ObDereferenceObject(FileObject);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Use local event */
|
|
|
|
Event = ExAllocatePoolWithTag(NonPagedPool, sizeof(KEVENT), TAG_IO);
|
2009-09-02 21:02:30 +08:00
|
|
|
if (!Event)
|
|
|
|
{
|
|
|
|
ObDereferenceObject(FileObject);
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
}
|
2006-11-08 19:47:44 +08:00
|
|
|
KeInitializeEvent(Event, SynchronizationEvent, FALSE);
|
|
|
|
LocalEvent = TRUE;
|
|
|
|
}
|
|
|
|
|
2015-05-19 03:47:11 +08:00
|
|
|
/* Check if FastIO is possible for the two available information classes */
|
|
|
|
FastIoDispatch = DeviceObject->DriverObject->FastIoDispatch;
|
|
|
|
if (FastIoDispatch != NULL &&
|
|
|
|
((FileInformationClass == FileBasicInformation && FastIoDispatch->FastIoQueryBasicInfo != NULL) ||
|
|
|
|
(FileInformationClass == FileStandardInformation && FastIoDispatch->FastIoQueryStandardInfo != NULL)))
|
|
|
|
{
|
|
|
|
BOOLEAN Success = FALSE;
|
|
|
|
|
|
|
|
if (FileInformationClass == FileBasicInformation)
|
|
|
|
{
|
|
|
|
Success = FastIoDispatch->FastIoQueryBasicInfo(FileObject, TRUE,
|
|
|
|
FileInformation,
|
|
|
|
&KernelIosb,
|
|
|
|
DeviceObject);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Success = FastIoDispatch->FastIoQueryStandardInfo(FileObject, TRUE,
|
|
|
|
FileInformation,
|
|
|
|
&KernelIosb,
|
|
|
|
DeviceObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If call succeed */
|
|
|
|
if (Success)
|
|
|
|
{
|
|
|
|
/* Write the IOSB back */
|
|
|
|
_SEH2_TRY
|
|
|
|
{
|
|
|
|
*IoStatusBlock = KernelIosb;
|
|
|
|
}
|
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
|
|
|
KernelIosb.Status = _SEH2_GetExceptionCode();
|
|
|
|
}
|
|
|
|
_SEH2_END;
|
|
|
|
|
2017-03-01 21:10:52 +08:00
|
|
|
/* Free the event if we had one */
|
|
|
|
if (LocalEvent)
|
|
|
|
{
|
|
|
|
ExFreePoolWithTag(Event, TAG_IO);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If FO was locked, unlock it */
|
|
|
|
if (FileObject->Flags & FO_SYNCHRONOUS_IO)
|
|
|
|
{
|
|
|
|
IopUnlockFileObject(FileObject);
|
|
|
|
}
|
2015-05-19 03:47:11 +08:00
|
|
|
|
|
|
|
/* We're done with FastIO! */
|
|
|
|
ObDereferenceObject(FileObject);
|
|
|
|
return KernelIosb.Status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-08 19:47:44 +08:00
|
|
|
/* Clear the File Object event */
|
|
|
|
KeClearEvent(&FileObject->Event);
|
|
|
|
|
|
|
|
/* Allocate the IRP */
|
|
|
|
Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
|
|
|
|
if (!Irp) return IopCleanupFailedIrp(FileObject, NULL, Event);
|
|
|
|
|
|
|
|
/* Set the IRP */
|
|
|
|
Irp->Tail.Overlay.OriginalFileObject = FileObject;
|
|
|
|
Irp->Tail.Overlay.Thread = PsGetCurrentThread();
|
|
|
|
Irp->RequestorMode = PreviousMode;
|
|
|
|
Irp->Overlay.AsynchronousParameters.UserApcRoutine = NULL;
|
|
|
|
Irp->Flags = (LocalEvent) ? IRP_SYNCHRONOUS_API : 0;
|
|
|
|
Irp->UserIosb = (LocalEvent) ? &KernelIosb : IoStatusBlock;
|
|
|
|
Irp->UserEvent = (LocalEvent) ? Event : NULL;
|
|
|
|
Irp->AssociatedIrp.SystemBuffer = NULL;
|
|
|
|
Irp->MdlAddress = NULL;
|
|
|
|
Irp->UserBuffer = FileInformation;
|
|
|
|
|
|
|
|
/* Set the Stack Data */
|
|
|
|
StackPtr = IoGetNextIrpStackLocation(Irp);
|
|
|
|
StackPtr->MajorFunction = IRP_MJ_QUERY_INFORMATION;
|
|
|
|
StackPtr->FileObject = FileObject;
|
|
|
|
|
2024-04-22 16:50:59 +08:00
|
|
|
/* Enter SEH (ExAllocatePoolWithQuotaTag raises on failure!) */
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_TRY
|
2006-11-08 19:47:44 +08:00
|
|
|
{
|
|
|
|
/* Allocate a buffer */
|
|
|
|
Irp->AssociatedIrp.SystemBuffer =
|
2024-04-22 16:50:59 +08:00
|
|
|
ExAllocatePoolWithQuotaTag(NonPagedPool, Length, TAG_SYSB);
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
2006-11-08 19:47:44 +08:00
|
|
|
{
|
2009-08-27 01:31:02 +08:00
|
|
|
/* Allocating failed, clean up and return the exception code */
|
2006-11-08 19:47:44 +08:00
|
|
|
IopCleanupAfterException(FileObject, Irp, NULL, Event);
|
2009-08-27 01:31:02 +08:00
|
|
|
_SEH2_YIELD(return _SEH2_GetExceptionCode());
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_END;
|
2006-11-08 19:47:44 +08:00
|
|
|
|
|
|
|
/* Set the flags */
|
2008-09-08 19:52:33 +08:00
|
|
|
Irp->Flags |= (IRP_BUFFERED_IO |
|
|
|
|
IRP_DEALLOCATE_BUFFER |
|
|
|
|
IRP_INPUT_OPERATION |
|
|
|
|
IRP_DEFER_IO_COMPLETION);
|
2006-11-08 19:47:44 +08:00
|
|
|
|
|
|
|
/* Set the Parameters */
|
|
|
|
StackPtr->Parameters.QueryFile.FileInformationClass = FileInformationClass;
|
|
|
|
StackPtr->Parameters.QueryFile.Length = Length;
|
|
|
|
|
|
|
|
/* Queue the IRP */
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
IopQueueIrpToThread(Irp);
|
2006-11-08 19:47:44 +08:00
|
|
|
|
|
|
|
/* Update operation counts */
|
|
|
|
IopUpdateOperationCount(IopOtherTransfer);
|
|
|
|
|
2015-02-16 07:06:30 +08:00
|
|
|
/* Fill in file information before calling the driver.
|
|
|
|
See 'File System Internals' page 485.*/
|
|
|
|
if (FileInformationClass == FileAccessInformation)
|
|
|
|
{
|
|
|
|
AccessBuffer = Irp->AssociatedIrp.SystemBuffer;
|
|
|
|
AccessBuffer->AccessFlags = HandleInformation.GrantedAccess;
|
|
|
|
Irp->IoStatus.Information = sizeof(FILE_ACCESS_INFORMATION);
|
|
|
|
CallDriver = FALSE;
|
|
|
|
}
|
2015-02-16 23:33:34 +08:00
|
|
|
else if (FileInformationClass == FileModeInformation)
|
|
|
|
{
|
|
|
|
ModeBuffer = Irp->AssociatedIrp.SystemBuffer;
|
|
|
|
ModeBuffer->Mode = IopGetFileMode(FileObject);
|
|
|
|
Irp->IoStatus.Information = sizeof(FILE_MODE_INFORMATION);
|
|
|
|
CallDriver = FALSE;
|
|
|
|
}
|
2015-02-16 07:06:30 +08:00
|
|
|
else if (FileInformationClass == FileAlignmentInformation)
|
|
|
|
{
|
|
|
|
AlignmentBuffer = Irp->AssociatedIrp.SystemBuffer;
|
|
|
|
AlignmentBuffer->AlignmentRequirement = DeviceObject->AlignmentRequirement;
|
|
|
|
Irp->IoStatus.Information = sizeof(FILE_ALIGNMENT_INFORMATION);
|
|
|
|
CallDriver = FALSE;
|
|
|
|
}
|
2015-02-21 22:19:16 +08:00
|
|
|
else if (FileInformationClass == FileAllInformation)
|
|
|
|
{
|
|
|
|
AllBuffer = Irp->AssociatedIrp.SystemBuffer;
|
|
|
|
AllBuffer->AccessInformation.AccessFlags = HandleInformation.GrantedAccess;
|
|
|
|
AllBuffer->ModeInformation.Mode = IopGetFileMode(FileObject);
|
|
|
|
AllBuffer->AlignmentInformation.AlignmentRequirement = DeviceObject->AlignmentRequirement;
|
|
|
|
Irp->IoStatus.Information = sizeof(FILE_ACCESS_INFORMATION) +
|
|
|
|
sizeof(FILE_MODE_INFORMATION) +
|
|
|
|
sizeof(FILE_ALIGNMENT_INFORMATION);
|
|
|
|
}
|
2015-02-16 07:06:30 +08:00
|
|
|
|
2006-11-08 19:47:44 +08:00
|
|
|
/* Call the Driver */
|
2015-02-16 07:06:30 +08:00
|
|
|
if (CallDriver)
|
|
|
|
{
|
|
|
|
Status = IoCallDriver(DeviceObject, Irp);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
Irp->IoStatus.Status = STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2006-11-08 19:47:44 +08:00
|
|
|
if (Status == STATUS_PENDING)
|
|
|
|
{
|
|
|
|
/* Check if this was async I/O */
|
|
|
|
if (LocalEvent)
|
|
|
|
{
|
|
|
|
/* Then to a non-alertable wait */
|
|
|
|
Status = KeWaitForSingleObject(Event,
|
|
|
|
Executive,
|
|
|
|
PreviousMode,
|
|
|
|
FALSE,
|
|
|
|
NULL);
|
|
|
|
if (Status == STATUS_USER_APC)
|
|
|
|
{
|
|
|
|
/* Abort the request */
|
|
|
|
IopAbortInterruptedIrp(Event, Irp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the final status */
|
|
|
|
Status = KernelIosb.Status;
|
|
|
|
|
|
|
|
/* Enter SEH to write the IOSB back */
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_TRY
|
2006-11-08 19:47:44 +08:00
|
|
|
{
|
|
|
|
/* Write it back to the caller */
|
|
|
|
*IoStatusBlock = KernelIosb;
|
|
|
|
}
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
2006-11-08 19:47:44 +08:00
|
|
|
{
|
|
|
|
/* Get the exception code */
|
2008-11-24 21:40:26 +08:00
|
|
|
Status = _SEH2_GetExceptionCode();
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_END;
|
2006-11-08 19:47:44 +08:00
|
|
|
|
|
|
|
/* Free the event */
|
2012-09-28 20:17:23 +08:00
|
|
|
ExFreePoolWithTag(Event, TAG_IO);
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Wait for the IRP */
|
|
|
|
Status = KeWaitForSingleObject(&FileObject->Event,
|
|
|
|
Executive,
|
|
|
|
PreviousMode,
|
2012-07-24 23:32:06 +08:00
|
|
|
(FileObject->Flags &
|
|
|
|
FO_ALERTABLE_IO) != 0,
|
2006-11-08 19:47:44 +08:00
|
|
|
NULL);
|
|
|
|
if ((Status == STATUS_USER_APC) || (Status == STATUS_ALERTED))
|
|
|
|
{
|
|
|
|
/* Abort the request */
|
|
|
|
IopAbortInterruptedIrp(&FileObject->Event, Irp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the final status */
|
|
|
|
Status = FileObject->FinalStatus;
|
|
|
|
|
|
|
|
/* Release the file lock */
|
|
|
|
IopUnlockFileObject(FileObject);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Free the event if we had one */
|
|
|
|
if (LocalEvent)
|
|
|
|
{
|
|
|
|
/* Clear it in the IRP for completion */
|
|
|
|
Irp->UserEvent = NULL;
|
2008-08-31 23:29:21 +08:00
|
|
|
ExFreePoolWithTag(Event, TAG_IO);
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the caller IOSB */
|
|
|
|
Irp->UserIosb = IoStatusBlock;
|
|
|
|
|
|
|
|
/* The IRP wasn't completed, complete it ourselves */
|
2021-10-28 23:17:03 +08:00
|
|
|
NormalRoutine = NULL;
|
|
|
|
NormalContext = NULL;
|
2006-11-08 19:47:44 +08:00
|
|
|
KeRaiseIrql(APC_LEVEL, &OldIrql);
|
|
|
|
IopCompleteRequest(&Irp->Tail.Apc,
|
|
|
|
&NormalRoutine,
|
|
|
|
&NormalContext,
|
|
|
|
(PVOID*)&FileObject,
|
|
|
|
&NormalContext);
|
|
|
|
KeLowerIrql(OldIrql);
|
|
|
|
|
|
|
|
/* Release the file object if we had locked it*/
|
|
|
|
if (!LocalEvent) IopUnlockFileObject(FileObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the Status */
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @unimplemented
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
NtQueryQuotaInformationFile(IN HANDLE FileHandle,
|
|
|
|
OUT PIO_STATUS_BLOCK IoStatusBlock,
|
|
|
|
OUT PVOID Buffer,
|
|
|
|
IN ULONG Length,
|
|
|
|
IN BOOLEAN ReturnSingleEntry,
|
|
|
|
IN PVOID SidList OPTIONAL,
|
|
|
|
IN ULONG SidListLength,
|
|
|
|
IN PSID StartSid OPTIONAL,
|
|
|
|
IN BOOLEAN RestartScan)
|
|
|
|
{
|
|
|
|
UNIMPLEMENTED;
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
NtReadFile(IN HANDLE FileHandle,
|
|
|
|
IN HANDLE Event OPTIONAL,
|
|
|
|
IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
|
|
|
|
IN PVOID ApcContext OPTIONAL,
|
|
|
|
OUT PIO_STATUS_BLOCK IoStatusBlock,
|
|
|
|
OUT PVOID Buffer,
|
|
|
|
IN ULONG Length,
|
|
|
|
IN PLARGE_INTEGER ByteOffset OPTIONAL,
|
|
|
|
IN PULONG Key OPTIONAL)
|
|
|
|
{
|
2009-08-27 01:31:02 +08:00
|
|
|
NTSTATUS Status;
|
2006-11-08 19:47:44 +08:00
|
|
|
PFILE_OBJECT FileObject;
|
2007-04-02 23:08:54 +08:00
|
|
|
PIRP Irp;
|
|
|
|
PDEVICE_OBJECT DeviceObject;
|
2006-11-08 19:47:44 +08:00
|
|
|
PIO_STACK_LOCATION StackPtr;
|
|
|
|
KPROCESSOR_MODE PreviousMode = KeGetPreviousMode();
|
|
|
|
PKEVENT EventObject = NULL;
|
|
|
|
LARGE_INTEGER CapturedByteOffset;
|
|
|
|
ULONG CapturedKey = 0;
|
|
|
|
BOOLEAN Synchronous = FALSE;
|
|
|
|
PMDL Mdl;
|
2015-05-01 21:20:26 +08:00
|
|
|
PFAST_IO_DISPATCH FastIoDispatch;
|
|
|
|
IO_STATUS_BLOCK KernelIosb;
|
|
|
|
BOOLEAN Success;
|
|
|
|
|
2006-11-08 19:47:44 +08:00
|
|
|
PAGED_CODE();
|
|
|
|
CapturedByteOffset.QuadPart = 0;
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
IOTRACE(IO_API_DEBUG, "FileHandle: %p\n", FileHandle);
|
2006-11-08 19:47:44 +08:00
|
|
|
|
2018-10-04 07:16:17 +08:00
|
|
|
/* Get File Object */
|
|
|
|
Status = ObReferenceObjectByHandle(FileHandle,
|
|
|
|
FILE_READ_DATA,
|
|
|
|
IoFileObjectType,
|
|
|
|
PreviousMode,
|
|
|
|
(PVOID*)&FileObject,
|
|
|
|
NULL);
|
|
|
|
if (!NT_SUCCESS(Status)) return Status;
|
|
|
|
|
|
|
|
/* Get the device object */
|
|
|
|
DeviceObject = IoGetRelatedDeviceObject(FileObject);
|
|
|
|
|
2006-11-08 19:47:44 +08:00
|
|
|
/* Validate User-Mode Buffers */
|
2009-08-27 01:31:02 +08:00
|
|
|
if (PreviousMode != KernelMode)
|
2006-11-08 19:47:44 +08:00
|
|
|
{
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_TRY
|
2006-11-08 19:47:44 +08:00
|
|
|
{
|
|
|
|
/* Probe the status block */
|
|
|
|
ProbeForWriteIoStatusBlock(IoStatusBlock);
|
|
|
|
|
|
|
|
/* Probe the read buffer */
|
|
|
|
ProbeForWrite(Buffer, Length, 1);
|
|
|
|
|
|
|
|
/* Check if we got a byte offset */
|
|
|
|
if (ByteOffset)
|
|
|
|
{
|
|
|
|
/* Capture and probe it */
|
|
|
|
CapturedByteOffset = ProbeForReadLargeInteger(ByteOffset);
|
|
|
|
}
|
|
|
|
|
2021-11-24 20:34:26 +08:00
|
|
|
/* 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;
|
|
|
|
}
|
|
|
|
|
2018-10-04 07:16:17 +08:00
|
|
|
/* Perform additional checks for non-cached file access */
|
|
|
|
if (FileObject->Flags & FO_NO_INTERMEDIATE_BUFFERING)
|
|
|
|
{
|
2018-10-04 16:42:13 +08:00
|
|
|
/* Fail if Length is not sector size aligned
|
|
|
|
* Perform a quick check for 2^ sector sizes
|
|
|
|
* If it fails, try a more standard way
|
|
|
|
*/
|
2018-10-04 07:16:17 +08:00
|
|
|
if ((DeviceObject->SectorSize != 0) &&
|
2018-10-04 16:42:13 +08:00
|
|
|
((DeviceObject->SectorSize - 1) & Length) != 0)
|
2018-10-04 07:16:17 +08:00
|
|
|
{
|
2018-10-04 16:42:13 +08:00
|
|
|
if (Length % DeviceObject->SectorSize != 0)
|
|
|
|
{
|
|
|
|
/* Release the file object and and fail */
|
|
|
|
ObDereferenceObject(FileObject);
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
2018-10-04 07:16:17 +08:00
|
|
|
}
|
|
|
|
|
2018-10-04 13:56:23 +08:00
|
|
|
/* Fail if buffer doesn't match alignment requirements */
|
|
|
|
if (((ULONG_PTR)Buffer & DeviceObject->AlignmentRequirement) != 0)
|
|
|
|
{
|
|
|
|
/* Release the file object and and fail */
|
|
|
|
ObDereferenceObject(FileObject);
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
2018-10-04 07:16:17 +08:00
|
|
|
if (ByteOffset)
|
|
|
|
{
|
|
|
|
/* Fail if ByteOffset is not sector size aligned */
|
|
|
|
if ((DeviceObject->SectorSize != 0) &&
|
2018-10-04 16:27:35 +08:00
|
|
|
(CapturedByteOffset.QuadPart % DeviceObject->SectorSize != 0))
|
2018-10-04 07:16:17 +08:00
|
|
|
{
|
|
|
|
/* Release the file object and and fail */
|
|
|
|
ObDereferenceObject(FileObject);
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-08 19:47:44 +08:00
|
|
|
/* Capture and probe the key */
|
|
|
|
if (Key) CapturedKey = ProbeForReadUlong(Key);
|
|
|
|
}
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
2006-11-08 19:47:44 +08:00
|
|
|
{
|
2018-10-04 07:16:17 +08:00
|
|
|
/* Release the file object and return the exception code */
|
|
|
|
ObDereferenceObject(FileObject);
|
2009-08-27 01:31:02 +08:00
|
|
|
_SEH2_YIELD(return _SEH2_GetExceptionCode());
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_END;
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Kernel mode: capture directly */
|
|
|
|
if (ByteOffset) CapturedByteOffset = *ByteOffset;
|
|
|
|
if (Key) CapturedKey = *Key;
|
|
|
|
}
|
|
|
|
|
2020-12-19 00:21:01 +08:00
|
|
|
/* Check for invalid offset */
|
|
|
|
if ((CapturedByteOffset.QuadPart < 0) && (CapturedByteOffset.QuadPart != -2))
|
|
|
|
{
|
|
|
|
/* -2 is FILE_USE_FILE_POINTER_POSITION */
|
|
|
|
ObDereferenceObject(FileObject);
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
2006-11-08 19:47:44 +08:00
|
|
|
/* Check for event */
|
|
|
|
if (Event)
|
|
|
|
{
|
|
|
|
/* Reference it */
|
|
|
|
Status = ObReferenceObjectByHandle(Event,
|
|
|
|
EVENT_MODIFY_STATE,
|
|
|
|
ExEventObjectType,
|
|
|
|
PreviousMode,
|
|
|
|
(PVOID*)&EventObject,
|
|
|
|
NULL);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* Fail */
|
|
|
|
ObDereferenceObject(FileObject);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Otherwise reset the event */
|
|
|
|
KeClearEvent(EventObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if we should use Sync IO or not */
|
|
|
|
if (FileObject->Flags & FO_SYNCHRONOUS_IO)
|
|
|
|
{
|
|
|
|
/* Lock the file object */
|
2018-10-02 15:55:07 +08:00
|
|
|
Status = IopLockFileObject(FileObject, PreviousMode);
|
|
|
|
if (Status != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
if (EventObject) ObDereferenceObject(EventObject);
|
|
|
|
ObDereferenceObject(FileObject);
|
|
|
|
return Status;
|
|
|
|
}
|
2006-11-08 19:47:44 +08:00
|
|
|
|
2015-05-01 21:20:26 +08:00
|
|
|
/* Check if we don't have a byte offset available */
|
2006-11-08 19:47:44 +08:00
|
|
|
if (!(ByteOffset) ||
|
|
|
|
((CapturedByteOffset.u.LowPart == FILE_USE_FILE_POINTER_POSITION) &&
|
|
|
|
(CapturedByteOffset.u.HighPart == -1)))
|
|
|
|
{
|
|
|
|
/* Use the Current Byte Offset instead */
|
|
|
|
CapturedByteOffset = FileObject->CurrentByteOffset;
|
|
|
|
}
|
|
|
|
|
2015-05-01 21:20:26 +08:00
|
|
|
/* If the file is cached, try fast I/O */
|
|
|
|
if (FileObject->PrivateCacheMap)
|
|
|
|
{
|
2016-02-29 21:59:32 +08:00
|
|
|
/* Perform fast read */
|
2015-05-01 21:20:26 +08:00
|
|
|
FastIoDispatch = DeviceObject->DriverObject->FastIoDispatch;
|
2016-03-01 05:45:44 +08:00
|
|
|
ASSERT(FastIoDispatch != NULL && FastIoDispatch->FastIoRead != NULL);
|
|
|
|
|
|
|
|
Success = FastIoDispatch->FastIoRead(FileObject,
|
|
|
|
&CapturedByteOffset,
|
|
|
|
Length,
|
|
|
|
TRUE,
|
|
|
|
CapturedKey,
|
|
|
|
Buffer,
|
|
|
|
&KernelIosb,
|
|
|
|
DeviceObject);
|
|
|
|
|
|
|
|
/* Only accept the result if we got a straightforward status */
|
|
|
|
if (Success &&
|
|
|
|
(KernelIosb.Status == STATUS_SUCCESS ||
|
|
|
|
KernelIosb.Status == STATUS_BUFFER_OVERFLOW ||
|
|
|
|
KernelIosb.Status == STATUS_END_OF_FILE))
|
2015-05-01 21:20:26 +08:00
|
|
|
{
|
2016-03-01 05:45:44 +08:00
|
|
|
/* Fast path -- update transfer & operation counts */
|
|
|
|
IopUpdateOperationCount(IopReadTransfer);
|
|
|
|
IopUpdateTransferCount(IopReadTransfer,
|
|
|
|
(ULONG)KernelIosb.Information);
|
2016-02-29 21:59:32 +08:00
|
|
|
|
2016-03-01 05:45:44 +08:00
|
|
|
/* Enter SEH to write the IOSB back */
|
|
|
|
_SEH2_TRY
|
|
|
|
{
|
|
|
|
/* Write it back to the caller */
|
|
|
|
*IoStatusBlock = KernelIosb;
|
|
|
|
}
|
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
|
|
|
/* The caller's IOSB was invalid, so fail */
|
|
|
|
if (EventObject) ObDereferenceObject(EventObject);
|
2015-05-01 21:20:26 +08:00
|
|
|
IopUnlockFileObject(FileObject);
|
|
|
|
ObDereferenceObject(FileObject);
|
2016-03-01 05:45:44 +08:00
|
|
|
_SEH2_YIELD(return _SEH2_GetExceptionCode());
|
|
|
|
}
|
|
|
|
_SEH2_END;
|
|
|
|
|
|
|
|
/* Signal the completion event */
|
|
|
|
if (EventObject)
|
|
|
|
{
|
|
|
|
KeSetEvent(EventObject, 0, FALSE);
|
|
|
|
ObDereferenceObject(EventObject);
|
2015-05-01 21:20:26 +08:00
|
|
|
}
|
2016-03-01 05:45:44 +08:00
|
|
|
|
|
|
|
/* Clean up */
|
|
|
|
IopUnlockFileObject(FileObject);
|
|
|
|
ObDereferenceObject(FileObject);
|
|
|
|
return KernelIosb.Status;
|
2015-05-01 21:20:26 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-24 00:30:14 +08:00
|
|
|
/* Remember we are sync */
|
2006-11-08 19:47:44 +08:00
|
|
|
Synchronous = TRUE;
|
|
|
|
}
|
|
|
|
else if (!(ByteOffset) &&
|
|
|
|
!(FileObject->Flags & (FO_NAMED_PIPE | FO_MAILSLOT)))
|
|
|
|
{
|
|
|
|
/* Otherwise, this was async I/O without a byte offset, so fail */
|
|
|
|
if (EventObject) ObDereferenceObject(EventObject);
|
|
|
|
ObDereferenceObject(FileObject);
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear the File Object's event */
|
|
|
|
KeClearEvent(&FileObject->Event);
|
|
|
|
|
|
|
|
/* Allocate the IRP */
|
|
|
|
Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
|
2015-05-01 19:57:51 +08:00
|
|
|
if (!Irp) return IopCleanupFailedIrp(FileObject, EventObject, NULL);
|
2006-11-08 19:47:44 +08:00
|
|
|
|
|
|
|
/* Set the IRP */
|
|
|
|
Irp->Tail.Overlay.OriginalFileObject = FileObject;
|
|
|
|
Irp->Tail.Overlay.Thread = PsGetCurrentThread();
|
2008-10-30 23:59:00 +08:00
|
|
|
Irp->RequestorMode = PreviousMode;
|
2006-11-08 19:47:44 +08:00
|
|
|
Irp->Overlay.AsynchronousParameters.UserApcRoutine = ApcRoutine;
|
|
|
|
Irp->Overlay.AsynchronousParameters.UserApcContext = ApcContext;
|
|
|
|
Irp->UserIosb = IoStatusBlock;
|
|
|
|
Irp->UserEvent = EventObject;
|
|
|
|
Irp->PendingReturned = FALSE;
|
|
|
|
Irp->Cancel = FALSE;
|
|
|
|
Irp->CancelRoutine = NULL;
|
|
|
|
Irp->AssociatedIrp.SystemBuffer = NULL;
|
|
|
|
Irp->MdlAddress = NULL;
|
|
|
|
|
|
|
|
/* Set the Stack Data */
|
|
|
|
StackPtr = IoGetNextIrpStackLocation(Irp);
|
|
|
|
StackPtr->MajorFunction = IRP_MJ_READ;
|
|
|
|
StackPtr->FileObject = FileObject;
|
|
|
|
StackPtr->Parameters.Read.Key = CapturedKey;
|
|
|
|
StackPtr->Parameters.Read.Length = Length;
|
|
|
|
StackPtr->Parameters.Read.ByteOffset = CapturedByteOffset;
|
|
|
|
|
|
|
|
/* Check if this is buffered I/O */
|
|
|
|
if (DeviceObject->Flags & DO_BUFFERED_IO)
|
|
|
|
{
|
|
|
|
/* Check if we have a buffer length */
|
|
|
|
if (Length)
|
|
|
|
{
|
2024-04-22 16:50:59 +08:00
|
|
|
/* Enter SEH (ExAllocatePoolWithQuotaTag raises on failure!) */
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_TRY
|
2006-11-08 19:47:44 +08:00
|
|
|
{
|
|
|
|
/* Allocate a buffer */
|
|
|
|
Irp->AssociatedIrp.SystemBuffer =
|
2024-04-22 16:50:59 +08:00
|
|
|
ExAllocatePoolWithQuotaTag(NonPagedPool, Length, TAG_SYSB);
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
2006-11-08 19:47:44 +08:00
|
|
|
{
|
2009-08-27 01:31:02 +08:00
|
|
|
/* Allocating failed, clean up and return the exception code */
|
2008-12-22 02:16:12 +08:00
|
|
|
IopCleanupAfterException(FileObject, Irp, EventObject, NULL);
|
2009-08-27 01:31:02 +08:00
|
|
|
_SEH2_YIELD(return _SEH2_GetExceptionCode());
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_END;
|
2006-11-08 19:47:44 +08:00
|
|
|
|
|
|
|
/* Set the buffer and flags */
|
|
|
|
Irp->UserBuffer = Buffer;
|
|
|
|
Irp->Flags = (IRP_BUFFERED_IO |
|
|
|
|
IRP_DEALLOCATE_BUFFER |
|
|
|
|
IRP_INPUT_OPERATION);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Not reading anything */
|
|
|
|
Irp->Flags = IRP_BUFFERED_IO | IRP_INPUT_OPERATION;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (DeviceObject->Flags & DO_DIRECT_IO)
|
|
|
|
{
|
|
|
|
/* Check if we have a buffer length */
|
|
|
|
if (Length)
|
|
|
|
{
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_TRY
|
2008-01-30 21:33:16 +08:00
|
|
|
{
|
|
|
|
/* Allocate an MDL */
|
|
|
|
Mdl = IoAllocateMdl(Buffer, Length, FALSE, TRUE, Irp);
|
2014-08-06 02:47:25 +08:00
|
|
|
if (!Mdl)
|
|
|
|
ExRaiseStatus(STATUS_INSUFFICIENT_RESOURCES);
|
2008-01-30 21:33:16 +08:00
|
|
|
MmProbeAndLockPages(Mdl, PreviousMode, IoWriteAccess);
|
|
|
|
}
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
2008-01-30 21:33:16 +08:00
|
|
|
{
|
2009-08-27 01:31:02 +08:00
|
|
|
/* Allocating failed, clean up and return the exception code */
|
2008-12-22 02:16:12 +08:00
|
|
|
IopCleanupAfterException(FileObject, Irp, EventObject, NULL);
|
2009-08-27 01:31:02 +08:00
|
|
|
_SEH2_YIELD(return _SEH2_GetExceptionCode());
|
2008-01-30 21:33:16 +08:00
|
|
|
}
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_END;
|
2008-01-30 21:33:16 +08:00
|
|
|
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* No allocation flags */
|
|
|
|
Irp->Flags = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* No allocation flags, and use the buffer directly */
|
|
|
|
Irp->Flags = 0;
|
|
|
|
Irp->UserBuffer = Buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now set the deferred read flags */
|
|
|
|
Irp->Flags |= (IRP_READ_OPERATION | IRP_DEFER_IO_COMPLETION);
|
2020-12-04 16:13:01 +08:00
|
|
|
|
2006-11-08 19:47:44 +08:00
|
|
|
if (FileObject->Flags & FO_NO_INTERMEDIATE_BUFFERING) Irp->Flags |= IRP_NOCACHE;
|
|
|
|
|
|
|
|
/* Perform the call */
|
|
|
|
return IopPerformSynchronousRequest(DeviceObject,
|
|
|
|
Irp,
|
|
|
|
FileObject,
|
|
|
|
TRUE,
|
|
|
|
PreviousMode,
|
|
|
|
Synchronous,
|
|
|
|
IopReadTransfer);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @unimplemented
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
NtReadFileScatter(IN HANDLE FileHandle,
|
|
|
|
IN HANDLE Event OPTIONAL,
|
|
|
|
IN PIO_APC_ROUTINE UserApcRoutine OPTIONAL,
|
|
|
|
IN PVOID UserApcContext OPTIONAL,
|
|
|
|
OUT PIO_STATUS_BLOCK UserIoStatusBlock,
|
|
|
|
IN FILE_SEGMENT_ELEMENT BufferDescription [],
|
|
|
|
IN ULONG BufferLength,
|
|
|
|
IN PLARGE_INTEGER ByteOffset,
|
|
|
|
IN PULONG Key OPTIONAL)
|
|
|
|
{
|
|
|
|
UNIMPLEMENTED;
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @unimplemented
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
NtSetEaFile(IN HANDLE FileHandle,
|
|
|
|
IN PIO_STATUS_BLOCK IoStatusBlock,
|
|
|
|
IN PVOID EaBuffer,
|
|
|
|
IN ULONG EaBufferSize)
|
|
|
|
{
|
|
|
|
UNIMPLEMENTED;
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
NtSetInformationFile(IN HANDLE FileHandle,
|
|
|
|
OUT PIO_STATUS_BLOCK IoStatusBlock,
|
|
|
|
IN PVOID FileInformation,
|
|
|
|
IN ULONG Length,
|
|
|
|
IN FILE_INFORMATION_CLASS FileInformationClass)
|
|
|
|
{
|
|
|
|
PFILE_OBJECT FileObject;
|
2009-08-27 01:31:02 +08:00
|
|
|
NTSTATUS Status;
|
2007-04-02 23:08:54 +08:00
|
|
|
PIRP Irp;
|
|
|
|
PDEVICE_OBJECT DeviceObject;
|
|
|
|
PIO_STACK_LOCATION StackPtr;
|
2006-11-08 19:47:44 +08:00
|
|
|
KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
|
|
|
|
PKEVENT Event = NULL;
|
|
|
|
BOOLEAN LocalEvent = FALSE;
|
|
|
|
PKNORMAL_ROUTINE NormalRoutine;
|
|
|
|
PVOID NormalContext;
|
|
|
|
KIRQL OldIrql;
|
|
|
|
IO_STATUS_BLOCK KernelIosb;
|
|
|
|
PVOID Queue;
|
|
|
|
PFILE_COMPLETION_INFORMATION CompletionInfo = FileInformation;
|
|
|
|
PIO_COMPLETION_CONTEXT Context;
|
2014-04-27 03:36:51 +08:00
|
|
|
PFILE_RENAME_INFORMATION RenameInfo;
|
2014-04-27 19:14:16 +08:00
|
|
|
HANDLE TargetHandle = NULL;
|
2009-05-24 17:08:51 +08:00
|
|
|
PAGED_CODE();
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
IOTRACE(IO_API_DEBUG, "FileHandle: %p\n", FileHandle);
|
2006-11-08 19:47:44 +08:00
|
|
|
|
|
|
|
/* Check if we're called from user mode */
|
|
|
|
if (PreviousMode != KernelMode)
|
|
|
|
{
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
/* Validate the information class */
|
2019-01-19 18:35:18 +08:00
|
|
|
if ((FileInformationClass < 0) ||
|
|
|
|
(FileInformationClass >= FileMaximumInformation) ||
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
!(IopSetOperationLength[FileInformationClass]))
|
|
|
|
{
|
|
|
|
/* Invalid class */
|
|
|
|
return STATUS_INVALID_INFO_CLASS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Validate the length */
|
|
|
|
if (Length < IopSetOperationLength[FileInformationClass])
|
|
|
|
{
|
|
|
|
/* Invalid length */
|
|
|
|
return STATUS_INFO_LENGTH_MISMATCH;
|
|
|
|
}
|
|
|
|
|
2006-11-08 19:47:44 +08:00
|
|
|
/* Enter SEH for probing */
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_TRY
|
2006-11-08 19:47:44 +08:00
|
|
|
{
|
|
|
|
/* Probe the I/O Status block */
|
|
|
|
ProbeForWriteIoStatusBlock(IoStatusBlock);
|
|
|
|
|
|
|
|
/* Probe the information */
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
ProbeForRead(FileInformation,
|
|
|
|
Length,
|
|
|
|
(Length == sizeof(BOOLEAN)) ?
|
|
|
|
sizeof(BOOLEAN) : sizeof(ULONG));
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
2006-11-08 19:47:44 +08:00
|
|
|
{
|
2009-08-27 01:31:02 +08:00
|
|
|
/* Return the exception code */
|
|
|
|
_SEH2_YIELD(return _SEH2_GetExceptionCode());
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_END;
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Validate the information class */
|
2019-01-19 18:35:18 +08:00
|
|
|
if ((FileInformationClass < 0) ||
|
|
|
|
(FileInformationClass >= FileMaximumInformation) ||
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
!(IopSetOperationLength[FileInformationClass]))
|
|
|
|
{
|
|
|
|
/* Invalid class */
|
|
|
|
return STATUS_INVALID_INFO_CLASS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Validate the length */
|
|
|
|
if (Length < IopSetOperationLength[FileInformationClass])
|
|
|
|
{
|
|
|
|
/* Invalid length */
|
|
|
|
return STATUS_INFO_LENGTH_MISMATCH;
|
|
|
|
}
|
|
|
|
}
|
2006-11-08 19:47:44 +08:00
|
|
|
|
|
|
|
/* Reference the Handle */
|
|
|
|
Status = ObReferenceObjectByHandle(FileHandle,
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
IopSetOperationAccess
|
|
|
|
[FileInformationClass],
|
2006-11-08 19:47:44 +08:00
|
|
|
IoFileObjectType,
|
|
|
|
PreviousMode,
|
|
|
|
(PVOID *)&FileObject,
|
|
|
|
NULL);
|
|
|
|
if (!NT_SUCCESS(Status)) return Status;
|
|
|
|
|
|
|
|
/* Check if this is a direct open or not */
|
|
|
|
if (FileObject->Flags & FO_DIRECT_DEVICE_OPEN)
|
|
|
|
{
|
|
|
|
/* Get the device object */
|
|
|
|
DeviceObject = IoGetAttachedDevice(FileObject->DeviceObject);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Get the device object */
|
|
|
|
DeviceObject = IoGetRelatedDeviceObject(FileObject);
|
|
|
|
}
|
|
|
|
|
2015-05-19 03:47:11 +08:00
|
|
|
DPRINT("Will call: %p\n", DeviceObject);
|
|
|
|
DPRINT("Associated driver: %p (%wZ)\n", DeviceObject->DriverObject, &DeviceObject->DriverObject->DriverName);
|
|
|
|
|
2006-11-08 19:47:44 +08:00
|
|
|
/* Check if this is a file that was opened for Synch I/O */
|
|
|
|
if (FileObject->Flags & FO_SYNCHRONOUS_IO)
|
|
|
|
{
|
|
|
|
/* Lock it */
|
2018-10-02 15:55:07 +08:00
|
|
|
Status = IopLockFileObject(FileObject, PreviousMode);
|
|
|
|
if (Status != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
ObDereferenceObject(FileObject);
|
|
|
|
return Status;
|
|
|
|
}
|
2006-11-08 19:47:44 +08:00
|
|
|
|
|
|
|
/* Check if the caller just wants the position */
|
|
|
|
if (FileInformationClass == FilePositionInformation)
|
|
|
|
{
|
|
|
|
/* Protect write in SEH */
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_TRY
|
2006-11-08 19:47:44 +08:00
|
|
|
{
|
|
|
|
/* Write the offset */
|
|
|
|
FileObject->CurrentByteOffset =
|
|
|
|
((PFILE_POSITION_INFORMATION)FileInformation)->
|
|
|
|
CurrentByteOffset;
|
|
|
|
|
|
|
|
/* Fill out the I/O Status Block */
|
|
|
|
IoStatusBlock->Information = 0;
|
|
|
|
Status = IoStatusBlock->Status = STATUS_SUCCESS;
|
|
|
|
}
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
2006-11-08 19:47:44 +08:00
|
|
|
{
|
|
|
|
/* Get the exception code */
|
2008-11-24 21:40:26 +08:00
|
|
|
Status = _SEH2_GetExceptionCode();
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_END;
|
2006-11-08 19:47:44 +08:00
|
|
|
|
2009-06-10 00:38:05 +08:00
|
|
|
/* Update transfer count */
|
|
|
|
IopUpdateTransferCount(IopOtherTransfer, Length);
|
|
|
|
|
2006-11-08 19:47:44 +08:00
|
|
|
/* Release the file lock, dereference the file and return */
|
|
|
|
IopUnlockFileObject(FileObject);
|
|
|
|
ObDereferenceObject(FileObject);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Use local event */
|
|
|
|
Event = ExAllocatePoolWithTag(NonPagedPool, sizeof(KEVENT), TAG_IO);
|
2009-05-24 17:08:51 +08:00
|
|
|
if (!Event)
|
|
|
|
{
|
|
|
|
ObDereferenceObject(FileObject);
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
}
|
|
|
|
|
2006-11-08 19:47:44 +08:00
|
|
|
KeInitializeEvent(Event, SynchronizationEvent, FALSE);
|
|
|
|
LocalEvent = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear the File Object event */
|
|
|
|
KeClearEvent(&FileObject->Event);
|
|
|
|
|
|
|
|
/* Allocate the IRP */
|
|
|
|
Irp = IoAllocateIrp(DeviceObject->StackSize, TRUE);
|
|
|
|
if (!Irp) return IopCleanupFailedIrp(FileObject, NULL, Event);
|
|
|
|
|
|
|
|
/* Set the IRP */
|
|
|
|
Irp->Tail.Overlay.OriginalFileObject = FileObject;
|
|
|
|
Irp->Tail.Overlay.Thread = PsGetCurrentThread();
|
|
|
|
Irp->RequestorMode = PreviousMode;
|
|
|
|
Irp->Overlay.AsynchronousParameters.UserApcRoutine = NULL;
|
|
|
|
Irp->Flags = (LocalEvent) ? IRP_SYNCHRONOUS_API : 0;
|
|
|
|
Irp->UserIosb = (LocalEvent) ? &KernelIosb : IoStatusBlock;
|
|
|
|
Irp->UserEvent = (LocalEvent) ? Event : NULL;
|
|
|
|
Irp->AssociatedIrp.SystemBuffer = NULL;
|
|
|
|
Irp->MdlAddress = NULL;
|
|
|
|
Irp->UserBuffer = FileInformation;
|
|
|
|
|
|
|
|
/* Set the Stack Data */
|
|
|
|
StackPtr = IoGetNextIrpStackLocation(Irp);
|
|
|
|
StackPtr->MajorFunction = IRP_MJ_SET_INFORMATION;
|
|
|
|
StackPtr->FileObject = FileObject;
|
|
|
|
|
2024-04-22 16:50:59 +08:00
|
|
|
/* Enter SEH (ExAllocatePoolWithQuotaTag raises on failure!) */
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_TRY
|
2006-11-08 19:47:44 +08:00
|
|
|
{
|
|
|
|
/* Allocate a buffer */
|
|
|
|
Irp->AssociatedIrp.SystemBuffer =
|
2024-04-22 16:50:59 +08:00
|
|
|
ExAllocatePoolWithQuotaTag(NonPagedPool, Length, TAG_SYSB);
|
2006-11-08 19:47:44 +08:00
|
|
|
|
|
|
|
/* Copy the data into it */
|
|
|
|
RtlCopyMemory(Irp->AssociatedIrp.SystemBuffer,
|
|
|
|
FileInformation,
|
|
|
|
Length);
|
|
|
|
}
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
2006-11-08 19:47:44 +08:00
|
|
|
{
|
2009-08-27 01:31:02 +08:00
|
|
|
/* Allocating failed, clean up and return the exception code */
|
2006-11-08 19:47:44 +08:00
|
|
|
IopCleanupAfterException(FileObject, Irp, NULL, Event);
|
2009-08-27 01:31:02 +08:00
|
|
|
_SEH2_YIELD(return _SEH2_GetExceptionCode());
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_END;
|
2006-11-08 19:47:44 +08:00
|
|
|
|
|
|
|
/* Set the flags */
|
2008-09-08 19:52:33 +08:00
|
|
|
Irp->Flags |= (IRP_BUFFERED_IO |
|
|
|
|
IRP_DEALLOCATE_BUFFER |
|
|
|
|
IRP_DEFER_IO_COMPLETION);
|
2006-11-08 19:47:44 +08:00
|
|
|
|
|
|
|
/* Set the Parameters */
|
|
|
|
StackPtr->Parameters.SetFile.FileInformationClass = FileInformationClass;
|
|
|
|
StackPtr->Parameters.SetFile.Length = Length;
|
|
|
|
|
|
|
|
/* Queue the IRP */
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
IopQueueIrpToThread(Irp);
|
2006-11-08 19:47:44 +08:00
|
|
|
|
|
|
|
/* Update operation counts */
|
|
|
|
IopUpdateOperationCount(IopOtherTransfer);
|
|
|
|
|
|
|
|
/* FIXME: Later, we can implement a lot of stuff here and avoid a driver call */
|
|
|
|
/* Handle IO Completion Port quickly */
|
|
|
|
if (FileInformationClass == FileCompletionInformation)
|
|
|
|
{
|
|
|
|
/* Check if the file object already has a completion port */
|
|
|
|
if ((FileObject->Flags & FO_SYNCHRONOUS_IO) ||
|
|
|
|
(FileObject->CompletionContext))
|
|
|
|
{
|
|
|
|
/* Fail */
|
|
|
|
Status = STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Reference the Port */
|
|
|
|
CompletionInfo = Irp->AssociatedIrp.SystemBuffer;
|
|
|
|
Status = ObReferenceObjectByHandle(CompletionInfo->Port,
|
|
|
|
IO_COMPLETION_MODIFY_STATE,
|
|
|
|
IoCompletionType,
|
|
|
|
PreviousMode,
|
|
|
|
(PVOID*)&Queue,
|
|
|
|
NULL);
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* Allocate the Context */
|
|
|
|
Context = ExAllocatePoolWithTag(PagedPool,
|
|
|
|
sizeof(IO_COMPLETION_CONTEXT),
|
|
|
|
IOC_TAG);
|
|
|
|
if (Context)
|
|
|
|
{
|
|
|
|
/* Set the Data */
|
|
|
|
Context->Key = CompletionInfo->Key;
|
|
|
|
Context->Port = Queue;
|
2010-01-14 06:35:43 +08:00
|
|
|
if (InterlockedCompareExchangePointer((PVOID*)&FileObject->
|
2006-11-08 19:47:44 +08:00
|
|
|
CompletionContext,
|
|
|
|
Context,
|
|
|
|
NULL))
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Someone else set the completion port in the
|
|
|
|
* meanwhile, so dereference the port and fail.
|
|
|
|
*/
|
2012-09-28 20:17:23 +08:00
|
|
|
ExFreePoolWithTag(Context, IOC_TAG);
|
2006-11-08 19:47:44 +08:00
|
|
|
ObDereferenceObject(Queue);
|
|
|
|
Status = STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Dereference the Port now */
|
|
|
|
ObDereferenceObject(Queue);
|
|
|
|
Status = STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the IRP Status */
|
|
|
|
Irp->IoStatus.Status = Status;
|
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
}
|
2014-04-27 03:36:51 +08:00
|
|
|
else if (FileInformationClass == FileRenameInformation ||
|
|
|
|
FileInformationClass == FileLinkInformation ||
|
|
|
|
FileInformationClass == FileMoveClusterInformation)
|
|
|
|
{
|
|
|
|
/* Get associated information */
|
|
|
|
RenameInfo = Irp->AssociatedIrp.SystemBuffer;
|
|
|
|
|
|
|
|
/* Only rename if:
|
|
|
|
* -> We have a name
|
|
|
|
* -> In unicode
|
|
|
|
* -> sizes are valid
|
|
|
|
*/
|
|
|
|
if (RenameInfo->FileNameLength != 0 &&
|
|
|
|
!(RenameInfo->FileNameLength & 1) &&
|
|
|
|
(Length - FIELD_OFFSET(FILE_RENAME_INFORMATION, FileName) >= RenameInfo->FileNameLength))
|
|
|
|
{
|
|
|
|
/* Properly set information received */
|
|
|
|
if (FileInformationClass == FileMoveClusterInformation)
|
|
|
|
{
|
|
|
|
StackPtr->Parameters.SetFile.ClusterCount = ((PFILE_MOVE_CLUSTER_INFORMATION)RenameInfo)->ClusterCount;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
StackPtr->Parameters.SetFile.ReplaceIfExists = RenameInfo->ReplaceIfExists;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we got fully path OR relative target, attempt a parent directory open */
|
|
|
|
if (RenameInfo->FileName[0] == OBJ_NAME_PATH_SEPARATOR || RenameInfo->RootDirectory)
|
|
|
|
{
|
|
|
|
Status = IopOpenLinkOrRenameTarget(&TargetHandle, Irp, RenameInfo, FileObject);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
Irp->IoStatus.Status = Status;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Call the Driver */
|
|
|
|
Status = IoCallDriver(DeviceObject, Irp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Call the Driver */
|
|
|
|
Status = IoCallDriver(DeviceObject, Irp);
|
|
|
|
}
|
|
|
|
}
|
2014-04-27 19:14:16 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
Status = STATUS_INVALID_PARAMETER;
|
|
|
|
Irp->IoStatus.Status = Status;
|
|
|
|
}
|
2014-04-27 03:36:51 +08:00
|
|
|
}
|
2006-11-08 19:47:44 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Call the Driver */
|
|
|
|
Status = IoCallDriver(DeviceObject, Irp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if we're waiting for the IRP to complete */
|
|
|
|
if (Status == STATUS_PENDING)
|
|
|
|
{
|
|
|
|
/* Check if this was async I/O */
|
|
|
|
if (LocalEvent)
|
|
|
|
{
|
|
|
|
/* Then to a non-alertable wait */
|
|
|
|
Status = KeWaitForSingleObject(Event,
|
|
|
|
Executive,
|
|
|
|
PreviousMode,
|
|
|
|
FALSE,
|
|
|
|
NULL);
|
|
|
|
if (Status == STATUS_USER_APC)
|
|
|
|
{
|
|
|
|
/* Abort the request */
|
|
|
|
IopAbortInterruptedIrp(Event, Irp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the final status */
|
|
|
|
Status = KernelIosb.Status;
|
|
|
|
|
|
|
|
/* Enter SEH to write the IOSB back */
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_TRY
|
2006-11-08 19:47:44 +08:00
|
|
|
{
|
|
|
|
/* Write it back to the caller */
|
|
|
|
*IoStatusBlock = KernelIosb;
|
|
|
|
}
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
2006-11-08 19:47:44 +08:00
|
|
|
{
|
|
|
|
/* Get the exception code */
|
2008-11-24 21:40:26 +08:00
|
|
|
Status = _SEH2_GetExceptionCode();
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_END;
|
2006-11-08 19:47:44 +08:00
|
|
|
|
|
|
|
/* Free the event */
|
2012-09-28 20:17:23 +08:00
|
|
|
ExFreePoolWithTag(Event, TAG_IO);
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Wait for the IRP */
|
|
|
|
Status = KeWaitForSingleObject(&FileObject->Event,
|
|
|
|
Executive,
|
|
|
|
PreviousMode,
|
2012-07-24 23:32:06 +08:00
|
|
|
(FileObject->Flags &
|
|
|
|
FO_ALERTABLE_IO) != 0,
|
2006-11-08 19:47:44 +08:00
|
|
|
NULL);
|
|
|
|
if ((Status == STATUS_USER_APC) || (Status == STATUS_ALERTED))
|
|
|
|
{
|
|
|
|
/* Abort the request */
|
|
|
|
IopAbortInterruptedIrp(&FileObject->Event, Irp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the final status */
|
|
|
|
Status = FileObject->FinalStatus;
|
|
|
|
|
|
|
|
/* Release the file lock */
|
|
|
|
IopUnlockFileObject(FileObject);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Free the event if we had one */
|
|
|
|
if (LocalEvent)
|
|
|
|
{
|
|
|
|
/* Clear it in the IRP for completion */
|
|
|
|
Irp->UserEvent = NULL;
|
2012-09-28 20:17:23 +08:00
|
|
|
ExFreePoolWithTag(Event, TAG_IO);
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the caller IOSB */
|
|
|
|
Irp->UserIosb = IoStatusBlock;
|
|
|
|
|
|
|
|
/* The IRP wasn't completed, complete it ourselves */
|
2021-10-28 23:17:03 +08:00
|
|
|
NormalRoutine = NULL;
|
|
|
|
NormalContext = NULL;
|
2006-11-08 19:47:44 +08:00
|
|
|
KeRaiseIrql(APC_LEVEL, &OldIrql);
|
|
|
|
IopCompleteRequest(&Irp->Tail.Apc,
|
|
|
|
&NormalRoutine,
|
|
|
|
&NormalContext,
|
|
|
|
(PVOID*)&FileObject,
|
|
|
|
&NormalContext);
|
|
|
|
KeLowerIrql(OldIrql);
|
|
|
|
|
|
|
|
/* Release the file object if we had locked it*/
|
|
|
|
if (!LocalEvent) IopUnlockFileObject(FileObject);
|
|
|
|
}
|
|
|
|
|
2014-04-27 19:14:16 +08:00
|
|
|
if (TargetHandle != NULL)
|
2014-04-27 03:36:51 +08:00
|
|
|
{
|
|
|
|
ObCloseHandle(TargetHandle, KernelMode);
|
|
|
|
}
|
|
|
|
|
2006-11-08 19:47:44 +08:00
|
|
|
/* Return the Status */
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @unimplemented
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
NtSetQuotaInformationFile(IN HANDLE FileHandle,
|
|
|
|
OUT PIO_STATUS_BLOCK IoStatusBlock,
|
|
|
|
IN PVOID Buffer,
|
|
|
|
IN ULONG BufferLength)
|
|
|
|
{
|
|
|
|
UNIMPLEMENTED;
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
NtUnlockFile(IN HANDLE FileHandle,
|
|
|
|
OUT PIO_STATUS_BLOCK IoStatusBlock,
|
|
|
|
IN PLARGE_INTEGER ByteOffset,
|
|
|
|
IN PLARGE_INTEGER Length,
|
|
|
|
IN ULONG Key OPTIONAL)
|
|
|
|
{
|
|
|
|
PFILE_OBJECT FileObject;
|
|
|
|
PLARGE_INTEGER LocalLength = NULL;
|
2007-04-02 23:08:54 +08:00
|
|
|
PIRP Irp;
|
|
|
|
PIO_STACK_LOCATION StackPtr;
|
|
|
|
PDEVICE_OBJECT DeviceObject;
|
2006-11-08 19:47:44 +08:00
|
|
|
PKEVENT Event = NULL;
|
|
|
|
BOOLEAN LocalEvent = FALSE;
|
|
|
|
KPROCESSOR_MODE PreviousMode = KeGetPreviousMode();
|
|
|
|
LARGE_INTEGER CapturedByteOffset, CapturedLength;
|
2009-08-27 01:31:02 +08:00
|
|
|
NTSTATUS Status;
|
2006-11-08 19:47:44 +08:00
|
|
|
OBJECT_HANDLE_INFORMATION HandleInformation;
|
|
|
|
IO_STATUS_BLOCK KernelIosb;
|
2015-05-19 03:47:11 +08:00
|
|
|
PFAST_IO_DISPATCH FastIoDispatch;
|
2006-11-08 19:47:44 +08:00
|
|
|
PAGED_CODE();
|
|
|
|
CapturedByteOffset.QuadPart = 0;
|
|
|
|
CapturedLength.QuadPart = 0;
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
IOTRACE(IO_API_DEBUG, "FileHandle: %p\n", FileHandle);
|
2006-11-08 19:47:44 +08:00
|
|
|
|
|
|
|
/* Get File Object */
|
|
|
|
Status = ObReferenceObjectByHandle(FileHandle,
|
|
|
|
0,
|
|
|
|
IoFileObjectType,
|
|
|
|
PreviousMode,
|
|
|
|
(PVOID*)&FileObject,
|
|
|
|
&HandleInformation);
|
|
|
|
if (!NT_SUCCESS(Status)) return Status;
|
|
|
|
|
|
|
|
/* Check if we're called from user mode */
|
|
|
|
if (PreviousMode != KernelMode)
|
|
|
|
{
|
|
|
|
/* Must have either FILE_READ_DATA or FILE_WRITE_DATA access */
|
|
|
|
if (!(HandleInformation.GrantedAccess &
|
|
|
|
(FILE_WRITE_DATA | FILE_READ_DATA)))
|
|
|
|
{
|
|
|
|
ObDereferenceObject(FileObject);
|
|
|
|
return STATUS_ACCESS_DENIED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Enter SEH for probing */
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_TRY
|
2006-11-08 19:47:44 +08:00
|
|
|
{
|
|
|
|
/* Probe the I/O Status block */
|
|
|
|
ProbeForWriteIoStatusBlock(IoStatusBlock);
|
|
|
|
|
|
|
|
/* Probe and capture the large integers */
|
|
|
|
CapturedByteOffset = ProbeForReadLargeInteger(ByteOffset);
|
|
|
|
CapturedLength = ProbeForReadLargeInteger(Length);
|
|
|
|
}
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
2006-11-08 19:47:44 +08:00
|
|
|
{
|
|
|
|
/* Dereference the object and return exception code */
|
|
|
|
ObDereferenceObject(FileObject);
|
2009-08-27 01:31:02 +08:00
|
|
|
_SEH2_YIELD(return _SEH2_GetExceptionCode());
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
2009-08-27 01:31:02 +08:00
|
|
|
_SEH2_END;
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Otherwise, capture them directly */
|
|
|
|
CapturedByteOffset = *ByteOffset;
|
|
|
|
CapturedLength = *Length;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if this is a direct open or not */
|
|
|
|
if (FileObject->Flags & FO_DIRECT_DEVICE_OPEN)
|
|
|
|
{
|
|
|
|
DeviceObject = IoGetAttachedDevice(FileObject->DeviceObject);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DeviceObject = IoGetRelatedDeviceObject(FileObject);
|
|
|
|
}
|
|
|
|
|
2015-05-19 03:47:11 +08:00
|
|
|
/* Try to do it the FastIO way if possible */
|
|
|
|
FastIoDispatch = DeviceObject->DriverObject->FastIoDispatch;
|
|
|
|
if (FastIoDispatch != NULL && FastIoDispatch->FastIoUnlockSingle != NULL)
|
|
|
|
{
|
|
|
|
if (FastIoDispatch->FastIoUnlockSingle(FileObject,
|
|
|
|
&CapturedByteOffset,
|
|
|
|
&CapturedLength,
|
|
|
|
PsGetCurrentProcess(),
|
|
|
|
Key,
|
|
|
|
&KernelIosb,
|
|
|
|
DeviceObject))
|
|
|
|
{
|
|
|
|
/* Write the IOSB back */
|
|
|
|
_SEH2_TRY
|
|
|
|
{
|
|
|
|
*IoStatusBlock = KernelIosb;
|
|
|
|
}
|
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
|
|
|
KernelIosb.Status = _SEH2_GetExceptionCode();
|
|
|
|
}
|
|
|
|
_SEH2_END;
|
|
|
|
|
|
|
|
/* We're done with FastIO! */
|
|
|
|
ObDereferenceObject(FileObject);
|
|
|
|
return KernelIosb.Status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-08 19:47:44 +08:00
|
|
|
/* Check if we should use Sync IO or not */
|
|
|
|
if (FileObject->Flags & FO_SYNCHRONOUS_IO)
|
|
|
|
{
|
|
|
|
/* Lock it */
|
2018-10-02 15:55:07 +08:00
|
|
|
Status = IopLockFileObject(FileObject, PreviousMode);
|
|
|
|
if (Status != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
ObDereferenceObject(FileObject);
|
|
|
|
return Status;
|
|
|
|
}
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Use local event */
|
|
|
|
Event = ExAllocatePoolWithTag(NonPagedPool, sizeof(KEVENT), TAG_IO);
|
2009-09-02 21:02:30 +08:00
|
|
|
if (!Event)
|
|
|
|
{
|
|
|
|
ObDereferenceObject(FileObject);
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
}
|
2006-11-08 19:47:44 +08:00
|
|
|
KeInitializeEvent(Event, SynchronizationEvent, FALSE);
|
|
|
|
LocalEvent = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear File Object event */
|
|
|
|
KeClearEvent(&FileObject->Event);
|
|
|
|
|
|
|
|
/* Allocate the IRP */
|
|
|
|
Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
|
|
|
|
if (!Irp) return IopCleanupFailedIrp(FileObject, NULL, Event);
|
|
|
|
|
|
|
|
/* Set up the IRP */
|
|
|
|
Irp->RequestorMode = PreviousMode;
|
|
|
|
Irp->Flags = (LocalEvent) ? IRP_SYNCHRONOUS_API : 0;
|
|
|
|
Irp->UserIosb = (LocalEvent) ? &KernelIosb : IoStatusBlock;
|
|
|
|
Irp->UserEvent = (LocalEvent) ? Event : NULL;
|
|
|
|
Irp->Tail.Overlay.Thread = PsGetCurrentThread();
|
|
|
|
Irp->Tail.Overlay.OriginalFileObject = FileObject;
|
|
|
|
Irp->Overlay.AsynchronousParameters.UserApcRoutine = NULL;
|
|
|
|
|
|
|
|
/* Set up Stack Data */
|
|
|
|
StackPtr = IoGetNextIrpStackLocation(Irp);
|
|
|
|
StackPtr->MajorFunction = IRP_MJ_LOCK_CONTROL;
|
|
|
|
StackPtr->MinorFunction = IRP_MN_UNLOCK_SINGLE;
|
|
|
|
StackPtr->FileObject = FileObject;
|
|
|
|
|
2024-04-22 16:50:59 +08:00
|
|
|
/* Enter SEH (ExAllocatePoolWithQuotaTag raises on failure!) */
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_TRY
|
2006-11-08 19:47:44 +08:00
|
|
|
{
|
|
|
|
/* Allocate a buffer */
|
2024-04-22 16:50:59 +08:00
|
|
|
LocalLength = ExAllocatePoolWithQuotaTag(NonPagedPool,
|
|
|
|
sizeof(LARGE_INTEGER),
|
|
|
|
TAG_LOCK);
|
2006-11-08 19:47:44 +08:00
|
|
|
|
|
|
|
/* Set the length */
|
|
|
|
*LocalLength = CapturedLength;
|
|
|
|
Irp->Tail.Overlay.AuxiliaryBuffer = (PVOID)LocalLength;
|
|
|
|
StackPtr->Parameters.LockControl.Length = LocalLength;
|
|
|
|
}
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
2006-11-08 19:47:44 +08:00
|
|
|
{
|
2009-08-27 01:31:02 +08:00
|
|
|
/* Allocating failed, clean up and return the exception code */
|
2006-11-08 19:47:44 +08:00
|
|
|
IopCleanupAfterException(FileObject, Irp, NULL, Event);
|
2012-09-28 20:17:23 +08:00
|
|
|
if (LocalLength) ExFreePoolWithTag(LocalLength, TAG_LOCK);
|
2006-11-08 19:47:44 +08:00
|
|
|
|
2009-08-27 01:31:02 +08:00
|
|
|
/* Return the exception code */
|
|
|
|
_SEH2_YIELD(return _SEH2_GetExceptionCode());
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_END;
|
2006-11-08 19:47:44 +08:00
|
|
|
|
|
|
|
/* Set Parameters */
|
|
|
|
StackPtr->Parameters.LockControl.ByteOffset = CapturedByteOffset;
|
|
|
|
StackPtr->Parameters.LockControl.Key = Key;
|
|
|
|
|
|
|
|
/* Call the Driver */
|
|
|
|
Status = IopPerformSynchronousRequest(DeviceObject,
|
|
|
|
Irp,
|
|
|
|
FileObject,
|
|
|
|
FALSE,
|
|
|
|
PreviousMode,
|
|
|
|
!LocalEvent,
|
|
|
|
IopOtherTransfer);
|
|
|
|
|
|
|
|
/* Check if this was async I/O */
|
|
|
|
if (LocalEvent)
|
|
|
|
{
|
|
|
|
/* It was, finalize this request */
|
|
|
|
Status = IopFinalizeAsynchronousIo(Status,
|
|
|
|
Event,
|
|
|
|
Irp,
|
|
|
|
PreviousMode,
|
|
|
|
&KernelIosb,
|
|
|
|
IoStatusBlock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return status */
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
NtWriteFile(IN HANDLE FileHandle,
|
|
|
|
IN HANDLE Event OPTIONAL,
|
|
|
|
IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
|
|
|
|
IN PVOID ApcContext OPTIONAL,
|
|
|
|
OUT PIO_STATUS_BLOCK IoStatusBlock,
|
|
|
|
IN PVOID Buffer,
|
|
|
|
IN ULONG Length,
|
|
|
|
IN PLARGE_INTEGER ByteOffset OPTIONAL,
|
|
|
|
IN PULONG Key OPTIONAL)
|
|
|
|
{
|
2009-08-27 01:31:02 +08:00
|
|
|
NTSTATUS Status;
|
2006-11-08 19:47:44 +08:00
|
|
|
PFILE_OBJECT FileObject;
|
2007-04-02 23:08:54 +08:00
|
|
|
PIRP Irp;
|
|
|
|
PDEVICE_OBJECT DeviceObject;
|
2006-11-08 19:47:44 +08:00
|
|
|
PIO_STACK_LOCATION StackPtr;
|
|
|
|
KPROCESSOR_MODE PreviousMode = KeGetPreviousMode();
|
|
|
|
PKEVENT EventObject = NULL;
|
|
|
|
LARGE_INTEGER CapturedByteOffset;
|
|
|
|
ULONG CapturedKey = 0;
|
|
|
|
BOOLEAN Synchronous = FALSE;
|
|
|
|
PMDL Mdl;
|
|
|
|
OBJECT_HANDLE_INFORMATION ObjectHandleInfo;
|
2015-05-01 21:20:26 +08:00
|
|
|
PFAST_IO_DISPATCH FastIoDispatch;
|
|
|
|
IO_STATUS_BLOCK KernelIosb;
|
|
|
|
BOOLEAN Success;
|
|
|
|
|
2006-11-08 19:47:44 +08:00
|
|
|
PAGED_CODE();
|
|
|
|
CapturedByteOffset.QuadPart = 0;
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
IOTRACE(IO_API_DEBUG, "FileHandle: %p\n", FileHandle);
|
2006-11-08 19:47:44 +08:00
|
|
|
|
2017-11-13 05:32:16 +08:00
|
|
|
/* Get File Object for write */
|
|
|
|
Status = ObReferenceFileObjectForWrite(FileHandle,
|
|
|
|
PreviousMode,
|
|
|
|
&FileObject,
|
|
|
|
&ObjectHandleInfo);
|
2006-11-08 19:47:44 +08:00
|
|
|
if (!NT_SUCCESS(Status)) return Status;
|
|
|
|
|
2018-10-04 07:16:17 +08:00
|
|
|
/* Get the device object */
|
|
|
|
DeviceObject = IoGetRelatedDeviceObject(FileObject);
|
|
|
|
|
2006-11-08 19:47:44 +08:00
|
|
|
/* Validate User-Mode Buffers */
|
2009-08-27 01:31:02 +08:00
|
|
|
if (PreviousMode != KernelMode)
|
2006-11-08 19:47:44 +08:00
|
|
|
{
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_TRY
|
2006-11-08 19:47:44 +08:00
|
|
|
{
|
|
|
|
/* Probe the status block */
|
|
|
|
ProbeForWriteIoStatusBlock(IoStatusBlock);
|
|
|
|
|
|
|
|
/* Probe the read buffer */
|
|
|
|
ProbeForRead(Buffer, Length, 1);
|
|
|
|
|
|
|
|
/* Check if we got a byte offset */
|
|
|
|
if (ByteOffset)
|
|
|
|
{
|
|
|
|
/* Capture and probe it */
|
|
|
|
CapturedByteOffset = ProbeForReadLargeInteger(ByteOffset);
|
|
|
|
}
|
|
|
|
|
2021-11-24 20:34:26 +08:00
|
|
|
/* 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;
|
|
|
|
}
|
|
|
|
|
2018-10-04 07:16:17 +08:00
|
|
|
/* Perform additional checks for non-cached file access */
|
|
|
|
if (FileObject->Flags & FO_NO_INTERMEDIATE_BUFFERING)
|
|
|
|
{
|
2018-10-04 16:42:13 +08:00
|
|
|
/* Fail if Length is not sector size aligned
|
|
|
|
* Perform a quick check for 2^ sector sizes
|
|
|
|
* If it fails, try a more standard way
|
|
|
|
*/
|
2018-10-04 07:16:17 +08:00
|
|
|
if ((DeviceObject->SectorSize != 0) &&
|
2018-10-04 16:42:13 +08:00
|
|
|
((DeviceObject->SectorSize - 1) & Length) != 0)
|
2018-10-04 07:16:17 +08:00
|
|
|
{
|
2018-10-04 16:42:13 +08:00
|
|
|
if (Length % DeviceObject->SectorSize != 0)
|
|
|
|
{
|
|
|
|
/* Release the file object and and fail */
|
|
|
|
ObDereferenceObject(FileObject);
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
2018-10-04 07:16:17 +08:00
|
|
|
}
|
|
|
|
|
2018-10-04 13:56:23 +08:00
|
|
|
/* Fail if buffer doesn't match alignment requirements */
|
|
|
|
if (((ULONG_PTR)Buffer & DeviceObject->AlignmentRequirement) != 0)
|
|
|
|
{
|
|
|
|
/* Release the file object and and fail */
|
|
|
|
ObDereferenceObject(FileObject);
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
2018-10-04 07:16:17 +08:00
|
|
|
if (ByteOffset)
|
|
|
|
{
|
|
|
|
/* Fail if ByteOffset is not sector size aligned */
|
|
|
|
if ((DeviceObject->SectorSize != 0) &&
|
2018-10-04 16:27:35 +08:00
|
|
|
(CapturedByteOffset.QuadPart % DeviceObject->SectorSize != 0))
|
2018-10-04 07:16:17 +08:00
|
|
|
{
|
2018-10-04 13:53:12 +08:00
|
|
|
/* Only if that's not specific values for synchronous IO */
|
2018-10-04 16:27:35 +08:00
|
|
|
if ((CapturedByteOffset.QuadPart != FILE_WRITE_TO_END_OF_FILE) &&
|
|
|
|
(CapturedByteOffset.QuadPart != FILE_USE_FILE_POINTER_POSITION ||
|
2018-10-04 13:53:12 +08:00
|
|
|
!BooleanFlagOn(FileObject->Flags, FO_SYNCHRONOUS_IO)))
|
|
|
|
{
|
|
|
|
/* Release the file object and and fail */
|
|
|
|
ObDereferenceObject(FileObject);
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
2018-10-04 07:16:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-08 19:47:44 +08:00
|
|
|
/* Capture and probe the key */
|
|
|
|
if (Key) CapturedKey = ProbeForReadUlong(Key);
|
|
|
|
}
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
2006-11-08 19:47:44 +08:00
|
|
|
{
|
2015-04-03 11:40:53 +08:00
|
|
|
/* Release the file object and return the exception code */
|
|
|
|
ObDereferenceObject(FileObject);
|
2009-08-27 01:31:02 +08:00
|
|
|
_SEH2_YIELD(return _SEH2_GetExceptionCode());
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_END;
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Kernel mode: capture directly */
|
|
|
|
if (ByteOffset) CapturedByteOffset = *ByteOffset;
|
|
|
|
if (Key) CapturedKey = *Key;
|
|
|
|
}
|
|
|
|
|
2020-12-19 00:21:01 +08:00
|
|
|
/* Check for invalid offset */
|
|
|
|
if (CapturedByteOffset.QuadPart < -2)
|
|
|
|
{
|
|
|
|
/* -1 is FILE_WRITE_TO_END_OF_FILE */
|
|
|
|
/* -2 is FILE_USE_FILE_POINTER_POSITION */
|
|
|
|
ObDereferenceObject(FileObject);
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
2006-11-08 19:47:44 +08:00
|
|
|
/* Check if this is an append operation */
|
|
|
|
if ((ObjectHandleInfo.GrantedAccess &
|
|
|
|
(FILE_APPEND_DATA | FILE_WRITE_DATA)) == FILE_APPEND_DATA)
|
|
|
|
{
|
|
|
|
/* Give the drivers something to understand */
|
|
|
|
CapturedByteOffset.u.LowPart = FILE_WRITE_TO_END_OF_FILE;
|
|
|
|
CapturedByteOffset.u.HighPart = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for event */
|
|
|
|
if (Event)
|
|
|
|
{
|
|
|
|
/* Reference it */
|
|
|
|
Status = ObReferenceObjectByHandle(Event,
|
|
|
|
EVENT_MODIFY_STATE,
|
|
|
|
ExEventObjectType,
|
|
|
|
PreviousMode,
|
|
|
|
(PVOID*)&EventObject,
|
|
|
|
NULL);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* Fail */
|
|
|
|
ObDereferenceObject(FileObject);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Otherwise reset the event */
|
|
|
|
KeClearEvent(EventObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if we should use Sync IO or not */
|
|
|
|
if (FileObject->Flags & FO_SYNCHRONOUS_IO)
|
|
|
|
{
|
|
|
|
/* Lock the file object */
|
2018-10-02 15:55:07 +08:00
|
|
|
Status = IopLockFileObject(FileObject, PreviousMode);
|
|
|
|
if (Status != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
if (EventObject) ObDereferenceObject(EventObject);
|
|
|
|
ObDereferenceObject(FileObject);
|
|
|
|
return Status;
|
|
|
|
}
|
2006-11-08 19:47:44 +08:00
|
|
|
|
2015-05-01 21:20:26 +08:00
|
|
|
/* Check if we don't have a byte offset available */
|
2006-11-08 19:47:44 +08:00
|
|
|
if (!(ByteOffset) ||
|
|
|
|
((CapturedByteOffset.u.LowPart == FILE_USE_FILE_POINTER_POSITION) &&
|
|
|
|
(CapturedByteOffset.u.HighPart == -1)))
|
|
|
|
{
|
|
|
|
/* Use the Current Byte Offset instead */
|
|
|
|
CapturedByteOffset = FileObject->CurrentByteOffset;
|
|
|
|
}
|
|
|
|
|
2015-05-01 21:20:26 +08:00
|
|
|
/* If the file is cached, try fast I/O */
|
|
|
|
if (FileObject->PrivateCacheMap)
|
|
|
|
{
|
2016-02-29 21:59:32 +08:00
|
|
|
/* Perform fast write */
|
2015-05-01 21:20:26 +08:00
|
|
|
FastIoDispatch = DeviceObject->DriverObject->FastIoDispatch;
|
2016-03-01 05:45:44 +08:00
|
|
|
ASSERT(FastIoDispatch != NULL && FastIoDispatch->FastIoWrite != NULL);
|
|
|
|
|
|
|
|
Success = FastIoDispatch->FastIoWrite(FileObject,
|
|
|
|
&CapturedByteOffset,
|
|
|
|
Length,
|
|
|
|
TRUE,
|
|
|
|
CapturedKey,
|
|
|
|
Buffer,
|
|
|
|
&KernelIosb,
|
|
|
|
DeviceObject);
|
|
|
|
|
|
|
|
/* Only accept the result if it was successful */
|
|
|
|
if (Success &&
|
|
|
|
KernelIosb.Status == STATUS_SUCCESS)
|
2015-05-01 21:20:26 +08:00
|
|
|
{
|
2016-03-01 05:45:44 +08:00
|
|
|
/* Fast path -- update transfer & operation counts */
|
|
|
|
IopUpdateOperationCount(IopWriteTransfer);
|
|
|
|
IopUpdateTransferCount(IopWriteTransfer,
|
|
|
|
(ULONG)KernelIosb.Information);
|
2016-02-29 21:59:32 +08:00
|
|
|
|
2016-03-01 05:45:44 +08:00
|
|
|
/* Enter SEH to write the IOSB back */
|
|
|
|
_SEH2_TRY
|
|
|
|
{
|
|
|
|
/* Write it back to the caller */
|
|
|
|
*IoStatusBlock = KernelIosb;
|
|
|
|
}
|
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
|
|
|
/* The caller's IOSB was invalid, so fail */
|
|
|
|
if (EventObject) ObDereferenceObject(EventObject);
|
2015-05-01 21:20:26 +08:00
|
|
|
IopUnlockFileObject(FileObject);
|
|
|
|
ObDereferenceObject(FileObject);
|
2016-03-01 05:45:44 +08:00
|
|
|
_SEH2_YIELD(return _SEH2_GetExceptionCode());
|
|
|
|
}
|
|
|
|
_SEH2_END;
|
|
|
|
|
|
|
|
/* Signal the completion event */
|
|
|
|
if (EventObject)
|
|
|
|
{
|
|
|
|
KeSetEvent(EventObject, 0, FALSE);
|
|
|
|
ObDereferenceObject(EventObject);
|
2015-05-01 21:20:26 +08:00
|
|
|
}
|
2016-03-01 05:45:44 +08:00
|
|
|
|
|
|
|
/* Clean up */
|
|
|
|
IopUnlockFileObject(FileObject);
|
|
|
|
ObDereferenceObject(FileObject);
|
|
|
|
return KernelIosb.Status;
|
2015-05-01 21:20:26 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-24 00:30:14 +08:00
|
|
|
/* Remember we are sync */
|
2006-11-08 19:47:44 +08:00
|
|
|
Synchronous = TRUE;
|
|
|
|
}
|
|
|
|
else if (!(ByteOffset) &&
|
|
|
|
!(FileObject->Flags & (FO_NAMED_PIPE | FO_MAILSLOT)))
|
|
|
|
{
|
|
|
|
/* Otherwise, this was async I/O without a byte offset, so fail */
|
|
|
|
if (EventObject) ObDereferenceObject(EventObject);
|
|
|
|
ObDereferenceObject(FileObject);
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear the File Object's event */
|
|
|
|
KeClearEvent(&FileObject->Event);
|
|
|
|
|
|
|
|
/* Allocate the IRP */
|
|
|
|
Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
|
2015-05-01 19:57:51 +08:00
|
|
|
if (!Irp) return IopCleanupFailedIrp(FileObject, EventObject, NULL);
|
2006-11-08 19:47:44 +08:00
|
|
|
|
|
|
|
/* Set the IRP */
|
|
|
|
Irp->Tail.Overlay.OriginalFileObject = FileObject;
|
|
|
|
Irp->Tail.Overlay.Thread = PsGetCurrentThread();
|
2008-10-30 23:59:00 +08:00
|
|
|
Irp->RequestorMode = PreviousMode;
|
2006-11-08 19:47:44 +08:00
|
|
|
Irp->Overlay.AsynchronousParameters.UserApcRoutine = ApcRoutine;
|
|
|
|
Irp->Overlay.AsynchronousParameters.UserApcContext = ApcContext;
|
|
|
|
Irp->UserIosb = IoStatusBlock;
|
|
|
|
Irp->UserEvent = EventObject;
|
|
|
|
Irp->PendingReturned = FALSE;
|
|
|
|
Irp->Cancel = FALSE;
|
|
|
|
Irp->CancelRoutine = NULL;
|
|
|
|
Irp->AssociatedIrp.SystemBuffer = NULL;
|
|
|
|
Irp->MdlAddress = NULL;
|
|
|
|
|
|
|
|
/* Set the Stack Data */
|
|
|
|
StackPtr = IoGetNextIrpStackLocation(Irp);
|
|
|
|
StackPtr->MajorFunction = IRP_MJ_WRITE;
|
|
|
|
StackPtr->FileObject = FileObject;
|
|
|
|
StackPtr->Flags = FileObject->Flags & FO_WRITE_THROUGH ?
|
|
|
|
SL_WRITE_THROUGH : 0;
|
|
|
|
StackPtr->Parameters.Write.Key = CapturedKey;
|
|
|
|
StackPtr->Parameters.Write.Length = Length;
|
|
|
|
StackPtr->Parameters.Write.ByteOffset = CapturedByteOffset;
|
|
|
|
|
|
|
|
/* Check if this is buffered I/O */
|
|
|
|
if (DeviceObject->Flags & DO_BUFFERED_IO)
|
|
|
|
{
|
|
|
|
/* Check if we have a buffer length */
|
|
|
|
if (Length)
|
|
|
|
{
|
2024-04-22 16:50:59 +08:00
|
|
|
/* Enter SEH (ExAllocatePoolWithQuotaTag raises on failure!) */
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_TRY
|
2006-11-08 19:47:44 +08:00
|
|
|
{
|
|
|
|
/* Allocate a buffer */
|
|
|
|
Irp->AssociatedIrp.SystemBuffer =
|
2024-04-22 16:50:59 +08:00
|
|
|
ExAllocatePoolWithQuotaTag(NonPagedPool, Length, TAG_SYSB);
|
2006-11-08 19:47:44 +08:00
|
|
|
|
|
|
|
/* Copy the data into it */
|
|
|
|
RtlCopyMemory(Irp->AssociatedIrp.SystemBuffer, Buffer, Length);
|
|
|
|
}
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
2006-11-08 19:47:44 +08:00
|
|
|
{
|
2009-08-27 01:31:02 +08:00
|
|
|
/* Allocating failed, clean up and return the exception code */
|
2008-12-22 02:16:12 +08:00
|
|
|
IopCleanupAfterException(FileObject, Irp, EventObject, NULL);
|
2009-08-27 01:31:02 +08:00
|
|
|
_SEH2_YIELD(return _SEH2_GetExceptionCode());
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_END;
|
2006-11-08 19:47:44 +08:00
|
|
|
|
|
|
|
/* Set the flags */
|
|
|
|
Irp->Flags = (IRP_BUFFERED_IO | IRP_DEALLOCATE_BUFFER);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Not writing anything */
|
|
|
|
Irp->Flags = IRP_BUFFERED_IO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (DeviceObject->Flags & DO_DIRECT_IO)
|
|
|
|
{
|
|
|
|
/* Check if we have a buffer length */
|
|
|
|
if (Length)
|
|
|
|
{
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_TRY
|
2008-01-30 21:33:16 +08:00
|
|
|
{
|
|
|
|
/* Allocate an MDL */
|
|
|
|
Mdl = IoAllocateMdl(Buffer, Length, FALSE, TRUE, Irp);
|
2014-08-06 02:47:25 +08:00
|
|
|
if (!Mdl)
|
|
|
|
ExRaiseStatus(STATUS_INSUFFICIENT_RESOURCES);
|
2008-01-30 21:33:16 +08:00
|
|
|
MmProbeAndLockPages(Mdl, PreviousMode, IoReadAccess);
|
|
|
|
}
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
2008-01-30 21:33:16 +08:00
|
|
|
{
|
2009-08-27 01:31:02 +08:00
|
|
|
/* Allocating failed, clean up and return the exception code */
|
2008-12-22 02:16:12 +08:00
|
|
|
IopCleanupAfterException(FileObject, Irp, EventObject, NULL);
|
2009-08-27 01:31:02 +08:00
|
|
|
_SEH2_YIELD(return _SEH2_GetExceptionCode());
|
2008-01-30 21:33:16 +08:00
|
|
|
}
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_END;
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* No allocation flags */
|
|
|
|
Irp->Flags = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* No allocation flags, and use the buffer directly */
|
|
|
|
Irp->Flags = 0;
|
|
|
|
Irp->UserBuffer = Buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now set the deferred read flags */
|
|
|
|
Irp->Flags |= (IRP_WRITE_OPERATION | IRP_DEFER_IO_COMPLETION);
|
2020-12-04 16:13:01 +08:00
|
|
|
|
2006-11-08 19:47:44 +08:00
|
|
|
if (FileObject->Flags & FO_NO_INTERMEDIATE_BUFFERING) Irp->Flags |= IRP_NOCACHE;
|
|
|
|
|
|
|
|
/* Perform the call */
|
|
|
|
return IopPerformSynchronousRequest(DeviceObject,
|
|
|
|
Irp,
|
|
|
|
FileObject,
|
|
|
|
TRUE,
|
|
|
|
PreviousMode,
|
|
|
|
Synchronous,
|
|
|
|
IopWriteTransfer);
|
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
NtWriteFileGather(IN HANDLE FileHandle,
|
|
|
|
IN HANDLE Event OPTIONAL,
|
|
|
|
IN PIO_APC_ROUTINE UserApcRoutine OPTIONAL,
|
|
|
|
IN PVOID UserApcContext OPTIONAL,
|
|
|
|
OUT PIO_STATUS_BLOCK UserIoStatusBlock,
|
|
|
|
IN FILE_SEGMENT_ELEMENT BufferDescription [],
|
|
|
|
IN ULONG BufferLength,
|
|
|
|
IN PLARGE_INTEGER ByteOffset,
|
|
|
|
IN PULONG Key OPTIONAL)
|
|
|
|
{
|
|
|
|
UNIMPLEMENTED;
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
NtQueryVolumeInformationFile(IN HANDLE FileHandle,
|
|
|
|
OUT PIO_STATUS_BLOCK IoStatusBlock,
|
|
|
|
OUT PVOID FsInformation,
|
|
|
|
IN ULONG Length,
|
|
|
|
IN FS_INFORMATION_CLASS FsInformationClass)
|
|
|
|
{
|
|
|
|
PFILE_OBJECT FileObject;
|
2007-04-02 23:08:54 +08:00
|
|
|
PIRP Irp;
|
|
|
|
PIO_STACK_LOCATION StackPtr;
|
|
|
|
PDEVICE_OBJECT DeviceObject;
|
2006-11-08 19:47:44 +08:00
|
|
|
PKEVENT Event = NULL;
|
|
|
|
BOOLEAN LocalEvent = FALSE;
|
|
|
|
KPROCESSOR_MODE PreviousMode = KeGetPreviousMode();
|
2009-08-27 01:31:02 +08:00
|
|
|
NTSTATUS Status;
|
2006-11-08 19:47:44 +08:00
|
|
|
IO_STATUS_BLOCK KernelIosb;
|
|
|
|
PAGED_CODE();
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
IOTRACE(IO_API_DEBUG, "FileHandle: %p\n", FileHandle);
|
2006-11-08 19:47:44 +08:00
|
|
|
|
|
|
|
/* Check if we're called from user mode */
|
|
|
|
if (PreviousMode != KernelMode)
|
|
|
|
{
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
/* Validate the information class */
|
2019-01-19 18:35:18 +08:00
|
|
|
if ((FsInformationClass < 0) ||
|
|
|
|
(FsInformationClass >= FileFsMaximumInformation) ||
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
!(IopQueryFsOperationLength[FsInformationClass]))
|
|
|
|
{
|
|
|
|
/* Invalid class */
|
|
|
|
return STATUS_INVALID_INFO_CLASS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Validate the length */
|
|
|
|
if (Length < IopQueryFsOperationLength[FsInformationClass])
|
|
|
|
{
|
|
|
|
/* Invalid length */
|
|
|
|
return STATUS_INFO_LENGTH_MISMATCH;
|
|
|
|
}
|
|
|
|
|
2006-11-08 19:47:44 +08:00
|
|
|
/* Enter SEH for probing */
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_TRY
|
2006-11-08 19:47:44 +08:00
|
|
|
{
|
|
|
|
/* Probe the I/O Status block */
|
|
|
|
ProbeForWriteIoStatusBlock(IoStatusBlock);
|
|
|
|
|
|
|
|
/* Probe the information */
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
ProbeForWrite(FsInformation, Length, sizeof(ULONG));
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
2006-11-08 19:47:44 +08:00
|
|
|
{
|
2009-08-27 01:31:02 +08:00
|
|
|
/* Return the exception code */
|
|
|
|
_SEH2_YIELD(return _SEH2_GetExceptionCode());
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_END;
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get File Object */
|
|
|
|
Status = ObReferenceObjectByHandle(FileHandle,
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
IopQueryFsOperationAccess
|
|
|
|
[FsInformationClass],
|
2006-11-08 19:47:44 +08:00
|
|
|
IoFileObjectType,
|
|
|
|
PreviousMode,
|
|
|
|
(PVOID*)&FileObject,
|
|
|
|
NULL);
|
|
|
|
if (!NT_SUCCESS(Status)) return Status;
|
|
|
|
|
2019-03-29 05:39:15 +08:00
|
|
|
/* Only allow direct device open for FileFsDeviceInformation */
|
|
|
|
if (BooleanFlagOn(FileObject->Flags, FO_DIRECT_DEVICE_OPEN) &&
|
|
|
|
FsInformationClass != FileFsDeviceInformation)
|
|
|
|
{
|
|
|
|
ObDereferenceObject(FileObject);
|
|
|
|
return STATUS_INVALID_DEVICE_REQUEST;
|
|
|
|
}
|
|
|
|
|
2006-11-08 19:47:44 +08:00
|
|
|
/* Check if we should use Sync IO or not */
|
|
|
|
if (FileObject->Flags & FO_SYNCHRONOUS_IO)
|
|
|
|
{
|
|
|
|
/* Lock it */
|
2018-10-02 15:55:07 +08:00
|
|
|
Status = IopLockFileObject(FileObject, PreviousMode);
|
|
|
|
if (Status != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
ObDereferenceObject(FileObject);
|
|
|
|
return Status;
|
|
|
|
}
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
|
|
|
|
2019-03-29 05:29:22 +08:00
|
|
|
/*
|
|
|
|
* Quick path for FileFsDeviceInformation - the kernel has enough
|
|
|
|
* info to reply instead of the driver, excepted for network file systems
|
|
|
|
*/
|
|
|
|
if (FsInformationClass == FileFsDeviceInformation &&
|
|
|
|
(BooleanFlagOn(FileObject->Flags, FO_DIRECT_DEVICE_OPEN) || FileObject->DeviceObject->DeviceType != FILE_DEVICE_NETWORK_FILE_SYSTEM))
|
|
|
|
{
|
|
|
|
PFILE_FS_DEVICE_INFORMATION FsDeviceInfo = FsInformation;
|
|
|
|
DeviceObject = FileObject->DeviceObject;
|
|
|
|
|
|
|
|
_SEH2_TRY
|
|
|
|
{
|
|
|
|
FsDeviceInfo->DeviceType = DeviceObject->DeviceType;
|
|
|
|
|
|
|
|
/* Complete characteristcs with mount status if relevant */
|
|
|
|
FsDeviceInfo->Characteristics = DeviceObject->Characteristics;
|
|
|
|
if (IopGetMountFlag(DeviceObject))
|
|
|
|
{
|
|
|
|
SetFlag(FsDeviceInfo->Characteristics, FILE_DEVICE_IS_MOUNTED);
|
|
|
|
}
|
|
|
|
|
|
|
|
IoStatusBlock->Information = sizeof(FILE_FS_DEVICE_INFORMATION);
|
|
|
|
IoStatusBlock->Status = STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
2019-03-30 04:47:34 +08:00
|
|
|
/* Check if we had a file lock */
|
|
|
|
if (BooleanFlagOn(FileObject->Flags, FO_SYNCHRONOUS_IO))
|
|
|
|
{
|
|
|
|
/* Release it */
|
|
|
|
IopUnlockFileObject(FileObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Dereference the FO */
|
|
|
|
ObDereferenceObject(FileObject);
|
|
|
|
|
2019-03-29 05:29:22 +08:00
|
|
|
_SEH2_YIELD(return _SEH2_GetExceptionCode());
|
|
|
|
}
|
|
|
|
_SEH2_END;
|
|
|
|
|
2019-03-30 04:47:34 +08:00
|
|
|
/* Check if we had a file lock */
|
|
|
|
if (BooleanFlagOn(FileObject->Flags, FO_SYNCHRONOUS_IO))
|
|
|
|
{
|
|
|
|
/* Release it */
|
|
|
|
IopUnlockFileObject(FileObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Dereference the FO */
|
|
|
|
ObDereferenceObject(FileObject);
|
2019-03-29 05:29:22 +08:00
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
2019-03-30 04:42:42 +08:00
|
|
|
/* This is to be handled by the kernel, not by FSD */
|
|
|
|
else if (FsInformationClass == FileFsDriverPathInformation)
|
|
|
|
{
|
2021-10-28 23:23:02 +08:00
|
|
|
_SEH2_VOLATILE PFILE_FS_DRIVER_PATH_INFORMATION DriverPathInfo = NULL;
|
2019-03-30 04:42:42 +08:00
|
|
|
|
2024-04-22 16:50:59 +08:00
|
|
|
/* Enter SEH (ExAllocatePoolWithQuotaTag raises on failure!) */
|
2019-03-30 04:42:42 +08:00
|
|
|
_SEH2_TRY
|
|
|
|
{
|
|
|
|
/* Allocate our local structure */
|
|
|
|
DriverPathInfo = ExAllocatePoolWithQuotaTag(NonPagedPool, Length, TAG_IO);
|
|
|
|
|
|
|
|
/* And copy back caller data */
|
|
|
|
RtlCopyMemory(DriverPathInfo, FsInformation, Length);
|
|
|
|
|
|
|
|
/* Is the driver in the IO path? */
|
2021-10-28 23:23:02 +08:00
|
|
|
Status = IopGetDriverPathInformation(FileObject,
|
|
|
|
(PFILE_FS_DRIVER_PATH_INFORMATION)DriverPathInfo,
|
|
|
|
Length);
|
2019-03-30 04:42:42 +08:00
|
|
|
/* We failed, don't continue execution */
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
RtlRaiseStatus(Status);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We succeed, copy back info */
|
|
|
|
((PFILE_FS_DRIVER_PATH_INFORMATION)FsInformation)->DriverInPath = DriverPathInfo->DriverInPath;
|
|
|
|
|
|
|
|
/* We're done */
|
|
|
|
IoStatusBlock->Information = sizeof(FILE_FS_DRIVER_PATH_INFORMATION);
|
|
|
|
IoStatusBlock->Status = STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
|
|
|
Status = _SEH2_GetExceptionCode();
|
|
|
|
}
|
|
|
|
_SEH2_END;
|
|
|
|
|
|
|
|
/* Don't leak */
|
|
|
|
if (DriverPathInfo != NULL)
|
|
|
|
{
|
|
|
|
ExFreePoolWithTag(DriverPathInfo, TAG_IO);
|
|
|
|
}
|
|
|
|
|
2019-03-30 04:47:34 +08:00
|
|
|
/* Check if we had a file lock */
|
|
|
|
if (BooleanFlagOn(FileObject->Flags, FO_SYNCHRONOUS_IO))
|
|
|
|
{
|
|
|
|
/* Release it */
|
|
|
|
IopUnlockFileObject(FileObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Dereference the FO */
|
|
|
|
ObDereferenceObject(FileObject);
|
2019-03-30 04:42:42 +08:00
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
2019-03-29 05:29:22 +08:00
|
|
|
|
2019-03-30 04:47:34 +08:00
|
|
|
if (!BooleanFlagOn(FileObject->Flags, FO_SYNCHRONOUS_IO))
|
|
|
|
{
|
|
|
|
/* Use local event */
|
|
|
|
Event = ExAllocatePoolWithTag(NonPagedPool, sizeof(KEVENT), TAG_IO);
|
|
|
|
if (!Event)
|
|
|
|
{
|
|
|
|
ObDereferenceObject(FileObject);
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
}
|
|
|
|
KeInitializeEvent(Event, SynchronizationEvent, FALSE);
|
|
|
|
LocalEvent = TRUE;
|
|
|
|
}
|
|
|
|
|
2006-11-08 19:47:44 +08:00
|
|
|
/* Get the device object */
|
|
|
|
DeviceObject = IoGetRelatedDeviceObject(FileObject);
|
|
|
|
|
|
|
|
/* Clear File Object event */
|
|
|
|
KeClearEvent(&FileObject->Event);
|
|
|
|
|
|
|
|
/* Allocate the IRP */
|
|
|
|
Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
|
|
|
|
if (!Irp) return IopCleanupFailedIrp(FileObject, NULL, Event);
|
|
|
|
|
|
|
|
/* Set up the IRP */
|
|
|
|
Irp->RequestorMode = PreviousMode;
|
|
|
|
Irp->Flags = (LocalEvent) ? IRP_SYNCHRONOUS_API : 0;
|
|
|
|
Irp->UserIosb = (LocalEvent) ? &KernelIosb : IoStatusBlock;
|
|
|
|
Irp->UserEvent = (LocalEvent) ? Event : NULL;
|
|
|
|
Irp->Tail.Overlay.Thread = PsGetCurrentThread();
|
|
|
|
Irp->Tail.Overlay.OriginalFileObject = FileObject;
|
|
|
|
Irp->Overlay.AsynchronousParameters.UserApcRoutine = NULL;
|
|
|
|
Irp->UserBuffer = FsInformation;
|
|
|
|
Irp->AssociatedIrp.SystemBuffer = NULL;
|
|
|
|
Irp->MdlAddress = NULL;
|
|
|
|
|
|
|
|
/* Set up Stack Data */
|
|
|
|
StackPtr = IoGetNextIrpStackLocation(Irp);
|
|
|
|
StackPtr->MajorFunction = IRP_MJ_QUERY_VOLUME_INFORMATION;
|
|
|
|
StackPtr->FileObject = FileObject;
|
|
|
|
|
2024-04-22 16:50:59 +08:00
|
|
|
/* Enter SEH (ExAllocatePoolWithQuotaTag raises on failure!) */
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_TRY
|
2006-11-08 19:47:44 +08:00
|
|
|
{
|
|
|
|
/* Allocate a buffer */
|
|
|
|
Irp->AssociatedIrp.SystemBuffer =
|
2024-04-22 16:50:59 +08:00
|
|
|
ExAllocatePoolWithQuotaTag(NonPagedPool, Length, TAG_SYSB);
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
2006-11-08 19:47:44 +08:00
|
|
|
{
|
2009-08-27 01:31:02 +08:00
|
|
|
/* Allocating failed, clean up and return the exception code */
|
2006-11-08 19:47:44 +08:00
|
|
|
IopCleanupAfterException(FileObject, Irp, NULL, Event);
|
2009-08-27 01:31:02 +08:00
|
|
|
_SEH2_YIELD(return _SEH2_GetExceptionCode());
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_END;
|
2006-11-08 19:47:44 +08:00
|
|
|
|
|
|
|
/* Set the flags for this buffered + deferred I/O */
|
|
|
|
Irp->Flags |= (IRP_BUFFERED_IO |
|
|
|
|
IRP_DEALLOCATE_BUFFER |
|
|
|
|
IRP_INPUT_OPERATION |
|
|
|
|
IRP_DEFER_IO_COMPLETION);
|
|
|
|
|
|
|
|
/* Set Parameters */
|
|
|
|
StackPtr->Parameters.QueryVolume.Length = Length;
|
|
|
|
StackPtr->Parameters.QueryVolume.FsInformationClass = FsInformationClass;
|
|
|
|
|
|
|
|
/* Call the Driver */
|
|
|
|
Status = IopPerformSynchronousRequest(DeviceObject,
|
|
|
|
Irp,
|
|
|
|
FileObject,
|
|
|
|
TRUE,
|
|
|
|
PreviousMode,
|
|
|
|
!LocalEvent,
|
|
|
|
IopOtherTransfer);
|
|
|
|
|
|
|
|
/* Check if this was async I/O */
|
|
|
|
if (LocalEvent)
|
|
|
|
{
|
|
|
|
/* It was, finalize this request */
|
|
|
|
Status = IopFinalizeAsynchronousIo(Status,
|
|
|
|
Event,
|
|
|
|
Irp,
|
|
|
|
PreviousMode,
|
|
|
|
&KernelIosb,
|
|
|
|
IoStatusBlock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return status */
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
NtSetVolumeInformationFile(IN HANDLE FileHandle,
|
|
|
|
OUT PIO_STATUS_BLOCK IoStatusBlock,
|
|
|
|
IN PVOID FsInformation,
|
|
|
|
IN ULONG Length,
|
|
|
|
IN FS_INFORMATION_CLASS FsInformationClass)
|
|
|
|
{
|
|
|
|
PFILE_OBJECT FileObject;
|
2007-04-02 23:08:54 +08:00
|
|
|
PIRP Irp;
|
|
|
|
PIO_STACK_LOCATION StackPtr;
|
2010-08-18 00:04:46 +08:00
|
|
|
PDEVICE_OBJECT DeviceObject, TargetDeviceObject;
|
2006-11-08 19:47:44 +08:00
|
|
|
PKEVENT Event = NULL;
|
|
|
|
BOOLEAN LocalEvent = FALSE;
|
|
|
|
KPROCESSOR_MODE PreviousMode = KeGetPreviousMode();
|
2009-08-27 01:31:02 +08:00
|
|
|
NTSTATUS Status;
|
2006-11-08 19:47:44 +08:00
|
|
|
IO_STATUS_BLOCK KernelIosb;
|
2010-08-18 00:04:46 +08:00
|
|
|
TARGET_DEVICE_CUSTOM_NOTIFICATION NotificationStructure;
|
2006-11-08 19:47:44 +08:00
|
|
|
PAGED_CODE();
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
IOTRACE(IO_API_DEBUG, "FileHandle: %p\n", FileHandle);
|
2006-11-08 19:47:44 +08:00
|
|
|
|
|
|
|
/* Check if we're called from user mode */
|
|
|
|
if (PreviousMode != KernelMode)
|
|
|
|
{
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
/* Validate the information class */
|
2019-01-19 18:35:18 +08:00
|
|
|
if ((FsInformationClass < 0) ||
|
|
|
|
(FsInformationClass >= FileFsMaximumInformation) ||
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
!(IopSetFsOperationLength[FsInformationClass]))
|
|
|
|
{
|
|
|
|
/* Invalid class */
|
|
|
|
return STATUS_INVALID_INFO_CLASS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Validate the length */
|
|
|
|
if (Length < IopSetFsOperationLength[FsInformationClass])
|
|
|
|
{
|
|
|
|
/* Invalid length */
|
|
|
|
return STATUS_INFO_LENGTH_MISMATCH;
|
|
|
|
}
|
|
|
|
|
2006-11-08 19:47:44 +08:00
|
|
|
/* Enter SEH for probing */
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_TRY
|
2006-11-08 19:47:44 +08:00
|
|
|
{
|
|
|
|
/* Probe the I/O Status block */
|
|
|
|
ProbeForWriteIoStatusBlock(IoStatusBlock);
|
|
|
|
|
|
|
|
/* Probe the information */
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
ProbeForRead(FsInformation, Length, sizeof(ULONG));
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
2006-11-08 19:47:44 +08:00
|
|
|
{
|
2009-08-27 01:31:02 +08:00
|
|
|
/* Return the exception code */
|
|
|
|
_SEH2_YIELD(return _SEH2_GetExceptionCode());
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_END;
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get File Object */
|
|
|
|
Status = ObReferenceObjectByHandle(FileHandle,
|
- Fix SleepEx.
- Put volatile statements in EX_RUNDOWN_REF, IRP, DEVICE_OBJECT, ERESOURCE, FILE_OBJECT, IO_REMOVE_LOCK, WORK_QUEUE_ITEM where required (thanks to Microsoft's changes in the WDK to mark the fields properly).
- Update FILE_OBJECT definition.
- Add some asserts to some I/O functions.
- Add stub support for File Objects created by XP+ Drivers which have File Object Extensions.
- Add some fixes to IopDeleteFile, including proper reference counting for the DO and VPB, as well as cleanup when the file is closed without a handle.
- Fix a bug in IopSecurityFile.
- Queue and unqueue IRPs in all I/O functions.
- Fully support IRP cancellation now.
- Fix critical bugs in NtDeviceIoControlFile and NtDeviceFsControlFile which were causing double queueing of IRPs and freeing of invalid memory, as well as invalid paramter checking for user-mode buffers.
- Add exhaustive validation checks to IoCreateFile, add more failure cases, and validate the EA buffer. Also support IO_ATTACH_DEVICE_API flag.
- Implement IoCreateStreamFileObjectEx and IoCreateStreamFileObjectLite and fix several bugs in the original implementation of IoCreateStreamFileObject.
- Fix a bug in RtlRaiseException.
- Update Io*ShareAccess routines to support XP+ style semantics related to special File Object flags which disable their use.
- Add validation to all Query/Set routines so that information clasess, lengths, buffers and alignment are properly checked.
- Also add an array for the proper acess rights that each query/set operation requires.
- Check backup/restore privileges during I/O File operations.
- Check traverse access during I/O File Operations.
- Check access privileges to the device during I/O file operations.
- Rename IopReferenceDeviceObject and also verify if an exclusive DO is trying to be invalidly opened.
- Support various extra security checks during I/O File/Device Parse Routine.
- Fix a bug during IopCleanupIrp so that we don't dereference the File OBject if this was a create operation.
- Fix some bogus asserts in IofCompleteRequest, and save the IRP Flags before signalling it's event, since the driver might've freed it behind our back.
- Fix a large bug in ObInsertObject which affected the insert of unnamed objects with forced security options (Such as process/threads).
- Fix the creation of the Process/Thread/Job Obejct Types to that security information is forced.
- Remove "Fix PS!!!" messages since the bug is now fixed and these objects now get proper security descriptors.
- Fix another bug in ObInsertObjet which wasn't properly validating user-mode objects and always assumed kernel mode.
- Silence multiple trace/checkpoint messages that have accumulated throughout time for various debugging purposes.
svn path=/trunk/; revision=25118
2006-12-11 02:40:30 +08:00
|
|
|
IopSetFsOperationAccess
|
|
|
|
[FsInformationClass],
|
2006-11-08 19:47:44 +08:00
|
|
|
IoFileObjectType,
|
|
|
|
PreviousMode,
|
|
|
|
(PVOID*)&FileObject,
|
|
|
|
NULL);
|
|
|
|
if (!NT_SUCCESS(Status)) return Status;
|
|
|
|
|
2010-08-18 00:04:46 +08:00
|
|
|
/* Get target device for notification */
|
|
|
|
Status = IoGetRelatedTargetDevice(FileObject, &TargetDeviceObject);
|
|
|
|
if (!NT_SUCCESS(Status)) TargetDeviceObject = NULL;
|
|
|
|
|
2006-11-08 19:47:44 +08:00
|
|
|
/* Check if we should use Sync IO or not */
|
|
|
|
if (FileObject->Flags & FO_SYNCHRONOUS_IO)
|
|
|
|
{
|
|
|
|
/* Lock it */
|
2018-10-02 15:55:07 +08:00
|
|
|
Status = IopLockFileObject(FileObject, PreviousMode);
|
|
|
|
if (Status != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
ObDereferenceObject(FileObject);
|
|
|
|
if (TargetDeviceObject) ObDereferenceObject(TargetDeviceObject);
|
|
|
|
return Status;
|
|
|
|
}
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Use local event */
|
|
|
|
Event = ExAllocatePoolWithTag(NonPagedPool, sizeof(KEVENT), TAG_IO);
|
2009-09-02 21:02:30 +08:00
|
|
|
if (!Event)
|
|
|
|
{
|
|
|
|
ObDereferenceObject(FileObject);
|
2010-08-18 00:04:46 +08:00
|
|
|
if (TargetDeviceObject) ObDereferenceObject(TargetDeviceObject);
|
2009-09-02 21:02:30 +08:00
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
}
|
2006-11-08 19:47:44 +08:00
|
|
|
KeInitializeEvent(Event, SynchronizationEvent, FALSE);
|
|
|
|
LocalEvent = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the device object */
|
2009-01-04 18:12:38 +08:00
|
|
|
DeviceObject = IoGetRelatedDeviceObject(FileObject);
|
2006-11-08 19:47:44 +08:00
|
|
|
|
|
|
|
/* Clear File Object event */
|
|
|
|
KeClearEvent(&FileObject->Event);
|
|
|
|
|
|
|
|
/* Allocate the IRP */
|
|
|
|
Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
|
2010-08-18 00:04:46 +08:00
|
|
|
if (!Irp)
|
|
|
|
{
|
|
|
|
if (TargetDeviceObject) ObDereferenceObject(TargetDeviceObject);
|
|
|
|
return IopCleanupFailedIrp(FileObject, NULL, Event);
|
|
|
|
}
|
2006-11-08 19:47:44 +08:00
|
|
|
|
|
|
|
/* Set up the IRP */
|
|
|
|
Irp->RequestorMode = PreviousMode;
|
|
|
|
Irp->Flags = (LocalEvent) ? IRP_SYNCHRONOUS_API : 0;
|
|
|
|
Irp->UserIosb = (LocalEvent) ? &KernelIosb : IoStatusBlock;
|
|
|
|
Irp->UserEvent = (LocalEvent) ? Event : NULL;
|
|
|
|
Irp->Tail.Overlay.Thread = PsGetCurrentThread();
|
|
|
|
Irp->Tail.Overlay.OriginalFileObject = FileObject;
|
|
|
|
Irp->Overlay.AsynchronousParameters.UserApcRoutine = NULL;
|
|
|
|
Irp->UserBuffer = FsInformation;
|
|
|
|
Irp->AssociatedIrp.SystemBuffer = NULL;
|
|
|
|
Irp->MdlAddress = NULL;
|
|
|
|
|
|
|
|
/* Set up Stack Data */
|
|
|
|
StackPtr = IoGetNextIrpStackLocation(Irp);
|
|
|
|
StackPtr->MajorFunction = IRP_MJ_SET_VOLUME_INFORMATION;
|
|
|
|
StackPtr->FileObject = FileObject;
|
|
|
|
|
2024-04-22 16:50:59 +08:00
|
|
|
/* Enter SEH (ExAllocatePoolWithQuotaTag raises on failure!) */
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_TRY
|
2006-11-08 19:47:44 +08:00
|
|
|
{
|
|
|
|
/* Allocate a buffer */
|
|
|
|
Irp->AssociatedIrp.SystemBuffer =
|
2024-04-22 16:50:59 +08:00
|
|
|
ExAllocatePoolWithQuotaTag(NonPagedPool, Length, TAG_SYSB);
|
2006-11-08 19:47:44 +08:00
|
|
|
|
|
|
|
/* Copy the data into it */
|
|
|
|
RtlCopyMemory(Irp->AssociatedIrp.SystemBuffer, FsInformation, Length);
|
|
|
|
}
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
2006-11-08 19:47:44 +08:00
|
|
|
{
|
2009-08-27 01:31:02 +08:00
|
|
|
/* Allocating failed, clean up and return the exception code */
|
2006-11-08 19:47:44 +08:00
|
|
|
IopCleanupAfterException(FileObject, Irp, NULL, Event);
|
2010-08-18 00:04:46 +08:00
|
|
|
if (TargetDeviceObject) ObDereferenceObject(TargetDeviceObject);
|
2009-08-27 01:31:02 +08:00
|
|
|
_SEH2_YIELD(return _SEH2_GetExceptionCode());
|
2006-11-08 19:47:44 +08:00
|
|
|
}
|
2008-11-24 21:40:26 +08:00
|
|
|
_SEH2_END;
|
2006-11-08 19:47:44 +08:00
|
|
|
|
|
|
|
/* Set the flags for this buffered + deferred I/O */
|
|
|
|
Irp->Flags |= (IRP_BUFFERED_IO | IRP_DEALLOCATE_BUFFER);
|
|
|
|
|
|
|
|
/* Set Parameters */
|
|
|
|
StackPtr->Parameters.SetVolume.Length = Length;
|
|
|
|
StackPtr->Parameters.SetVolume.FsInformationClass = FsInformationClass;
|
|
|
|
|
|
|
|
/* Call the Driver */
|
|
|
|
Status = IopPerformSynchronousRequest(DeviceObject,
|
|
|
|
Irp,
|
|
|
|
FileObject,
|
2008-07-30 21:13:52 +08:00
|
|
|
FALSE,
|
2006-11-08 19:47:44 +08:00
|
|
|
PreviousMode,
|
|
|
|
!LocalEvent,
|
|
|
|
IopOtherTransfer);
|
|
|
|
|
|
|
|
/* Check if this was async I/O */
|
|
|
|
if (LocalEvent)
|
|
|
|
{
|
|
|
|
/* It was, finalize this request */
|
|
|
|
Status = IopFinalizeAsynchronousIo(Status,
|
|
|
|
Event,
|
|
|
|
Irp,
|
|
|
|
PreviousMode,
|
|
|
|
&KernelIosb,
|
|
|
|
IoStatusBlock);
|
|
|
|
}
|
|
|
|
|
2010-08-18 00:04:46 +08:00
|
|
|
if (TargetDeviceObject && NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* Time to report change */
|
|
|
|
NotificationStructure.Version = 1;
|
|
|
|
NotificationStructure.Size = sizeof(TARGET_DEVICE_CUSTOM_NOTIFICATION);
|
|
|
|
NotificationStructure.Event = GUID_IO_VOLUME_NAME_CHANGE;
|
|
|
|
NotificationStructure.FileObject = NULL;
|
|
|
|
NotificationStructure.NameBufferOffset = - 1;
|
|
|
|
Status = IoReportTargetDeviceChange(TargetDeviceObject, &NotificationStructure);
|
|
|
|
}
|
|
|
|
|
2006-11-08 19:47:44 +08:00
|
|
|
/* Return status */
|
|
|
|
return Status;
|
|
|
|
}
|
2008-01-06 01:29:44 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @unimplemented
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
NtCancelDeviceWakeupRequest(IN HANDLE DeviceHandle)
|
|
|
|
{
|
|
|
|
UNIMPLEMENTED;
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @unimplemented
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
NtRequestDeviceWakeup(IN HANDLE DeviceHandle)
|
|
|
|
{
|
|
|
|
UNIMPLEMENTED;
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|