https://git.reactos.org/?p=reactos.git;a=commitdiff;h=1d777ffab5458495c04f2…
commit 1d777ffab5458495c04f250cf7ced379f306a7af
Author: Pierre Schweitzer <pierre(a)reactos.org>
AuthorDate: Sun Nov 12 22:33:58 2017 +0100
[NTOSKNRL] In NtWriteFile, remove the check that is now redundant with ObReferenceFileObjectForWrite().
CORE-14003
---
ntoskrnl/io/iomgr/iofunc.c | 15 ---------------
1 file changed, 15 deletions(-)
diff --git a/ntoskrnl/io/iomgr/iofunc.c b/ntoskrnl/io/iomgr/iofunc.c
index 9ab983ac21..46fcce201d 100644
--- a/ntoskrnl/io/iomgr/iofunc.c
+++ b/ntoskrnl/io/iomgr/iofunc.c
@@ -3511,21 +3511,6 @@ NtWriteFile(IN HANDLE FileHandle,
{
_SEH2_TRY
{
- /*
- * Check if the handle has either FILE_WRITE_DATA or
- * FILE_APPEND_DATA 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);
- _SEH2_YIELD(return STATUS_ACCESS_DENIED);
- }
-
/* Probe the status block */
ProbeForWriteIoStatusBlock(IoStatusBlock);
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=c3d5a3f2bdff97f03b802…
commit c3d5a3f2bdff97f03b802fe95dce9d0c9375e53e
Author: Pierre Schweitzer <pierre(a)reactos.org>
AuthorDate: Sun Nov 12 22:32:16 2017 +0100
[NTOSKRNL] In NtWriteFile, quit using ObReferenceObjectByHandle in favor of ObReferenceFileObjectForWrite().
This avoids RO FSDs being called for write operations.
CORE-14003
---
ntoskrnl/io/iomgr/iofunc.c | 18 +++++-------------
1 file changed, 5 insertions(+), 13 deletions(-)
diff --git a/ntoskrnl/io/iomgr/iofunc.c b/ntoskrnl/io/iomgr/iofunc.c
index 93f1fe4e5f..9ab983ac21 100644
--- a/ntoskrnl/io/iomgr/iofunc.c
+++ b/ntoskrnl/io/iomgr/iofunc.c
@@ -3499,19 +3499,11 @@ NtWriteFile(IN HANDLE FileHandle,
CapturedByteOffset.QuadPart = 0;
IOTRACE(IO_API_DEBUG, "FileHandle: %p\n", FileHandle);
- /* Get File Object
- * FIXME: We should call ObReferenceFileObjectForWrite() instead to
- * check whether write access was actually granted. If not it will
- * fail and we will return.
- * That would allow avoiding ASSERT on FastIO later on if the FSD
- * is read-only
- */
- Status = ObReferenceObjectByHandle(FileHandle,
- 0,
- IoFileObjectType,
- PreviousMode,
- (PVOID*)&FileObject,
- &ObjectHandleInfo);
+ /* Get File Object for write */
+ Status = ObReferenceFileObjectForWrite(FileHandle,
+ PreviousMode,
+ &FileObject,
+ &ObjectHandleInfo);
if (!NT_SUCCESS(Status)) return Status;
/* Validate User-Mode Buffers */
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=da8134527b69a2a1bc019…
commit da8134527b69a2a1bc0193352dcb73b70762f613
Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
AuthorDate: Sun Nov 12 22:02:45 2017 +0100
[NTOS] Do not perform hive write operations when we are not supposed to.
- When we are in LiveCD mode (more generally, when hives are shared), load
the system hives as volatile.
- Ignore hive write operations when everything operates in read-only mode
and just return success instead.
- Just return success on hive file I/O if no file is associated with a
given hive. This happens when e.g. a CM hive has a primary but no log.
---
ntoskrnl/config/cmsysini.c | 8 ++++++--
ntoskrnl/config/cmwraprs.c | 24 ++++++++++++++++++++++++
2 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/ntoskrnl/config/cmsysini.c b/ntoskrnl/config/cmsysini.c
index 6b079ce0d4..112543fac7 100644
--- a/ntoskrnl/config/cmsysini.c
+++ b/ntoskrnl/config/cmsysini.c
@@ -900,7 +900,7 @@ CmpInitializeSystemHive(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
/* We imported, no need to create a new hive */
Allocate = FALSE;
- /* Manually set the hive as volatile, if in Live CD mode */
+ /* Manually set the hive as volatile, if in LiveCD mode */
if (CmpShareSystemHives) SystemHive->Hive.HiveFlags = HIVE_VOLATILE;
}
else
@@ -1433,9 +1433,13 @@ CmpInitializeHiveList(IN USHORT Flag)
/* Loop every hive we care about */
for (i = 0; i < CM_NUMBER_OF_MACHINE_HIVES; i++)
{
- /* Make sure the list is setup */
+ /* Make sure the list is set up */
ASSERT(CmpMachineHiveList[i].Name != NULL);
+ /* Load the hive as volatile, if in LiveCD mode */
+ if (CmpShareSystemHives)
+ CmpMachineHiveList[i].HHiveFlags |= HIVE_VOLATILE;
+
/* Create a thread to handle this hive */
Status = PsCreateSystemThread(&Thread,
THREAD_ALL_ACCESS,
diff --git a/ntoskrnl/config/cmwraprs.c b/ntoskrnl/config/cmwraprs.c
index 031dc77c00..0f5e47da92 100644
--- a/ntoskrnl/config/cmwraprs.c
+++ b/ntoskrnl/config/cmwraprs.c
@@ -82,6 +82,10 @@ CmpFileRead(IN PHHIVE RegistryHive,
IO_STATUS_BLOCK IoStatusBlock;
NTSTATUS Status;
+ /* Just return success if no file is associated with this hive */
+ if (HiveHandle == NULL)
+ return TRUE;
+
_FileOffset.QuadPart = *FileOffset;
Status = ZwReadFile(HiveHandle, NULL, NULL, NULL, &IoStatusBlock,
Buffer, (ULONG)BufferLength, &_FileOffset, NULL);
@@ -102,6 +106,14 @@ CmpFileWrite(IN PHHIVE RegistryHive,
IO_STATUS_BLOCK IoStatusBlock;
NTSTATUS Status;
+ /* Just return success if no file is associated with this hive */
+ if (HiveHandle == NULL)
+ return TRUE;
+
+ /* Don't do anything if we're not supposed to */
+ if (CmpNoWrite)
+ return TRUE;
+
_FileOffset.QuadPart = *FileOffset;
Status = ZwWriteFile(HiveHandle, NULL, NULL, NULL, &IoStatusBlock,
Buffer, (ULONG)BufferLength, &_FileOffset, NULL);
@@ -122,6 +134,10 @@ CmpFileSetSize(IN PHHIVE RegistryHive,
IO_STATUS_BLOCK IoStatusBlock;
NTSTATUS Status;
+ /* Just return success if no file is associated with this hive */
+ if (HiveHandle == NULL)
+ return TRUE;
+
EndOfFileInfo.EndOfFile.QuadPart = FileSize;
Status = ZwSetInformationFile(HiveHandle,
&IoStatusBlock,
@@ -153,6 +169,14 @@ CmpFileFlush(IN PHHIVE RegistryHive,
IO_STATUS_BLOCK IoStatusBlock;
NTSTATUS Status;
+ /* Just return success if no file is associated with this hive */
+ if (HiveHandle == NULL)
+ return TRUE;
+
+ /* Don't do anything if we're not supposed to */
+ if (CmpNoWrite)
+ return TRUE;
+
Status = ZwFlushBuffersFile(HiveHandle, &IoStatusBlock);
return NT_SUCCESS(Status) ? TRUE : FALSE;
}
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=5f255827d3282b2dea1bc…
commit 5f255827d3282b2dea1bc6d5ba77607550742ced
Author: Pierre Schweitzer <pierre(a)reactos.org>
AuthorDate: Sun Nov 12 21:16:31 2017 +0100
[CDFS_NEW] Following 1bef487, add a hack and stub FastIO write routine to avoid bugchecks on write attempts.
This allows booting the ReactOS LiveCD as HDD image in Qemu without issues :-)
---
drivers/filesystems/cdfs_new/cdinit.c | 36 +++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
diff --git a/drivers/filesystems/cdfs_new/cdinit.c b/drivers/filesystems/cdfs_new/cdinit.c
index b6bec14c45..1f086fe61d 100755
--- a/drivers/filesystems/cdfs_new/cdinit.c
+++ b/drivers/filesystems/cdfs_new/cdinit.c
@@ -58,6 +58,29 @@ CdShutdown (
#pragma alloc_text(INIT, CdInitializeGlobalData)
#endif
+#ifdef __REACTOS__
+
+//
+// Stub for CcWrite, this is a hack
+//
+BOOLEAN
+NTAPI
+CdFastIoWrite (
+ IN PFILE_OBJECT FileObject,
+ IN PLARGE_INTEGER FileOffset,
+ IN ULONG Length,
+ IN BOOLEAN Wait,
+ IN ULONG LockKey,
+ IN PVOID Buffer,
+ OUT PIO_STATUS_BLOCK IoStatus,
+ IN PDEVICE_OBJECT DeviceObject)
+{
+ ASSERT(FALSE);
+ return FALSE;
+}
+
+#endif
+
//
// Local support routine
@@ -342,6 +365,19 @@ Return Value:
CdFastIoDispatch.SizeOfFastIoDispatch = sizeof(FAST_IO_DISPATCH);
CdFastIoDispatch.FastIoCheckIfPossible = CdFastIoCheckIfPossible; // CheckForFastIo
CdFastIoDispatch.FastIoRead = FsRtlCopyRead; // Read
+#ifdef __REACTOS__
+
+ //
+ // Add a stub for CdFastIoWrite. This is a hack required because
+ // our current implementation of NtWriteFile won't validate
+ // access granted to files opened. And some applications may attempt
+ // to write to a file. In case it is cached, the kernel will null-dereference
+ // the fastIO routine, trying to call it.
+ // FIXME: remove once NtWriteFile got fixed!
+ //
+
+ CdFastIoDispatch.FastIoWrite = CdFastIoWrite; // Write
+#endif
CdFastIoDispatch.FastIoQueryBasicInfo = CdFastQueryBasicInfo; // QueryBasicInfo
CdFastIoDispatch.FastIoQueryStandardInfo = CdFastQueryStdInfo; // QueryStandardInfo
CdFastIoDispatch.FastIoLock = CdFastLock; // Lock
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=1bef48796e4df655c71dd…
commit 1bef48796e4df655c71ddd92a00417dbe9e530ca
Author: Pierre Schweitzer <pierre(a)reactos.org>
AuthorDate: Sun Nov 12 21:11:22 2017 +0100
[NTOSKRNL] Add a FIXME in NtWriteFile() that explains how broken is our current implementation regarding read-only FSDs
---
ntoskrnl/io/iomgr/iofunc.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/ntoskrnl/io/iomgr/iofunc.c b/ntoskrnl/io/iomgr/iofunc.c
index 5aa67ee3e1..93f1fe4e5f 100644
--- a/ntoskrnl/io/iomgr/iofunc.c
+++ b/ntoskrnl/io/iomgr/iofunc.c
@@ -3499,7 +3499,13 @@ NtWriteFile(IN HANDLE FileHandle,
CapturedByteOffset.QuadPart = 0;
IOTRACE(IO_API_DEBUG, "FileHandle: %p\n", FileHandle);
- /* Get File Object */
+ /* Get File Object
+ * FIXME: We should call ObReferenceFileObjectForWrite() instead to
+ * check whether write access was actually granted. If not it will
+ * fail and we will return.
+ * That would allow avoiding ASSERT on FastIO later on if the FSD
+ * is read-only
+ */
Status = ObReferenceObjectByHandle(FileHandle,
0,
IoFileObjectType,