Commit graph

59 commits

Author SHA1 Message Date
George Bișoc 8e7b22a631
[NTOS:OB] Fix the SAL2 annotation of ObQueryTypeInfo
The data has to be written into ObjectTypeInfo based on the return length,
not only what is provided by the input buffer length. Fix suggested by
Hermès.
2023-04-22 17:18:57 +02:00
George Bișoc 00c69bcd15
[NTOS:OB] Properly calculate the return length in ObQueryTypeInfo
On a x86 system aligning the return length pointer to a 4-byte boundary
works best since pointers in general are 4-byte aligned for x86 systems.

However, what happens on a AMD64 system is that we still align this pointer
to 4-byte, ObjectTypeInfo is a 8-byte pointer and we might write into
the return length past the 4-byte boundary.

If one were to allocate a pool of memory with that length and query all
the object types info and free the said pool of memory thereafter, the
system will crash with BAD_POOL_HEADER because ObQueryTypeInfo overwrote
the return length past the 4-byte boundary length therefore leading up with
corrupted memory blocks in the pool header.

This symptom of BAD_POOL_HEADER happens exactly the same in Windows Server
2003 x64 Edition. Newer versions of Windows like 10 aren't affected.

But, Windows has another bug where they are using MaximumLength for the
calculation of the needed length to be returned to caller. MaximumLength
does not guarantee you that it includes the NULL-terminator in the length
and that potentially leads to a buffer overrun.

Also annotate the ObQueryTypeInfo function with SAL2.

https://processhacker.sourceforge.io/doc/object_8c_source.html (read the
comment in KphObjectTypeInformation).
2023-04-21 12:45:31 +02:00
George Bișoc 29fc7bb33e
[NTOS:OB] Implement name information querying on ObjectBasicInformation case
Currently there is no implementation support for object name information
querying when someone queries information about an object with ObjectBasicInformation
class case. Some device drivers may take use of such information.

NameInfoSize is a size that is the sum of all name directories of an object,
including path separators. TypeInfoSize is a size that is pointed by
the size of a type object itself, therefore this size remains pretty much
fixed depending on the kind of an object.

For more information:
https://www.geoffchappell.com/studies/windows/km/ntoskrnl/inc/api/ntobapi/object_basic_information.htm
http://undocumented.ntinternals.net/index.html?page=UserMode%2FUndocumented%20Functions%2FNT%20Objects%2FType%20independed%2FNtQueryObject.html
2023-03-25 11:55:11 +01:00
Timo Kreuzer e7bbbf049e [NTOS] Fix double free on allocation failure in ObCreateObject 2022-12-01 20:17:40 +02:00
Hermès Bélusca-Maïto ab5fdac922
[NTOS] Add TAG_DACL in tag.h and use it. 2022-11-03 02:55:49 +01:00
George Bișoc 5da5e644bb
[NTOS:OB] Include the security descriptor charge when charging the paged pool quota of an object
On ObpChargeQuotaForObject function, the kernel will either charge the default object type charges or the specified information charges obtained from ObCreateObject API call. What happens is that if a paged pool charge is specified on ObCreateObject call the kernel will charge that
but when an object is about to be de-allocated, the amount of quota to return back to the system is the amounting of the paged pool charge specified previously by the ObCreateObject call plus the amounting of the security descriptor charge (see oblife.c / line 98).

This will result in a fatal crash with a bugcheck of QUOTA_UNDERFLOW because we are returning quota with bits of it that was never charged and that's SecurityDescriptorCharge. A QUOTA_UNDERFLOW bugcheck occurs in two following scenarios:

-- When installing Virtualbox Guest Additions and prompting the installer to reboot the system for you
-- When logging off and on back to the system and then you restart the system normally

This bug has been discovered whilst working on #4555 PR.
2022-06-26 19:47:02 +02:00
George Bișoc 9f8fbe14f5
[NTOS:OB] Specify the query security descriptor tag when freeing the allocation
We are allocating blocks of pool memory for a security descriptor with its own specific tag, TAG_SEC_QUERY, so just use it when freeing when releasing the descriptor as well (aka freeing the said pool).
2022-05-08 19:16:34 +02:00
George Bișoc 0c07eac5b4
[NTOS:OB] Charge/Return pool quotas of objects
As it currently stands the Object Manager doesn't charge any quotas when objects are created, nor it returns quotas when objects are de-allocated and freed from the objects namespace database. This alone can bring inconsistencies in the kernel as we simply don't know what is the amount charged in an object and thus we aren't keeping track of quotas flow.

Now with both PsReturnSharedPoolQuota and PsChargeSharedPoolQuota implemented, the Object Manager can now track the said flow of quotas every time an object is created or de-allocated, thus enforcing consistency with the use of quota resources.
2022-01-11 10:11:10 +01:00
George Bișoc 3bc2d590a1
[NTOSKRNL] Regroup the pool allocation tags in one dedicated place
We have a special file, tag.h, which serves as a place to store whatever kernel pool allocation tag yet we still have some tags sparse over the kernel code... So just re-group them in one unique place.
2021-12-27 18:57:03 +01:00
Hermès Bélusca-Maïto 74513a75ab
[NTOS:OB] Minor refactoring.
- NtQuerySymbolicLinkObject(): Use an intermediate variable for the object header.
- Simplify code in ObpLookupEntryDirectory() by calling ObpReleaseLookupContextObject() instead.
- Use TAG_OBJECT_TYPE instead of hardcoded tag values.
2021-09-25 01:09:01 +02:00
Hermès Bélusca-Maïto 4c63ed5a7a
[NTOS:OB] Clarify and fix the usage of the Obp*DirectoryLock*() and ObpReleaseLookupContextObject() functions.
- Disentangle the usage of ObpAcquireDirectoryLockExclusive() when it's
  used only for accessing a directory structure, or as part of a lookup
  operation.

  The Obp*DirectoryLock*() -- both shared and exclusive -- functions
  are only for locking an OB directory, for reading or writing its
  structure members.

  When performing lookup operations (insertions/deletions of entries
  within a directory), use a ObpAcquireLookupContextLock() function that
  exclusively locks the directory and saves extra lock state, that can
  be used by ObpReleaseLookupContextObject() for cleanup.

- Add documentation for these functions.
2021-09-25 00:47:43 +02:00
George Bișoc 19cdb521d2
[NTOS:OB] Acquire the lock before setting directory's session ID 2021-09-24 19:49:40 +02:00
Jérôme Gardou 3ad38f29b5 [NTOS:OB] Use RtlInitUnicodeString for constant string
CORE-17637
2021-06-28 10:20:57 +02:00
Victor Perevertkin 34593d933b
[FORMATTING][NTOS][HAL][DRIVERS][SDK] Fix trailing spaces 2021-06-11 15:33:08 +03:00
Serge Gautherie 5d89643311 [NTOS:OB] ObQueryDeviceMapInformation(): Fix annotations 2021-05-01 11:26:07 +02:00
George Bișoc f9c603db6e
[NTOS:OB] Do not close the handle if it's granted access to ObpAccessProtectCloseBit
As of now the Object Manager private service, ObpCloseHandleTableEntry, looks for OBJ_PROTECT_CLOSE attribute if a handle should not be closed. However, in ObDuplicateObject if an attribute of OBJ_PROTECT_CLOSE is found as it's been filled to the caller (see L2466) this attribute is removed from the attributes list of the new handle and ObpAccessProtectCloseBit access is granted to the newly duplicated object handle.

With that being said ObpCloseHandleTableEntry indiscriminately closes the object handle albeit it shouldn't do so. As a matter of fact in Windows Server 2003 SP2 this service indeed checks for ObpAccessProtectCloseBit flag bit and if the condition is met then it returns STATUS_HANDLE_NOT_CLOSABLE as it should. Therefore we should do the same.

Now NtClose can properly warn the calling thread the object handle can't be closed which fixes a testcase failure within NtDuplicateObject NTDLL APITEST where this function gives handle close protection bit as requested by the caller.
2021-04-26 19:36:38 +02:00
Victor Perevertkin 5c7ce4475e
[REACTOS] Cleanup INIT and some PAGE section allocations
- Change INIT_FUNCTION and INIT_SECTION to CODE_SEG("INIT") and DATA_SEG("INIT") respectively
- Remove INIT_FUNCTION from function prototypes
- Remove alloc_text pragma calls as they are not needed anymore
2020-11-02 21:45:31 +03:00
Serge Gautherie cf510c3e64
[NTOSKRNL] Sync some INIT_FUNCTION (#2824)
- Sync some INIT_FUNCTION with how they are used and what is already
  specified in the headers.
Addendum to commit 85e5b5be (r49445).

- KdbpGetCommandLineSettings(): Remove INIT_FUNCTION.
Fix MSVC 2015 x86 custom build:
"...\ntoskrnl\kdbg\kdb.c(1699): error C2983: 'KdbpGetCommandLineSettings': all declarations must have an identical __declspec(code_seg(...))"

And may also fix obscure bugs when entering into the KDBG debugger.
2020-05-23 16:05:58 +02:00
Serge Gautherie b20f815126
[NTOSKRNL] Place INIT_FUNCTION before the return type (#2823)
(but after 'static' or SAL 2 annotation.)
Follow-up to 71fefa32, which mentions that it's actually required by the compiler in some circumstances.
2020-05-23 15:56:10 +02:00
Thomas Faber 8c8c03e9a8
[NTOS:OB] Fix incorrect variable name in ObfDereferenceObject. 2020-05-17 21:43:58 +02:00
Pierre Schweitzer e12abf63c5
[NTOSKRNL] Handle symlink parsing when it's bound to a specific object 2019-08-19 10:45:50 +02:00
Pierre Schweitzer 4fd223729b [NTOSKRNL] When looping again in ObpLookupEntryDirectory, properly init root entry
This fixes looking in global directory for DOS drives that are globally mounted
(such as C: drive)

CORE-16114
2019-06-30 23:07:54 +02:00
Pierre Schweitzer f13b6e025f [NTOSKRNL] Implement support for device maps in ObpLookupObjectName
This allows getting rid of the ?? hack in the kernel but this doesn't
allow enabling LUID device maps as ReactOS can no longer open a
session with them enabled. So, we must remain with device maps at
root

CORE-16114
2019-06-30 23:07:54 +02:00
Bișoc George 42ce8519b6 [FASTFAT][FLTMGR][NTOS] Do not explicitly call ObfDereferenceObject() (#1636)
"Most code should not directly call the platform-specific ObfDereferenceObject() function but use the ObDereferenceObject() macro instead."

CORE-16081
2019-06-22 16:20:58 +02:00
Pierre Schweitzer f6eb13a969
[NTOSKRNL] Rework ObpDeleteSymbolicLinkName and ObpCreateSymbolicLinkName
So that they handle LUID mappings and process device maps.

Get rid of the ObpParseSymbolicLinkToIoDeviceObject helper and introduce a
new helper ObpProcessDosDeviceSymbolicLink that will do the same things
but also handle name creation/deletion as well as device map handling.
All this is based on previous code (hence the same comments :-)).

What's left to do now is to add support for device maps in ObpLookupObjectName
2019-06-11 21:21:52 +02:00
Pierre Schweitzer 33604e0147
[NTOSKRNL] Fix ObpLUIDDeviceMapsEnabled initialization 2019-06-10 21:17:21 +02:00
Pierre Schweitzer fd4752450f
[NTOSKRNL] Add support for global DOS directory in ObpLookupEntryDirectory
If any exists, we'll loop over in that directory, trying to find the object
2019-06-02 21:46:35 +02:00
Pierre Schweitzer de17b36037
[NTOSKRNL] Implement ObSetDirectoryDeviceMap 2019-06-01 21:22:30 +02:00
Pierre Schweitzer 7c618faa32
[NTOSKRNL] Implement SeGetLogonIdDeviceMap 2019-06-01 21:09:20 +02:00
Pierre Schweitzer 4bf7d54910
[NTOSKRNL] Implement ObpSetCurrentProcessDeviceMap 2019-06-01 18:58:36 +02:00
Pierre Schweitzer 57c6086806
[NTOSKRNL] Implement ObpReferenceDeviceMap() 2019-06-01 18:43:38 +02:00
Pierre Schweitzer 46b90ccb96
[NTOSKRNL] Add support for LUID mappings in ObQueryDeviceMapInformation 2019-06-01 17:40:18 +02:00
Pierre Schweitzer 1074a9aaff
[NTOSKRNL] Implement support for PROCESS_DEVICEMAP_INFORMATION_EX in NtQueryInformationProcess 2019-06-01 15:18:52 +02:00
Pierre Schweitzer b16a07fa69
[NTOSKRNL] Implement ObIsLUIDDeviceMapsEnabled and call it in NtQueryInformationProcess 2019-06-01 14:56:28 +02:00
Pierre Schweitzer 7898b2eaa3
[NTOSKRNL] Disable LUID mapping until it's properly implemented 2019-06-01 14:40:54 +02:00
Pierre Schweitzer 848f7bb687
[NTOSKRNL] On device map freeing, make directory object temporary again 2019-06-01 13:59:13 +02:00
Pierre Schweitzer 221ed88141
[NTOSKRNL] De-duplicate code between Ob(f)DereferenceDeviceMap functions 2019-06-01 13:54:34 +02:00
Pierre Schweitzer 1b42731dca
[NTOSKRNL] Add a few ASSERTs to ObpGetDosDevicesProtection for DBG builds 2019-06-01 13:51:40 +02:00
Pierre Schweitzer 8f655f9466
[NTOSKRNL] Implement ObpFreeDosDevicesProtection to free DACL 2019-06-01 13:44:55 +02:00
Pierre Schweitzer 933dddeb07
[NTOSKRNL] Modify ObpCreateDeviceMap so that it can handle any process
It is now able to set the newly created device map to any
process and will default to current process if none is provided.
It also sets system device map if no process is specified.
It also deferences existing device map in the process if needed.
Finaly, it will make the directory object permanant.
2019-06-01 13:35:41 +02:00
Pierre Schweitzer fe6c7f05e2
[NTOSKRNL] Use the security descriptor for all the symlinks 2019-05-21 19:28:17 +02:00
Pierre Schweitzer 95d303bf13
[NTOSKRNL] Simplify ObpCreateGlobalDosDevicesSD by using a SD on the stack
Rename it to ObpGetDosDevicesProtection to reflect the two previous changes:
its purpose is to return a DACL matching protection mode
2019-05-21 19:28:16 +02:00
Pierre Schweitzer 33f524c625
[NTOSKRNL] Use relaxed ACLs in ObpCreateGlobalDosDevicesSD when protection mode is not set 2019-05-21 19:28:16 +02:00
Pierre Schweitzer 1c4e44592c
[NTOSKRNL] Save ProtectionMode value on boot 2019-05-21 19:28:16 +02:00
Pierre Schweitzer a33a69b3f4
[NTOSKRNL] Save ObjectSecurityMode value on boot 2019-05-18 10:37:24 +02:00
Thomas Faber f5fc9e0cf2
[NTOS:OB] Correctly handle OBJ_PROTECT_CLOSE in ObDuplicateObject. 2019-02-02 23:02:50 +01:00
Serge Gautherie 0483a5a380 [NTOS:OB] Correctly check SeSinglePrivilegeCheck() return value (#1323)
SeSinglePrivilegeCheck() returns a BOOLEAN, not a NTSTATUS.
CORE-14271
2019-01-30 00:43:13 +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
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