kernel
Loading...
Searching...
No Matches
probe.c
Go to the documentation of this file.
1
/*++
2
3
Module Name:
4
5
probe.c
6
7
Purpose:
8
9
This translation unit contains the implementation of probing user addresses.
10
11
Author:
12
13
slep (Matanel) 2025.
14
15
Revision History:
16
17
--*/
18
19
#include "
../../includes/exception.h
"
20
#include "
../../assert.h
"
21
22
MTSTATUS
23
ProbeForRead
(
24
IN
const
void
*
Address
,
25
IN
size_t
Length
,
26
IN
uint32_t Alignment
27
)
28
29
/*++
30
31
Routine description:
32
33
Checks if the given user address is within the correct bounds and alignment of access.
34
35
Arguments:
36
37
[IN] const void* Address - The user address to check.
38
[IN] size_t Length - Length in bytes of user mode buffer.
39
[IN] uint32_t Alignment - Required alignment (in bytes) of user mode buffer. (1 for char, 2 for word, 4 for int, 8 for long long)
40
41
Return Values:
42
43
MTSTATUS Code.
44
45
MT_SUCCESS - Address is fine and meets boundaries and length + alignment.
46
MT_DATAYPE_MISALIGNMENT - The address given is not aligned properly with the datatype alignment given.
47
MT_ACCESS_VIOLATION - The address given is not within boundaries of the user mode virtual address range.
48
49
--*/
50
51
{
52
if
(!
Address
)
return
MT_ACCESS_VIOLATION
;
53
// Standard assertion to check if alignment meets function requirements. (and CPU)
54
assert
((Alignment == 1) || (Alignment == 2) || (Alignment == 4) || (Alignment == 8));
55
56
// Check Alignment
57
if
(((uint64_t)
Address
& (Alignment - 1)) != 0) {
58
return
MT_DATATYPE_MISALIGNMENT
;
59
}
60
61
if
(
Length
!= 0) {
62
uint64_t Start = (uint64_t)
Address
;
63
uint64_t End = Start +
Length
;
// Integer addition, exact bytes
64
65
// Check Overflow (Wrap around)
66
if
(End < Start) {
67
return
MT_ACCESS_VIOLATION
;
68
}
69
70
// Check against Highest User Address
71
// This should not be the MmUserProbeAddress, as the stack lives above that address, and if a user gives something from his stack there, it would resolve in an MT_ACCESS_VIOLATION.
72
if
(End > (uint64_t)
MmHighestUserAddress
) {
73
return
MT_ACCESS_VIOLATION
;
74
}
75
}
76
return
MT_SUCCESS
;
77
}
IN
#define IN
Definition
annotations.h:8
assert.h
assert
#define assert(...)
Definition
assert.h:57
exception.h
Address
uint64_t Address
Definition
mh.h:4
Length
uint32_t Length
Definition
mh.h:6
MT_SUCCESS
#define MT_SUCCESS
Definition
mtstatus.h:22
MT_DATATYPE_MISALIGNMENT
#define MT_DATATYPE_MISALIGNMENT
Definition
mtstatus.h:135
MTSTATUS
int32_t MTSTATUS
Definition
mtstatus.h:12
MT_ACCESS_VIOLATION
#define MT_ACCESS_VIOLATION
Definition
mtstatus.h:131
ProbeForRead
MTSTATUS ProbeForRead(IN const void *Address, IN size_t Length, IN uint32_t Alignment)
Definition
probe.c:23
MmHighestUserAddress
uintptr_t MmHighestUserAddress
Definition
process.c:32
Users
matanel
Desktop
Projects
KernelDevelopment
kernel
core
exp
probe.c
Generated by
1.14.0