ReactOS 0.4.17-dev-116-ga4b6fe9
dispatch.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Kernel Security Support Provider Interface Driver
3 * LICENSE: MIT (https://spdx.org/licenses/MIT)
4 * PURPOSE: Dispatch routines for ksecdd
5 * COPYRIGHT: Copyright 2014 Timo Kreuzer <timo.kreuzer@reactos.org>
6 */
7
8/* INCLUDES *******************************************************************/
9
10#include "ksecdd.h"
11#include <ksecioctl.h>
12
13#define NDEBUG
14#include <debug.h>
15
16
17/* FUNCTIONS ******************************************************************/
18
19static
22 PVOID InfoBuffer,
25{
26 PFILE_STANDARD_INFORMATION StandardInformation;
27
28 /* Only FileStandardInformation is supported */
30 {
32 }
33
34 /* Validate buffer size */
36 {
39 }
40
41 /* Fill the structure */
42 StandardInformation = (PFILE_STANDARD_INFORMATION)InfoBuffer;
43 StandardInformation->AllocationSize.QuadPart = 0;
44 StandardInformation->EndOfFile.QuadPart = 0;
45 StandardInformation->NumberOfLinks = 1;
46 StandardInformation->DeletePending = FALSE;
47 StandardInformation->Directory = FALSE;
49
50 return STATUS_SUCCESS;
51}
52
53static
56 PVOID InfoBuffer,
59{
60 PFILE_FS_DEVICE_INFORMATION DeviceInformation;
61
62 /* Only FileFsDeviceInformation is supported */
64 {
66 }
67
68 /* Validate buffer size */
70 {
73 }
74
75 /* Fill the structure */
76 DeviceInformation = (PFILE_FS_DEVICE_INFORMATION)InfoBuffer;
77 DeviceInformation->DeviceType = FILE_DEVICE_NULL;
78 DeviceInformation->Characteristics = 0;
80
81 return STATUS_SUCCESS;
82}
83
84static
89 SIZE_T InputLength,
90 PSIZE_T OutputLength)
91{
93
101 {
102 /* Make sure we have a valid output buffer */
103 if ((Buffer == NULL) || (OutputLength == NULL))
104 {
106 }
107
108 /* Check if the input is smaller than the output */
109 if (InputLength < *OutputLength)
110 {
111 /* We might have uninitialized memory, zero it out */
112 RtlSecureZeroMemory((PUCHAR)Buffer + InputLength,
113 *OutputLength - InputLength);
114 }
115 }
116
117 /* Check ioctl code */
118 switch (IoControlCode)
119 {
121
123 break;
124
126
127 Status = KsecGenRandom(Buffer, *OutputLength);
128 break;
129
131
133 *OutputLength,
135 break;
136
138
140 *OutputLength,
142 break;
143
145
147 *OutputLength,
149 break;
150
152
154 *OutputLength,
156 break;
157
159
161 *OutputLength,
163 break;
164
166
168 *OutputLength,
170 break;
171
172 default:
173 DPRINT1("Unhandled control code 0x%lx\n", IoControlCode);
174 __debugbreak();
176 }
177
178 return Status;
179}
180
182NTAPI
185 PIRP Irp)
186{
191 SIZE_T InputLength, OutputLength;
192 FILE_INFORMATION_CLASS FileInfoClass;
193 FS_INFORMATION_CLASS FsInfoClass;
195
197
199 {
200 case IRP_MJ_CREATE:
201 case IRP_MJ_CLOSE:
202
203 /* Just return success */
205 Information = 0;
206 break;
207
208 case IRP_MJ_READ:
209
210 /* There is nothing to read */
212 Information = 0;
213 break;
214
215 case IRP_MJ_WRITE:
216
217 /* Pretend to have written everything */
220 break;
221
223
224 /* Extract the parameters */
225 Buffer = Irp->AssociatedIrp.SystemBuffer;
226 OutputLength = IoStackLocation->Parameters.QueryFile.Length;
227 FileInfoClass = IoStackLocation->Parameters.QueryFile.FileInformationClass;
228
229 /* Call the internal function */
231 FileInfoClass,
232 &OutputLength);
233 Information = OutputLength;
234 break;
235
237
238 /* Extract the parameters */
239 Buffer = Irp->AssociatedIrp.SystemBuffer;
240 OutputLength = IoStackLocation->Parameters.QueryVolume.Length;
241 FsInfoClass = IoStackLocation->Parameters.QueryVolume.FsInformationClass;
242
243 /* Call the internal function */
245 FsInfoClass,
246 &OutputLength);
247 Information = OutputLength;
248 break;
249
251
252 /* Extract the parameters */
253 InputLength = IoStackLocation->Parameters.DeviceIoControl.InputBufferLength;
254 OutputLength = IoStackLocation->Parameters.DeviceIoControl.OutputBufferLength;
256
257 /* Check for METHOD_OUT_DIRECT method */
259 (OutputLength != 0))
260 {
261 /* Use the provided MDL */
262 OutputLength = Irp->MdlAddress->ByteCount;
265 if (Buffer == NULL)
266 {
268 Information = 0;
269 break;
270 }
271 }
272 else
273 {
274 /* Otherwise this is METHOD_BUFFERED, use the SystemBuffer */
275 Buffer = Irp->AssociatedIrp.SystemBuffer;
276 }
277
278 /* Call the internal function */
280 Buffer,
281 InputLength,
282 &OutputLength);
283 Information = OutputLength;
284 break;
285
286 default:
287 DPRINT1("Unhandled major function %lu!\n",
289 ASSERT(FALSE);
291 }
292
293 /* Return the information */
294 Irp->IoStatus.Status = Status;
295 Irp->IoStatus.Information = Information;
296
297 /* Complete the request */
299
300 return Status;
301}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
Definition: bufpool.h:45
_In_ PIRP Irp
Definition: csq.h:116
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
NTSTATUS NTAPI KsecDecryptMemory(_Inout_ PVOID Buffer, _In_ ULONG Length, _In_ ULONG OptionFlags)
Definition: crypt.c:327
NTSTATUS NTAPI KsecEncryptMemory(_Inout_ PVOID Buffer, _In_ ULONG Length, _In_ ULONG OptionFlags)
Definition: crypt.c:292
static NTSTATUS KsecDeviceControl(ULONG IoControlCode, PVOID Buffer, SIZE_T InputLength, PSIZE_T OutputLength)
Definition: dispatch.c:86
static NTSTATUS KsecQueryVolumeInformation(PVOID InfoBuffer, FS_INFORMATION_CLASS FsInformationClass, PSIZE_T BufferLength)
Definition: dispatch.c:55
static NTSTATUS KsecQueryFileInformation(PVOID InfoBuffer, FILE_INFORMATION_CLASS FileInformationClass, PSIZE_T BufferLength)
Definition: dispatch.c:21
NTSTATUS NTAPI KsecDdDispatch(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: dispatch.c:183
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG _In_ FS_INFORMATION_CLASS FsInformationClass
Definition: fltkernel.h:1330
enum _FILE_INFORMATION_CLASS FILE_INFORMATION_CLASS
Definition: directory.c:44
@ FileFsDeviceInformation
Definition: from_kernel.h:222
enum _FSINFOCLASS FS_INFORMATION_CLASS
Status
Definition: gdiplustypes.h:25
NTSTATUS NTAPI KsecGenRandom(PVOID Buffer, SIZE_T Length)
Definition: random.c:25
#define RTL_ENCRYPT_OPTION_SAME_LOGON
Definition: ksecdd.h:27
#define RTL_ENCRYPT_OPTION_SAME_PROCESS
Definition: ksecdd.h:25
#define RTL_ENCRYPT_OPTION_CROSS_PROCESS
Definition: ksecdd.h:26
#define IOCTL_KSEC_ENCRYPT_CROSS_PROCESS
Definition: ksecioctl.h:26
#define IOCTL_KSEC_DECRYPT_SAME_LOGON
Definition: ksecioctl.h:38
#define IOCTL_KSEC_DECRYPT_CROSS_PROCESS
Definition: ksecioctl.h:30
#define IOCTL_KSEC_ENCRYPT_SAME_PROCESS
Definition: ksecioctl.h:18
#define IOCTL_KSEC_ENCRYPT_SAME_LOGON
Definition: ksecioctl.h:34
#define IOCTL_KSEC_REGISTER_LSA_PROCESS
Definition: ksecioctl.h:6
#define IOCTL_KSEC_RANDOM_FILL_BUFFER
Definition: ksecioctl.h:14
#define IOCTL_KSEC_DECRYPT_SAME_PROCESS
Definition: ksecioctl.h:22
#define ASSERT(a)
Definition: mode.c:44
#define FILE_STANDARD_INFORMATION
Definition: disk.h:54
@ NormalPagePriority
Definition: imports.h:54
struct _FILE_FS_DEVICE_INFORMATION * PFILE_FS_DEVICE_INFORMATION
struct _FILE_FS_DEVICE_INFORMATION FILE_FS_DEVICE_INFORMATION
#define METHOD_OUT_DIRECT
Definition: nt_native.h:596
static OUT PIO_STATUS_BLOCK OUT PVOID IN ULONG IN FILE_INFORMATION_CLASS FileInformationClass
Definition: pipe.c:100
#define IoCompleteRequest
Definition: irp.c:1240
#define STATUS_INVALID_INFO_CLASS
Definition: ntstatus.h:333
#define FILE_DEVICE_NULL
Definition: winioctl.h:66
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
#define IRP_MJ_READ
Definition: rdpdr.c:46
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
#define IRP_MJ_QUERY_VOLUME_INFORMATION
Definition: rdpdr.c:50
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define IRP_MJ_QUERY_INFORMATION
Definition: rdpdr.c:48
void __cdecl __debugbreak(void)
Definition: intrin_ppc.h:698
struct _FILE_STANDARD_INFORMATION * PFILE_STANDARD_INFORMATION
#define FileStandardInformation
Definition: propsheet.cpp:61
#define STATUS_END_OF_FILE
Definition: shellext.h:67
#define STATUS_SUCCESS
Definition: shellext.h:65
LARGE_INTEGER AllocationSize
Definition: propsheet.cpp:54
struct _IO_STACK_LOCATION::@4454::@4459 Write
union _IO_STACK_LOCATION::@1696 Parameters
struct _IO_STACK_LOCATION::@1696::@1697 DeviceIoControl
struct _IO_STACK_LOCATION::@4454::@4467 QueryVolume
struct _IO_STACK_LOCATION::@4454::@4463 QueryFile
ULONG_PTR * PSIZE_T
Definition: typedefs.h:80
#define NTAPI
Definition: typedefs.h:36
ULONG_PTR SIZE_T
Definition: typedefs.h:80
uint32_t ULONG_PTR
Definition: typedefs.h:65
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
LONGLONG QuadPart
Definition: typedefs.h:114
_In_ PIO_STACK_LOCATION IoStackLocation
Definition: usbdlib.h:265
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2061
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG BufferLength
Definition: wdfdevice.h:3777
_In_ WDFREQUEST _In_ size_t _In_ size_t _In_ ULONG IoControlCode
Definition: wdfio.h:325
_In_ WDFREQUEST _In_ NTSTATUS _In_ ULONG_PTR Information
Definition: wdfrequest.h:1049
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define METHOD_FROM_CTL_CODE(ctrlCode)
#define MmGetSystemAddressForMdlSafe(_Mdl, _Priority)
FORCEINLINE PVOID RtlSecureZeroMemory(_Out_writes_bytes_all_(Size) PVOID Pointer, _In_ SIZE_T Size)
Definition: rtlfuncs.h:3142