Commit graph

598 commits

Author SHA1 Message Date
Timo Kreuzer 3410b25fde [NTOS] Turn broken assert into DPRINT 2019-01-19 13:38:24 +01:00
Timo Kreuzer 65dbfc2868
[NTOS:Mm] Rewrite MiWriteProtectSystemImage (#749)
* The previous version was overcomplicated and broken and therefore disabled.
* The new version also enforces NX protection on x64.
* Now that protecting works, also protect the boot loaded images.
2019-01-18 22:11:43 +01:00
Yaroslav Kibysh 0d86ab6a18 [NTOS:INBV] Update the boot screen's rotation bar's image (#1256)
Make it smoother than what it currently is.
2019-01-17 20:45:40 +01:00
Pierre Schweitzer d9a3fd16d4
[NTOSKRNL] Add support for callback when enumerating large pool allocations 2019-01-15 22:07:35 +01:00
Thomas Faber e7de564bfc
[NTOS:MM] Implement big pool table expansion. CORE-15051 2019-01-09 08:18:38 +01:00
Pierre Schweitzer a3f8813fff
[NTOSKRNL] Add support for large allocations in !poolfind 2019-01-08 08:43:23 +01:00
Pierre Schweitzer e1342127f0
[NTOSKRNL] In !irpfind, add info about current stack major/minor 2019-01-08 08:43:23 +01:00
Pierre Schweitzer e6a1851684
[NTOSKRNL] Misc fixes to !irpfind 2019-01-06 23:21:20 +01:00
Pierre Schweitzer 36f90e7e46
[NTOSKRNL] Move KDBG MM functions implementation to their own file 2019-01-06 22:50:57 +01:00
Pierre Schweitzer 25e14ae2a8
[NTOSKRNL] Fix !irpfind usage message 2019-01-06 13:00:43 +01:00
Pierre Schweitzer 28193399ee
[NTOSKRNL] Properly check for address validity in !poolfind 2019-01-06 12:58:14 +01:00
Pierre Schweitzer 47b48520b5
[NTOSKRNL] Reimplement !irpfind using !poolfind helpers
This allows avoiding one of the previous implementation limits:
leaked IRP not queued to a thread are now totally visible since
we look directly in the memory pool.
2019-01-06 12:49:57 +01:00
Pierre Schweitzer 12e579567c
[NTOSKRNL] Implement !poolfind command in KDBG
For now, it allows searching for pool allocations in
both paged and non paged pool.

It is based on Andreas Schuster work to identify POOL_HEADER
structures.
2019-01-06 11:56:38 +01:00
Timo Kreuzer cfd1647914
[REACTOS] Fix misc 64 bit issues (#783)
* [WIN32K] Fix handle calculation in DbgGdiHTIntegrityCheck
* [NOTEPAD] Fix MSVC warnings
* [PSDK] Simplify *PROC definitions in windef.h
* [VIDEOPRT] Don't try to use NtVdmControl on x64
* [FREELDR] Fix some macros
* [CRT] Make qsort 64 bit compatible
* [NTOS] Use #ifndef _WIN64 instead of #ifdef _M_IX86 around C_ASSERTs
* [FAST486] Fix 64 bit warnings and change DWORD to ULONG, so it can be used in kernel mode
* [APPHELP_APITEST] Fix 64 bit issue
2019-01-05 10:50:11 +01:00
Pierre Schweitzer d6dc1fd231
[NTOSKRNL] Add a raw implementation of !irpfind in kdbg
This is far from perfect, and totally doesn't match the
WinDBG way of doing it. Instead of browsing pool to find
matching 'IRP' tags, we just browse all the processes
to find the queued IRP. This requires the IRPs to be queued,
obviously, and will make us miss the leaked IRPs, for instance.

Proper way to do it would be to implement !poolfind and then
rely on its implementation to find our IRPs.

Perhaps later ;-)
2019-01-01 22:00:56 +01:00
Hermès Bélusca-Maïto 3fc3447f3e
Happy New Year 2019 everybody! 2019-01-01 00:00:00 +01:00
Pierre Schweitzer 1a93d83f92
[SDK] Add PsGetCurrentThreadTeb() to the DDK 2018-12-31 11:19:35 +01:00
Hermès Bélusca-Maïto bf6b5e1ceb
[NTOS] Fix a NULL-pointer access bug. 2018-12-30 15:26:43 +01:00
Hermès Bélusca-Maïto fefb982d64
[NTOS] Don't use TAG_IO_NAME when calling ExFreePoolWithTag() for freeing FileObject->FileName.Buffer .
This may look strange, since this buffer is originally allocated using
the TAG_IO_NAME tag. However, it happens that file-system drivers are
allowed to re-allocate this buffer: this is what the MS' open-sourced
CDFS driver does, see e.g. CdCommonCreate() and CdNormalizeFileNames()
in cdfs/create.c .

This fixes a pool tag mismatch 'mNoI' != 'nFdC' BSOD when resources
are freed when closing a file that has been opened with a relative name
on a CDFS-mounted volume.
2018-12-30 15:26:42 +01:00
Hermès Bélusca-Maïto d3a97e2228
[NTOS] Code formatting only. 2018-12-30 15:26:35 +01:00
Timo Kreuzer 71fefa32db
[NDK][NTOS] Add global definition of INIT_FUNCTION/INIT_SECTION (#779)
* Add an NDK header to define INIT_FUNCTION/INIT_SECTION globally
* Use _declspec(allocate(x)) and _declspec(code_seg(x)) on MSVC versions that support it
* Use INIT_FUNCTION on functions only and INIT_SECTION on data only (required by MSVC)
* Place INIT_FUNCTION before the return type (required by MSVC)
* Make sure declarations and implementations share the same modifiers (required by MSVC)
* Add a global linker option to suppress warnings about defined but unused INIT section
* Merge INIT section into .text in freeldr
2018-12-30 12:19:11 +01:00
Eric Kohl aecc523b6a [NTOS:IO] Fix indentation. No code changes. 2018-12-29 17:49:38 +01:00
Mark Jansen ec5c0c926b
[NTOS] When checking something for NULL, let's initialize it to NULL... 2018-12-27 23:03:22 +01:00
Eric Kohl 079f7027f6 [NTOS:IO] When a device has been started, create an Enum sub key to its service key and add the device instance name to the Enum sub key. 2018-12-25 23:04:27 +01:00
Pierre Schweitzer e16241255d
[NTOSKRNL] Set the MemoryMaker flag when executing write behind 2018-12-23 14:59:42 +01:00
Pierre Schweitzer 7e97071c8b
[NTOSKRNL] Implement write behind in Cc
For now, this is just a split between scan and flush that
were both done during lazy scan previously.
Lazy scan shouldn't perform any write operation, but only
queue a write behind operation.

Our implementation is far from the original, as it seems
our lazy scan should queue a write behind operation per
shared cache map. Right now, we only perform global
operation.
2018-12-23 14:45:38 +01:00
Pierre Schweitzer 1a267045f8
[NTOSKRNL] Honor files that shouldn't be lazy written 2018-12-23 12:10:58 +01:00
Pierre Schweitzer 0917c64812
[NTOSKRNL] When growing a file, invalid the last VACB so that it can be refreshed
This will avoid corruption when a file size is little grown and read afterwards.
Up to now, FSD where reading 0es instead of expected data, causing corruption.

This fixes MS FastFAT not being able to mount a FAT volume in ReactOS, corrupting
the FAT.
This also fixes the CcSetFileSizes kmtest tests.

This is based on a patch by Thomas Faber.

CORE-11819
2018-12-23 11:19:14 +01:00
Serge Gautherie 4d1f13cf77 [NTOS:CC] CcCanIWrite(): Use BYTES_TO_PAGES(Length) 2018-12-21 19:20:59 +01:00
Pierre Schweitzer 1435ff95b4
[NTOSKRNL] Don't call AcquireForLazyWrite with the master lock held
This incorrect behavior was leading to a call at too high IRQL for paged code.
This was triggered by MS FastFAT.

ReleaseFromLazyWrite call was already correctly called to that regard.

CORE-11819
2018-12-21 08:46:40 +01:00
Hermès Bélusca-Maïto b2bad34b9b
[NTOS] Addendum to 03873aee: check that the computed size of the OEM-converted string is less than MAXUSHORT. 2018-12-21 00:34:56 +01:00
Pierre Schweitzer daf9743c7b
[NTOSKRNL] Check that caller has the priviliege to unload a driver
Also, probe the service name when unloading a driver if called from
user-mode. This will avoid that userland applications can trigger an
invalid read in the kernel (and thus, a BSOD).

CORE-15468
2018-12-20 08:50:51 +01:00
Hermès Bélusca-Maïto bc5acd8102
[NTOS] Minor formatting + don't hardcode sizeof(UCHAR) value. 2018-12-20 03:47:46 +01:00
Hermès Bélusca-Maïto f4597b5540
[NTOS] Addendum to d8cb37bf: return the correct Status from NtAllocateUuids(). 2018-12-20 03:47:45 +01:00
Hermès Bélusca-Maïto 03873aeef3
[NTOS] Fixes for NtDisplayString().
- Require the user to have TCB privilege for using this function.
- Probe and capture the user-provided string (and avoid usermode-triggered BSODS ;-)
- Allocate the OEM-converted string in *NonPagedPool* because we are
  going to transmit the buffer to BOOTVID.
2018-12-20 03:47:36 +01:00
Pierre Schweitzer 4f8b041bf0
[NTOSKRNL] Drop the ViewLock mutex in favour of the master spin lock
This will allow Cc calls during DPC, which is required by MS FastFAT

CORE-11819
2018-12-19 22:51:45 +01:00
Eric Kohl b67dbdbea5 [NTOSKRNL] Fix indentation. No code changes. 2018-12-19 19:18:21 +01:00
Eric Kohl 7e56b21ad6 [NTOSKRNL] Fix indentation. No code changes. 2018-12-19 19:18:20 +01:00
Pierre Schweitzer 549793b8a4
[NTOSKRNL] Fix copy/pasta ;-) 2018-12-19 08:15:11 +01:00
Pierre Schweitzer d8cb37bf15
[NTOSKRNL] Probe parameters in NtAllocateUuids() if called from user-mode
This will avoid that userland applications can trigger an invalid write in
the kernel (and thus, a BSOD).

CORE-15462
2018-12-19 08:09:04 +01:00
Pierre Schweitzer 6ca1c55c6e
[NTOSKRNL] Only allow SYSTEM to call NtSetUuidSeed()
Also, validate input buffer before attempting any operation on it.
This will avoid userland applications to be able to trigger an invalid
read in the kernel (and thus a BSOD).

Regarding access restriction, see:
https://stackoverflow.com/questions/1254244/need-access-to-ntsetuuidseed-from-a-non-localsystem-process

CORE-15460
2018-12-18 23:12:41 +01:00
Eric Kohl 167bffd80f [NTOSKRNL] Add and call the CmpSaveBootControlSet() stub. 2018-12-16 12:49:59 +01:00
Eric Kohl e8d16d0a7d [NTOSKRNL] Fix indentation. No code changes. 2018-12-16 10:30:23 +01:00
Andrew Boyarshin 3ba51dc218 [NTOS:MM] Fix typo in MiCheckForUserStackOverflow 2018-12-12 12:57:08 +01:00
Eric Kohl 12fdc129cf [NTOSKRNL] IopGetDeviceProperty: Send an IRP_MN_QUERY_CAPABILITIES request to the device in order to query the power capabilities. 2018-12-10 00:37:04 +01:00
Pierre Schweitzer 962b2fd66a
[NTOSKRNL] Implement SystemDpcBehaviourInformation query 2018-12-09 20:54:40 +01:00
Pierre Schweitzer 13d9d3ebbf
[NTOSKRNL] Also account PRCBs for Io operations counters 2018-12-09 19:30:07 +01:00
Pierre Schweitzer e632375851
[NTOSKRNL] For SystemPerformanceInformation, return some info extracted from PRCB
This notably includes the amount of context switchs and system calls.
2018-12-09 18:56:50 +01:00
Pierre Schweitzer 4d974e56ee
[NTOSKRNL] Return the amount of hits in system lookaside lists in ExQueryPoolUsage() 2018-12-09 18:25:11 +01:00
Timo Kreuzer 431643b9b3 [NTOS:LPC] Add a number of DPRINTs on failure 2018-12-09 03:16:19 +01:00
Pierre Schweitzer 182cc5c5ab
[NTOSKRNL] Don't dereference VACB when allocating its memory area fails
This avoids performing a double-free (even though that's hidden by the
fact we use lookaside allocations for VACB), and it avoids freeing
a memory address at an uninitialized address.
We don't care about references here, the VACB was just allocated, never
linked and we're its only user.

CORE-15413
2018-12-08 19:56:03 +01:00
Pierre Schweitzer 67e7399164
[NTOSKRNL] Use proper enum type for IopCreateSecurityDescriptorPerType() 2018-12-04 19:20:47 +01:00
Pierre Schweitzer 73e7a5d474
[NTOSKRNL] Use the appropriated security descriptor when creating a device
CORE-9176
2018-12-04 19:13:57 +01:00
Pierre Schweitzer 36c38c45ee
[NTOSKRNL] Implement IopCreateDefaultDeviceSecurityDescriptor() and IopCreateSecurityDescriptorPerType()
CORE-9176
2018-12-04 19:13:57 +01:00
Andrew Boyarshin 198601a101 [NTOS:IO] Tiny improvement to debug message
Add quotes around string, since it is often empty, thus confusing in log.
2018-11-25 11:31:12 +01:00
Bernhard Feichtinger 8a0495063b [NTOS:MM] Handle unimplemeted case for MiCheckForUserStackOverflow 2018-11-25 11:29:18 +01:00
Hermès Bélusca-Maïto f87d9caf77 [NTOS:IO] Finally remove the dreadful IopParseDevice() hack! \o/ 2018-11-25 09:00:40 +01:00
Pierre Schweitzer 4f1e9252f1
[NTOSKRNL] ExfReleaseRundownProtectionCacheAware*() functions don't return anything 2018-11-17 17:36:18 +01:00
Pierre Schweitzer 7ed17cd714
[NTOSKRNL] Implement ExfReInitializeRundownProtectionCacheAware()
We're done with cache-aware rundown protections!
2018-11-17 16:44:37 +01:00
Pierre Schweitzer 05cca64448
[NTOSKRNL] Implement ExfRundownCompletedCacheAware() 2018-11-17 16:44:37 +01:00
Pierre Schweitzer fed61c6305
[NTOSKRNL] Replace ExGetRunRefForCurrentProcessor() by a more generic function 2018-11-17 16:44:36 +01:00
Pierre Schweitzer 7e849470af
[NTOSKRNL] Implement ExfWaitForRundownProtectionReleaseCacheAware() 2018-11-17 16:44:36 +01:00
Pierre Schweitzer acdf74aa3b
[NTOSKRNL] Properly align runrefs on SMP in ExInitializeRundownProtectionCacheAware() 2018-11-17 16:44:36 +01:00
Pierre Schweitzer c5db202bdc
[NTOSKRNL] Properly align allocation on SMP in ExAllocateCacheAwareRundownProtection() 2018-11-17 16:44:36 +01:00
Pierre Schweitzer 36fadc2dca
[NTOSKRNL] Implement ExfAcquireRundownProtectionCacheAwareEx(), ExfReleaseRundownProtectionCacheAwareEx() 2018-11-17 16:44:35 +01:00
Pierre Schweitzer afb2214154
[NTOSKRNL] Simplify implementation of ExfAcquireRundownProtectionCacheAware(), ExfReleaseRundownProtectionCacheAware() 2018-11-17 16:44:35 +01:00
Pierre Schweitzer 010b9b5469
[NTOSKRNL] Implement ExGetRunRefForCurrentProcessor() to get runref for a proc 2018-11-17 16:44:35 +01:00
Pierre Schweitzer 7e36e76d5d
[NTOSKRNL] Implement ExfAcquireRundownProtectionCacheAware(), ExfReleaseRundownProtectionCacheAware() 2018-11-17 16:44:35 +01:00
Pierre Schweitzer 47d309b262
[NTOSKRNL] Implement ExSizeOfRundownProtectionCacheAware() 2018-11-17 16:44:35 +01:00
Pierre Schweitzer ce94d37dbe
[NTOSKRNL] Implement ExInitializeRundownProtectionCacheAware() 2018-11-17 16:44:35 +01:00
Pierre Schweitzer bc77f83888
[NTOSKRNL] Implement ExAllocateCacheAwareRundownProtection() and ExFreeCacheAwareRundownProtection() 2018-11-17 16:44:34 +01:00
Pierre Schweitzer a0c33934fc
[NTOSKRNL] Properly check for negative values in IoCheckEaBufferValidity()
CID 1441355, 1441382
2018-11-16 22:07:08 +01:00
Pierre Schweitzer 95bc44e214
[NTOSKRNL] Don't leak DACL
Spotted by Thomas :-)
2018-11-11 23:21:36 +01:00
Hermès Bélusca-Maïto cbaa8e7dfb
[NTOS:IO] RAW-FS: Few improvements.
- Simplify the volume-deletion code in RawCheckForDismount().

- Fixes the OpenCount check in RawClose(): the VCB mutex must be
  released when the volume has not been dismounted, either because
  OpenCount != 0 or because RawCheckForDismount() returned FALSE.

- Explicitly use VCB_STATE_LOCKED instead of hardcoding its value.

- In IRP_MN_VERIFY_VOLUME handling, lock the volume before playing
  with it, and again let the volume be dismounted only if OpenCount == 0
  (and the IoDeleteDevice() call is done by RawCheckForDismount()).
2018-11-11 21:56:18 +01:00
Hermès Bélusca-Maïto a5ead049d9
[NTOS:IO] RAW-FS: Minor code formatting only. 2018-11-11 21:56:17 +01:00
Pierre Schweitzer 6747dacf10
[NTOSKRNL] Create a security descriptor for the \security directory object 2018-11-10 23:25:10 +01:00
Pierre Schweitzer 102ba75f15
[NTOSKRNL] Return security descriptor size when querying object basic info 2018-11-10 10:54:10 +01:00
Pierre Schweitzer 1fb32afefa
[NTOSKRNL] Return quota information when querying object basic info 2018-11-10 10:54:06 +01:00
Jérôme Gardou df25e4e791 [NTOS/MM] Properly handle page faults in regions marked with
PAGE_NOACCESS or PAGE_GUARD

ROSTESTS-110
2018-11-03 12:50:16 +01:00
Jérôme Gardou 47ac7a2b28 [NTOS/MM] Move up MmAlterViewAttributes for later use in MmNotPresentFaultSectionView
No code change
2018-11-03 12:50:16 +01:00
Pierre Schweitzer cf7969fbfa
[NTOSKRNL] Fix refcounting for BCBs
Now, we make sure that we update ref count and BCB list membership
with the BCB lock held, in a row.
This will avoid race conditions where the BCB was removed from the
list, then referenced again, leading to inconsistencies in memory
and crashes later on.
This could notably be triggered while building ReactOS on ReactOS
(one would call this a regression).

CORE-15235
2018-10-28 20:48:01 +01:00
Pierre Schweitzer 03294dd097
[NTOSKRNL] Rewrite IoCheckEaBufferValidity() so that it's less magic
And make its coding style consistent with our rules
2018-10-27 22:16:37 +02:00
Pierre Schweitzer 07e6af6aa1
[NTOSKRNL] Properly handle "big" security descriptors in ObpCaptureObjectCreateInformation() 2018-10-27 19:36:15 +02:00
Pierre Schweitzer 2ce071d19a
[NTOSKRNL] Implement SeComputeQuotaInformationSize() 2018-10-27 19:36:14 +02:00
Pierre Schweitzer 9c6037182c
[NTOSKRNL] Add support for unsecure object names 2018-10-27 12:01:38 +02:00
Pierre Schweitzer 0f36353551
[NTOSKRNL] Implement the ObpIsUnsecureName() helper function 2018-10-27 12:01:38 +02:00
Pierre Schweitzer b9423f07d9
[NTOSKRNL] Add support for the ObUnsecureGlobalNames registry key 2018-10-27 12:01:38 +02:00
Pierre Schweitzer 8e51bb6510
[NTOSKRNL] Reduce noise 2018-10-27 10:04:22 +02:00
Pierre Schweitzer 18f3922725
[NTOSKRNL] Call internal helper to get VACB on mapping
We already properly round our offset
2018-10-27 09:38:55 +02:00
Hermès Bélusca-Maïto 83d5c711b3
[NTOS] Drastically reduce the hackish function CmpGetRegistryPath() for the text-mode setup case (it should ultimately completely disappear).
svn path=/branches/setup_improvements/; revision=75163
2018-10-25 00:40:03 +02:00
Hermès Bélusca-Maïto cb69c4c691
[NTOS] Add some DPRINTs in IopLoadServiceModule() and IopOpenRegistryKeyEx() to investigate why these 1st-stage text-mode hacks may be, or are (respectively) still needed.
svn path=/branches/setup_improvements/; revision=74748
2018-10-25 00:40:03 +02:00
Hermès Bélusca-Maïto 2ed65d1555
[NTOS] Configuration Manager fixes.
- Rework CmpSetSystemValues() and remove its 1st-stage text-mode setup hack, since a real registry hive will be used for 1st-stage either.
- Lock, then unlock the registry in NtInitializeRegistry when initializing the hives & flusher.
- Call CmpInitializeHiveList() (i.e., initialize the other hives like \Software, \User, \.Default) only when we are not in setup-mode.

svn path=/branches/setup_improvements/; revision=74747
2018-10-25 00:40:02 +02:00
Hermès Bélusca-Maïto e2cb7b50b4
[NTOS] Remove some hacks that are not needed anymore, since a real registry hive will be used in 1st-stage as well.
This reverts a7c26408 (r53255) and ff75ae1b (r53694), and a hack from 6075ae9a (r46690).

svn path=/branches/setup_improvements/; revision=74745
svn path=/branches/setup_improvements/; revision=74746
2018-10-25 00:40:00 +02:00
Pierre Schweitzer f3b9beeb39
[NTOSKRNL] Translate pinning flags to mapping flags when first mapping a file 2018-10-23 22:07:53 +02:00
Hermès Bélusca-Maïto 0e6bc236a1
[NTOS:CM] CmpCmdHiveOpen(): Resolve FileAttributes->RootDirectory when a hive file name is provided relative to it.
Fixes registry hive loading. CORE-13448
2018-10-22 00:39:50 +02:00
Hermès Bélusca-Maïto d61c00c252
[NTOS:CM] Implement more support for force-unloading registry hives.
CORE-13448 CORE-10705
2018-10-22 00:05:13 +02:00
Hermès Bélusca-Maïto 16752875db
[NTOS:CM] Add extra validation for the information class parameter in NtEnumerateValueKey(). 2018-10-21 18:12:08 +02:00
Hermès Bélusca-Maïto 49e08b23ce
[NTOS:CM] Improve the capture of user-mode parameters.
- Improve the capture of OBJECT_ATTRIBUTES parameters that are passed
  (by pointer) to the Cm* helper functions, and the capture of
  UNICODE_STRINGs.

- Correctly differentiate user-mode vs. kernel-mode root directory handles
  (in OBJECT_ATTRIBUTES): note that most of the Cm* APIs expect their
  parameters to be kernel-mode (pointers, handles...).

CORE-13448
2018-10-21 17:11:50 +02:00
Hermès Bélusca-Maïto 29b2fdcc4d
[NTOS:CM] Minor fixes.
- Validate the information class parameter in NtQueryValueKey().
- Call the post-callback in NtSetValueKey() only if the callback
  has been registered and the CmSetValueKey() call is executed.
2018-10-20 19:52:34 +02:00
Hermès Bélusca-Maïto 5322969186
[NTOS:CM] Reuse the saved previous-mode from the ExGetPreviousMode() calls. 2018-10-20 19:52:32 +02:00
Hermès Bélusca-Maïto 4caf391324
[NTOS][MKHIVE] Minor code formatting. 2018-10-14 15:59:34 +02:00
Pierre Schweitzer 3d13a464f7
[NTOSKRNL] Add the CcPinMappedDataCount counter 2018-10-13 22:51:44 +02:00
Pierre Schweitzer 1afcbbd125
[NTOSKRNL] Rewrite the way we create BCB for pinning
We won't reuse a BCB created for mapping, we will now have
our own dedicated BCB.
This allows having a bit more cleaner implementation of CcPinMappedData()
2018-10-13 22:51:44 +02:00
Serge Gautherie a06b425839 [NTOS:KD] A few trivial code improvements 2018-10-12 08:43:02 +02:00
Serge Gautherie 561a10056b [NTOS:KD] Remove an unreachable "break;"
On behalf of Kudratov Olimjon.
CORE-8545
2018-10-12 08:43:02 +02:00
Pierre Schweitzer 1acb5a9fab
[NTOSKRNL] Don't keep the spin lock hold too long when we lost the BCB race
This will avoid a deadlock on unpin.
2018-10-12 08:20:32 +02:00
Pierre Schweitzer cf8ba3bd9c
[NTOSKRNL] Rewrite BCB handling to be more robust
We now handle race conditions when creating BCB to avoid
having duplicated BCB per shared maps.
Also, we already specify whether the memory will be pinned
when creating the BCB, to avoid potential duplications or
BCB misuse.
2018-10-11 23:15:01 +02:00
Pierre Schweitzer bd39459f89
[NTOSKRNL] Implement support for PIN_IF_BCB flag 2018-10-05 21:26:16 +02:00
Pierre Schweitzer 7fd2751c87
[NTOSKRNL] When pinning data, try to find an already pinned BCB
If found, attempt to lock it and return it.

This fixes a lot of CcPinRead tests (and seems to speed up a bit ReactOS)
2018-10-05 21:26:16 +02:00
Pierre Schweitzer 9fc75c1132
[NTOSKRNL] When mapping data, try to find if there's already a BCB
If so, return such BCB instead of creating a new one. This will
allow (at some point) to be more consistent in case of concurrent
mapping.

This fixes a few CcMapData tests.
2018-10-05 21:26:16 +02:00
Pierre Schweitzer f284947622
[NTOSKRNL] Move the PinCount out of the VACB to the BCB
Given current ReactOS implementation, a VACB can be pinned
several times, with different BCB. In next commits, a single
BCB will be able to be pinned several times. That would
lead to severe inconsistencies in counting and thus corruption.
2018-10-05 21:26:16 +02:00
Pierre Schweitzer 0b713d4fa0
[NTOSKRNL] On open, verify and validate the hint device object if any 2018-10-05 10:49:59 +02:00
Pierre Schweitzer 779d87b483
[NTOSKRNL] Implement IopCheckTopDeviceHint() 2018-10-05 10:49:59 +02:00
Pierre Schweitzer 670a7ac718
[NTOSKRNL] In IoGetRelatedDeviceObject(), validate hint is on the stack before returning it 2018-10-05 10:49:59 +02:00
Pierre Schweitzer 161b6728ef
[NTOSKRNL] Implement IopVerifyDeviceObjectOnStack() 2018-10-05 10:49:59 +02:00
Pierre Schweitzer 2a182931b6
[NTOSKRNL] A bit of cleanup in Io*FilterContext() 2018-10-04 22:24:52 +02:00
Pierre Schweitzer 5f0d02eb52
[NTOSKRNL] Implement IoChangeFileObjectFilterContext() 2018-10-04 19:30:39 +02:00
Pierre Schweitzer a43fb5e054
[NTOSKRNL] Implement IoGetFileObjectFilterContext() 2018-10-04 19:30:38 +02:00
Pierre Schweitzer e19e907a2c
[NTOSKRNL] Quickly check for alignment in NtRead/WriteFile
This quick check based on bits and operation is for 2^ based
sector sizes (most of the cases) and will perform faster than
the modulo operation which is still used in fallback in case
the sector size wouldn't be a power of 2.
2018-10-04 10:45:10 +02:00
Pierre Schweitzer 44155053cd
[NTOSKRNL] Use captured variable to check parameters in NtRead/WriteFile 2018-10-04 10:45:10 +02:00
Pierre Schweitzer bf59669065
[NTOSKRNL] On read/write, also check buffer respects device alignment requirements 2018-10-04 07:56:23 +02:00
Pierre Schweitzer 1bd25c5c24
[NTOSKRNL] When checking for byte offset alignment, tolerate some magic values 2018-10-04 07:53:12 +02:00
Eric Kohl fd33402104 [NTOSKRNL] NtReadFile/NtWriteFile: If a file has been opened for non-cached access, Length and ByteOffset must be sector size aligned.
This fixed two ntdll apitests.
2018-10-04 01:17:58 +02:00
Pierre Schweitzer d8f22735ed
[NTOSKRNL] In IopQueryNameInternal(), enclose output copy in a SEH statement 2018-10-03 22:55:23 +02:00
Pierre Schweitzer 15b9a6aa4c
[NTOSKRNL] Call IoCreateFileSpecifyDeviceObjectHint with the hint if it was specified 2018-10-03 21:29:12 +02:00
Pierre Schweitzer 520f404e9c
[NTOSKRNL] In IoQueryFileDosDeviceName(), in case of an error, return appropriate status 2018-10-03 17:08:42 +02:00
Pierre Schweitzer 8c6c5a92e8
[NTOSKRNL] Implement DOS name query in IopQueryNameInternal() 2018-10-03 13:56:18 +02:00
Pierre Schweitzer 769157f6ff
[NTOSKRNL] Allow FileNameInformation not to be implemented in storage stack 2018-10-03 13:52:05 +02:00
Pierre Schweitzer 46bda8a4c6
[NTOSKRNL] In IopQueryNameInternal() don't copy name if it's not valid 2018-10-03 13:50:16 +02:00
Pierre Schweitzer 4a7e89770e
[NTOSKRNL] Implement IoQueryFileDosDeviceName() 2018-10-03 11:56:21 +02:00
Pierre Schweitzer abfddca8bb
[NTOSKRNL] Stub support for querying DOS name when parsing FO name 2018-10-03 11:45:08 +02:00
Pierre Schweitzer a1401a7577
[NTOSKRNL] Use faster internal helper to query name
This only applies if we're called from kernel mode
with a synchronous file.
2018-10-03 10:22:33 +02:00
Pierre Schweitzer 1348f62f20
[NTOSKRNL] Rename IopQueryNameFile to IopQueryNameInternal 2018-10-03 10:22:33 +02:00
Thomas Faber 8fbc488050
[NTOS:IO] Implement IopAcquireFileObjectLock and use it to fix IopLockFileObject 2018-10-02 09:56:55 +02:00
Pierre Schweitzer fd8893e58f
[NTOSKRNL] Respect PFN cache attribute when required
This fixes noisy DPRINT1 being printed while reading
or writing files with NFS.
2018-10-01 20:59:37 +02:00
Pierre Schweitzer 890a293683
[NTOSKRNL] Fix remaining access computation on open 2018-09-30 10:55:44 +02:00
Pierre Schweitzer 6d0c07c44f
[NTOSKRNL] Implement access check for secure open 2018-09-30 10:55:43 +02:00
Pierre Schweitzer cf25432eed
[NTOSKRNL] Don't lock file object on close if we're not called by Ob
IopCloseFile can be called by IopDeleteFile. In that situation, it
doesn't set any process as first parameter. Furthermore, we are in a
situation where it's not required to lock the file object (see the
assert before the call).
2018-09-29 16:25:58 +02:00
Pierre Schweitzer 207ff9444e
[NTOSKRNL] Reference the file object before issuing the unlock all IRP
This fixes the last kmode assert triggered by httpd on ReactOS.

CORE-12045
2018-09-29 11:22:22 +02:00
Pierre Schweitzer 5472c1db82
[NTOSKRNL] Unlock file if required on last process handle close 2018-09-28 23:34:28 +02:00
Hermès Bélusca-Maïto 89c5191d3f
[NTOS:PS] In PspSetPrimaryToken(), check also for sibling token to determine whether it is required to have the SeAssignPrimaryTokenPrivilege.
In addition, it is the presence or absence of the 'Token' pointer that indicates whether or not we should use instead the provided token handle.
2018-09-28 00:45:03 +02:00
Hermès Bélusca-Maïto 7f9282927b
[NTOS:SE] Fixes for NT tokens.
- SeIsTokenChild(): Correctly check whether a caller-provided token
  is a child from the current process' primary token by looking at
  its ParentTokenId member.

- Add a SeIsTokenSibling() helper to determine whether a caller-provided
  token and the current process' primary token are siblings, by comparing
  their ParentTokenId's and AuthenticationId's.

NOTE: Children tokens are created through CreateRestrictedToken();
sibling tokens are created through DuplicateToken() (amongst others).

See slide 49 of https://www.slideshare.net/Shakacon/social-engineering-the-windows-kernel-by-james-forshaw
or https://googleprojectzero.blogspot.com/2016/01/raising-dead.html
for some details.
2018-09-28 00:45:01 +02:00
Pierre Schweitzer 2a80ae2bb6
[NTOSKRNL] Properly align VACB writes
Also simplify VACB reads alignment code.
Also add some sanity ASSERTs.
2018-09-23 10:32:14 +02:00
Eric Kohl e32a2cc026 [NTOSKRNL] IoGetDeviceProperty: Add support for the DevicePropertyRemovalPolicy property.
This could probably fix CORE-15068.
2018-09-22 11:22:22 +02:00
Eric Kohl e1b82b5b91 [NTOSKRNL] Create the 'Device Parameters' subkey and add the 'FirmwareIdentified' value for all ACPI-enumerated devices. 2018-09-21 15:37:34 +02:00
Eric Kohl 2550325577 [NTOSKRNL] Fix the indentation of some pnp manager functions. 2018-09-21 15:08:43 +02:00
Pierre Schweitzer 15a3ca08b0
[NTOSKRNL] Avoid integer overflow when computing VACB read/write size
This could be triggered when attempting to read/write to really big
files. It was causing an attempt to read 0 bytes in Cc, leading to
asserts failure in the kernel (and corrupted file).

CORE-15067
2018-09-21 08:37:20 +02:00
Pierre Schweitzer 108991a6fb
[NTOSKRNL] Stub IoInitializeCrashDump()
Also call it from NtCreatePagingFile() when we have successfully created
a paging file on the system boot partition.
2018-09-18 21:59:59 +02:00
Pierre Schweitzer 02da7b452c
[NTOSKRNL] Move data mapping implementation to an internel helper 2018-09-09 14:02:13 +02:00
Pierre Schweitzer 3dabca398f
[NTOSKRNL] Don't raise a status when parameters are invalid on file mapping 2018-09-05 22:06:29 +02:00
Pierre Schweitzer e17f61138c
[NTOSKRNL] When allocating a new BCB, save it in a list
This list is stored in the shared map. Later, this will allow
reusing BCB when appropriate
2018-09-05 22:06:25 +02:00
Pierre Schweitzer f96f1224a7
[NTOSKRNL] Fail on pinning when there's no pin access set
Instead of assert, now, CcPinRead will just fail. This is
not consistent without Windows behavior, but still better
than asserting while testing!
2018-09-01 12:41:01 +02:00
Pierre Schweitzer f0eb39084e
[NTOSKRNL] Fix a typo 2018-08-31 19:48:32 +02:00
Pierre Schweitzer e806d16b06
[NTOSKRNL] Warn about unimplemented feature in CcMapData() (in all callers)
Currently, our CcMapData() behavior (same goes for CcPinRead()) is broken
and is the total opposite of what Windows kernel does. By default, the later
will let you map a view in memory without even attempting to bring its
data in memory. On first access, there will be a fault and memory will
be read from the hardware and brought to memory. If you want to force read
on mapping/pinning, you have to set the MAP_NO_READ (or PIN_NO_READ) flag
where kernel will fault on your behalf (hence the need for MAP_WAIT/PIN_WAIT).

On ReactOS, by default, on mapping (and thus pinning), we will force a view
read so that data is in memory. The way our cache memory is managed at the
moment seems not to allow to fault on invalid access and if we don't force
read, the memory content will just be zeroed.
So trying to match Windows behavior, by default, now CcMapData() will enforce
the MAP_NO_READ flag and warn once about this behavior change.
2018-08-31 19:48:32 +02:00
Pierre Schweitzer b8e4af606a
[NTOSKRNL] Properly reset pinning state on pinning failure 2018-08-26 22:56:25 +02:00
Pierre Schweitzer 54f89baad4
[NTOSKRNL] When acquiring BCB shared, starve exclusive waiters 2018-08-26 22:47:48 +02:00
Pierre Schweitzer c1dd4c142f
[NTOSKRNL] Handle the PIN_WAIT flag in CcPinMappedData() 2018-08-26 22:05:11 +02:00
Pierre Schweitzer 469e15c7ae
[NTOSKRNL] Stubplement CcPinMappedData() and simplify CcPinRead()
It's based on the code that was in CcPinRead() implementation. This
made no sense to have CcPinMappedData() doing nothing while implementing
everything in CcPinRead(). Indeed, drivers (starting with MS drivers)
can map data first and pin it afterwards with CcPinMappedData(). It was
leading to incorrect behavior with our previous noop implementation.
2018-08-26 22:05:11 +02:00
Denis Malikov 0cf5efc14c [NTOS:KE] Fix stub for KeAcquireInStackQueuedSpinLockForDpc (#814)
Error was found when building as 0x600+.
CORE-12596
2018-08-26 15:19:26 +02:00
Eric Kohl 06e7233134 [NTOSKRNL] IopGetDeviceProperty: Initialize power data struct and convert flags from device capabilities to power data 2018-08-25 19:49:29 +02:00
Pierre Schweitzer 5c10b02957
[NTOSKRNL] Add the OLE flag where appropriate in FsRtlLegalAnsiCharacterArray
This brings in the ability to check NTFS streams names (OLE | NTFS).
This fixes failing tests from previous commit.
2018-08-25 14:26:49 +02:00
Timo Kreuzer f43a7b81a7
[NTOS:Mm] Fix a 64 bit issue in MmMapViewOfArm3Section (#778)
Fixes a Clang-Cl warning
CORE-14306
2018-08-21 11:25:22 +02:00
Timo Kreuzer d5181e44dd
[NTOS] Fix MiFindInitializationCode (#751)
Short: The code was suffering from an off-by-one bug (inconsistency between inclusive end exclusive end address), which could lead to freeing one page above the initialization code. This led to freeing part of the kernel import section on x64. Now it is consistently using the aligned/exclusive end address.

Long:
* Initialization sections are freed both for the boot loaded images as well as for drivers that are loaded later. Obviously the second mechanism needs to be able to run at any time, so it is not initialization code itself. For some reason someone decided though, it would be a smart idea to implement the code twice, once for the boot loaded images, once for drivers and concluding that the former was initialization code itself and had to be freed.
* Since freeing the code that frees the initialization sections, while it is doing that is not possible, it uses a "smart trick", initially skipping that range, returning its start and end to the caller and have the caller free it afterwards.
* The code was using the end address in an inconsistent way, partly aligning it to the start of the following section, sometimes pointing to the last byte that should be freed. The function that freed each chunk was assuming the latter (i.e. that the end was included in the range) and thus freed the page that contained the end address. The end address for the range that was returned to the caller was aligned to the start of the next section, and the caller used it to free the range including the following page. On x64 this was the start of the import section of ntoskrnl. How that worked on x86 I don't even want to know.
2018-08-21 10:35:57 +02:00
Timo Kreuzer e97b95cc2e [NTOS:MM] Fix ASSERT when expanding paged pool
The page directory is double mapped on x86 in the system process, so writing to it will already write to the PDE.
2018-08-20 23:52:42 +02:00
Timo Kreuzer c219be9409 [NTOS:MM] Fix paged pool expansion 2018-08-20 18:07:35 +02:00
Stanislav Motylkov d033fe9bbf [NTOS:EX] Implement SystemFirmwareTableInformation class 2018-08-19 20:27:59 +02:00
Timo Kreuzer 094a90ad4e [NTOS:PS] Fix an issue with PROCESS_DEVICEMAP_INFORMATION size on 64 bit builds
The PROCESS_DEVICEMAP_INFORMATION  union has 2 fields, one is a handle, the other one is a structure of 36 bytes (independent of architecture). The handle forces 64 bit alignment on 64 bit builds, making the structure 4 bytes bigger than on 32 bit builds. The site is checked in NtQueryInformationProcess (case ProcessDeviceMap). The expected size on x64 is the size of the Query structure without alignment. autocheck correctly passes the site of the Query union member, while smss passes the full size of PROCESS_DEVICEMAP_INFORMATION. Packing the structure is not an option, since it is defined in public headers without packing. Using the original headers sizeof(PROCESS_DEVICEMAP_INFORMATION) is 0x28, sizeof(PROCESS_DEVICEMAP_INFORMATION::Query) is 0x24.
2018-08-17 22:08:37 +02:00
Timo Kreuzer 2c909db295 [NTOS:OB] Rename object types to their official names to satisfy WinDbg
- Rename ObDirectoryType to ObpDirectoryObjectType and remove it from NDK (this is not exported!)
- Rename ObSymbolicLinkType to ObpSymbolicLinkObjectType
- Remove duplicated ObpTypeObjectType from ob.h
2018-08-17 20:28:45 +02:00
Pierre Schweitzer 65f9783808
[NTOSKRNL] Properly initialize the IO_STATUS_BLOCK 2018-08-17 19:13:13 +02:00
Pierre Schweitzer 12e8d7fe0e
[NTOSKRNL] Only allow page file on a few specific device types 2018-08-16 19:00:22 +02:00
Pierre Schweitzer cc59c97308
[NTOSKRNL] Don't need all access for file object 2018-08-16 18:54:23 +02:00
Pierre Schweitzer 8281f4baa6
[NTOSKRNL] Add a check commented out for now.
It's to be enabled once page file handling is moved to ARM3
2018-08-16 18:49:55 +02:00
Pierre Schweitzer 7f0ad923d2
[NTOSKRNL] MmTotalCommitLimit and MmTotalCommitLimitMaximum are in pages, not bytes 2018-08-16 18:40:23 +02:00
Timo Kreuzer dd73d1b6d4 [NTOS:MM] Make SLIST handling for kernel stacks portable
Kernel stacks that re freed, can be placed on an SLIST for quick reuse. The old code was using a member of the PFN of the last stack page as the SLIST_ENTRY. This relies on the following (non-portable) assumptions:
- A stack always has a PTE associated with it.
- This PTE has a PFN associated with it.
- The PFN has an empty field that can be re-used as an SLIST_ENTRY.
- The PFN has another field that points back to the PTE, which then can be used to get the stack base.

Specifically: On x64 the PFN field is not 16 bytes aligned, so it cannot be used as an SLIST_ENTRY. (In a "usermode kernel" the other assumptions are also invalid).

The new code does what Windows does (and which seems absolutely obvious to do): Place the SLIST_ENTRY directly on the stack.
2018-08-16 16:52:02 +02:00
Timo Kreuzer 6c154c0625 [NTOS:SE] Fix SeSetSecurityDescriptorInfoEx to prevent pool corruption on x64 2018-08-16 16:32:49 +02:00
Serge Gautherie 20d4b2cfac [NTOS:MM] Update a DPRINT string (#760)
CORE-12729
2018-08-16 15:10:24 +02:00
Pierre Schweitzer 19318dcc1d
[NTOSKRNL] Start making our MMPAGING_FILE struct look like the real one 2018-08-16 14:04:27 +02:00
Pierre Schweitzer e392bdf962
[NTOSKRNL] Store page file sizes in pages, not in bytes 2018-08-16 13:50:16 +02:00
Pierre Schweitzer 2fe4e71383
[NTOSKRNL] Store page file minimum size and use it to prevent page file shrinking 2018-08-16 13:41:16 +02:00
Pierre Schweitzer bfc6a7957c
[NTOSKRNL] Page files don't have an init size, but a minimum size
NFC
2018-08-16 12:42:34 +02:00
Pierre Schweitzer 315867d4ff
[NTOSKRNL] Drop the MmPagingFile spin lock in favor of a guarded mutex 2018-08-16 12:39:24 +02:00
Pierre Schweitzer 891a6eeeb9
[NTOSKRNL] Drop the alloc map from page file
It was making no sense, and implemented in a broken way
that couldn't have worked if code path was used.
2018-08-16 12:16:39 +02:00
Pierre Schweitzer 5bd938bd24
[NTOSKRNL] Stub page file extension support 2018-08-16 11:58:58 +02:00
Pierre Schweitzer 1ea68d0510
[NTOSKRNL] Don't use anonymus allocations for MM objects 2018-08-13 08:30:17 +02:00
Pierre Schweitzer 34e8f45122
[NTOSKRNL] Keep page file name along the page file and free it on shutdown 2018-08-13 08:30:17 +02:00
Pierre Schweitzer 5aaadf39db
[NTOSKRNL] Dereference page file objects in MM shutdown phase 1
Hack the call the MM shutdown phase  1
2018-08-13 08:30:17 +02:00
Pierre Schweitzer 3814a822f1
[NTOSKRNL] Close page files (and delete them!) on shutdown 2018-08-13 08:30:17 +02:00
Pierre Schweitzer d793f196df
[NTOSKRNL] Stub MM shutdown 2018-08-13 08:30:17 +02:00
Pierre Schweitzer 02b0ca08e4
[NTOSKRNL] Misc fixes:
- Rename page file struct to MMPAGING_FILE
- Increment page files count after current page file was put in the list
2018-08-11 23:34:08 +02:00
Pierre Schweitzer f106c297de
[NTOSKRNL] Rename PagingFileList to MmPagingFile and make insertion simpler 2018-08-11 23:19:58 +02:00
Pierre Schweitzer 47cd447cfa
[NTOSKRNL] Remove useless define 2018-08-11 23:07:53 +02:00
Pierre Schweitzer f080ee1305
[NTOSKRNL] Replace the alloc map by a bitmap 2018-08-11 23:01:12 +02:00
Pierre Schweitzer fb07332450
[NTOSKRNL] Drop unused field 2018-08-11 23:01:11 +02:00
Pierre Schweitzer 814a6fc098
[NTOSKRNL] Revert r4668 (yeah, that was 15y ago)
It's hardly understandable and doesn't really makes sense.
Furthermore, it breaks compatibility with 3rd party FSD that
don't implement such FSCTL.
Obviously, Windows doesn't do this.
2018-08-11 23:01:11 +02:00
Pierre Schweitzer 28b4b419c2
[NTOSKRNL] Restrict rights on the page file 2018-08-11 23:01:11 +02:00
Pierre Schweitzer 36c20dc56b
[NTOSKRNL] Deny page file creation on floppy disk 2018-08-11 23:01:11 +02:00
Pierre Schweitzer 2969c28a27
[NTOSKRNL] Properly open a page file and set appropriate attributes 2018-08-11 23:01:11 +02:00
Pierre Schweitzer 0ad4ef6002
[NTOSKRNL] Check that caller has appropriate right before creating page file 2018-08-11 23:01:05 +02:00
Serge Gautherie 7d6bda16c6
[REACTOS] Improve how some ASSERTMSG() message values are printed: enforce ending "\n".
NB: Not touching calls in "third-party" code: class and classpnp.
2018-08-08 22:03:45 +02:00
Serge Gautherie 9ff9bd81c4 [NTOSKRNL] Round memory size up, "debug log" part
Assumed to better match actual physical RAM size.

CORE-12321
2018-08-07 20:36:04 +02:00