-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Object Manager Plus #2197
base: master
Are you sure you want to change the base?
Object Manager Plus #2197
Changes from all commits
2463e2c
6df0062
0d69a76
726209f
7d56d32
0f62519
535512f
2a5be4c
9ef7295
a56cead
7a8d222
07d02b7
6129939
61ee5dc
3f0fcb6
64ca49c
de9c45d
d32789f
d3717d1
5d0ccff
c6443fe
2f1f76a
8dbe1a7
d01f1be
9d5e5b6
e430722
c4cd9db
2e873d6
40c73c0
d241e11
39fe831
8efc05b
d0969ea
b36c721
636fe14
85b0bca
40df499
117433b
523ee43
63a4e21
d1fc7bc
2f12ae5
20aadaa
521daf7
090eafc
6a54450
90918e7
28672d2
d2dde14
65047f5
97126e7
178cfd6
9e82cd2
b33af14
2a633f4
bfeaca9
df35cfa
881c3bf
fc395e6
69992cc
ced53e6
b6a0d64
bbc49c1
0d532c5
4e99970
fc988a2
52a5063
4b385f2
77db313
a42066a
048fb5a
f906b11
9320999
17e3d0c
7934455
5fe9630
f402c50
1cd222d
aecb9f9
fb32568
828ee39
ce9ebf9
3d3a1f7
11f2c6f
d75dcb2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2372,6 +2372,62 @@ NTSTATUS KphOpenNamedObject( | |
return status; | ||
} | ||
|
||
/** | ||
* \brief Opens a named object by its type index from nt!ObTypeIndexTable. | ||
* | ||
* \param[out] ObjectHandle Set to the opened handle. | ||
* \param[in] DesiredAccess Desires access to the object. | ||
* \param[in] ObjectAttributes Attributes to open the object. | ||
* \param[in] TypeIndex Type index of object to open. | ||
* \param[in] AccessMode The mode in which to perform access checks. | ||
* | ||
* \return Successful or errant status. | ||
*/ | ||
_IRQL_requires_max_(PASSIVE_LEVEL) | ||
_Must_inspect_result_ | ||
NTSTATUS KphOpenObjectByTypeIndex( | ||
_Out_ PHANDLE ObjectHandle, | ||
_In_ ACCESS_MASK DesiredAccess, | ||
_In_ POBJECT_ATTRIBUTES ObjectAttributes, | ||
_In_ ULONG TypeIndex, | ||
_In_ KPROCESSOR_MODE AccessMode | ||
) | ||
{ | ||
KPH_PAGED_CODE_PASSIVE(); | ||
|
||
if (!KphDynObTypeIndexTable) | ||
{ | ||
return STATUS_NOINTERFACE; | ||
} | ||
|
||
if (AccessMode != KernelMode) | ||
{ | ||
OBJECT_TYPES_INFORMATION typesInfo = { 0 }; | ||
|
||
if (ZwQueryObject(NULL, | ||
ObjectTypesInformation, | ||
&typesInfo, | ||
sizeof(typesInfo), | ||
NULL) == STATUS_INFO_LENGTH_MISMATCH) | ||
{ | ||
if (TypeIndex < 2 || TypeIndex > typesInfo.NumberOfTypes) | ||
{ | ||
return STATUS_INVALID_PARAMETER; | ||
} | ||
} | ||
else | ||
{ | ||
return STATUS_UNSUCCESSFUL; | ||
} | ||
} | ||
|
||
return KphOpenNamedObject(ObjectHandle, | ||
DesiredAccess, | ||
ObjectAttributes, | ||
KphDynObTypeIndexTable[TypeIndex], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can cause an out of bounds read in kernel mode. The kernel should not trust input from user mode under any circumstances. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought that it enough to validate parameters in native.c
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That might be fine. Although I'll have to check some internals to be certain. Ideally, since we would be using some dyndata anyway - we would extract both the table and the count to avoid the syscall. But it sounds like |
||
AccessMode); | ||
} | ||
|
||
/** | ||
* \brief Duplicates an object. | ||
* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not yet clear to me in the PR why this is necessary. Or why any additional driver APIs are necessary at all. In any case we need to be careful here and make sure this is correct. If we do need this we need some dynamic data handling around it.
I would prefer to take care of driver changes like this myself. If there is something you need for the driver to achieve the goals please allow me time to provide an appropriately safe API to do so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was experimental implementation, and I know what it is bad and not safe. I wrote this with a purpose to open objects for which public
NtOpenXXX
API isn't existing (like Type, Callback). This gives a power to open any object.Object types table offset is RIP relative to instruction in
ObGetObjectType
. To add it to dyndata we need to knowObGetObjectType
address,lea rcx
instruction address and offset vaule, then we can calculate full address. And we should do it at runtime, since it address points to data section of loaded kernel image (hope I'm not wrong).It's very interesting, but for now there is no particular need of
KphOpenObjectByTypeIndex
. Type information and statistics can be retrieved without need to open this Type object. Current implementation always open object properties, even if object cannot be opened.But, if possible, I really want to keep
PhOpenDevice
(see answer below).Example,
\ObjectTypes\Token
information with driver and KphOpenObjectByTypeIndex (left), and without (right):s04_00-08_TGEhD.mp4