Return 0xC0000022 by Calling of ObRegisterCallbacks()

Hi all,
I got the wdk6001, and try to write a driver on 64bits windows vista sp1 with the new api : ObRegisterCallbacks( ) and ObUnregisterCallbacks ().
The driver receive IOCTL from user mode program after it is installed,then call the ObRegisterCallbacks( ), but I got the return value with 0xC0000022, are there anybody know what is the reason?

these are my codes:

SYSTEM_VERSION g_OsVer;
PVOID *g_hProcCreateHandle;

//
// PRE OPERATION
//
OB_PREOP_CALLBACK_STATUS PreProcCreateRoutine(
__in PVOID RegistrationContext,
__inout POB_PRE_OPERATION_INFORMATION OperationInformation
)
{
OB_PRE_OPERATION_INFORMATION OpInfo;

KDPRINT((“PreProcCreateRoutine()”));

return OB_PREOP_SUCCESS;
}

//
// POST OPERATION
//
VOID PostProcCreateRoutine( __in PVOID RegistrationContext,
__in POB_POST_OPERATION_INFORMATION OperationInformation)
{
KDPRINT((“PostProcCreateRoutine.”));
}

//
// REGISTE CALLBACK FUNCTION
//
NTSTATUS RegisteCallbackFunction()
{
NTSTATUS ntStatus = STATUS_SUCCESS;

UNICODE_STRING Altitude;

USHORT filterVersion = ObGetFilterVersion();
USHORT registrationCount = 2;

POB_OPERATION_REGISTRATION ProcCreateOperation;
POB_CALLBACK_REGISTRATION ProcCreateCallBack;

REG_CONTEXT *hRegistrationContext;
hRegistrationContext = MALLOC(sizeof(REG_CONTEXT));
hRegistrationContext->ulIndex = 1;

ProcCreateOperation = MALLOC(sizeof(OB_OPERATION_REGISTRATION));
ProcCreateCallBack = MALLOC(sizeof(OB_CALLBACK_REGISTRATION));

if (filterVersion == OB_FLT_REGISTRATION_VERSION)
{
KDPRINT((“Filter Version is correct.”));

ProcCreateOperation->ObjectType = PsProcessType;
ProcCreateOperation->Operations = OB_OPERATION_HANDLE_CREATE;
ProcCreateOperation->PreOperation = PreProcCreateRoutine;
ProcCreateOperation->PostOperation = PostProcCreateRoutine;

ProcCreateCallBack->Version = OB_FLT_REGISTRATION_VERSION;
ProcCreateCallBack->OperationRegistrationCount = registrationCount;

RtlInitUnicodeString(&Altitude, L"123456");
ProcCreateCallBack->Altitude = Altitude;

ProcCreateCallBack->RegistrationContext = hRegistrationContext;
ProcCreateCallBack->OperationRegistration = ProcCreateOperation;

ntStatus = ObRegisterCallbacks(ProcCreateCallBack, g_hProcCreateHandle);
if (ntStatus == STATUS_SUCCESS)
{
KDPRINT((“Register Callback Function Successful…”));
} else {
if (ntStatus == STATUS_FLT_INSTANCE_ALTITUDE_COLLISION)
{
KDPRINT((“Status Filter Instance Altitude Collision”));
}
if (ntStatus == STATUS_INVALID_PARAMETER)
{
KDPRINT((“Status Invalid Parameter”));
}
if (ntStatus == STATUS_INSUFFICIENT_RESOURCES )
{
KDPRINT((“Status Allocate Memory Failed.”));
}

KDPRINT((“Register Callback Function Failed with 0x%08x”, ntStatus));
}

} else {
KDPRINT(("Filter Version is not supported. "));
}

return ntStatus;
}

//
// FREE PROC FILTER
//
NTSTATUS FreeProcFilter()
{
ObUnRegisterCallbacks(g_hProcCreateHandle);

return STATUS_SUCCESS;
}

//
// INIT PROC FILTER
//
NTSTATUS InitProcFilter()
{
if (RegisteCallbackFunction() == STATUS_SUCCESS)
{
KDPRINT((“Register Callback Function Successfully…”));
}

return STATUS_SUCCESS;
}

//
// IOCTL
//
NTSTATUS DoDeviceIoControl(IN PDEVICE_OBJECT pDriverObject, IN PIRP pIrp)
{
NTSTATUS ntStatus = STATUS_SUCCESS;
PIO_STACK_LOCATION irpStack = IoGetCurrentIrpStackLocation(pIrp);
ULONG ulIoctlCode;

ulIoctlCode = irpStack->Parameters.DeviceIoControl.IoControlCode;
switch(ulIoctlCode)
{
case IOCTL_HOOK_SYSTEM_CALL:
InitProcFilter();
break;

case IOCTL_UNHOOK_SYSTEM_CALL:
FreeProcFilter();
break;
}
return ntStatus;
}

Your binary must be signed for the registration to work, this is why you are receiving STATUS_ACCESS_DENIED. Also you are leaking ProcCreateOperation, ProcCreateCallBack, and hRegistrationContext (not that there is any need in the first place for you to allocate them, they can be declared on the stack). I will file a bug to fix the doc to include this error code

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@msn.com
Sent: Thursday, November 01, 2007 7:14 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Return 0xC0000022 by Calling of ObRegisterCallbacks()

Hi all,
I got the wdk6001, and try to write a driver on 64bits windows vista sp1 with the new api : ObRegisterCallbacks( ) and ObUnregisterCallbacks ().
The driver receive IOCTL from user mode program after it is installed,then call the ObRegisterCallbacks( ), but I got the return value with 0xC0000022, are there anybody know what is the reason?

these are my codes:

SYSTEM_VERSION g_OsVer;
PVOID *g_hProcCreateHandle;

//
// PRE OPERATION
//
OB_PREOP_CALLBACK_STATUS PreProcCreateRoutine(
__in PVOID RegistrationContext,
__inout POB_PRE_OPERATION_INFORMATION OperationInformation
)
{
OB_PRE_OPERATION_INFORMATION OpInfo;

KDPRINT((“PreProcCreateRoutine()”));

return OB_PREOP_SUCCESS;
}

//
// POST OPERATION
//
VOID PostProcCreateRoutine( __in PVOID RegistrationContext,
__in POB_POST_OPERATION_INFORMATION OperationInformation)
{
KDPRINT((“PostProcCreateRoutine.”));
}

//
// REGISTE CALLBACK FUNCTION
//
NTSTATUS RegisteCallbackFunction()
{
NTSTATUS ntStatus = STATUS_SUCCESS;

UNICODE_STRING Altitude;

USHORT filterVersion = ObGetFilterVersion();
USHORT registrationCount = 2;

POB_OPERATION_REGISTRATION ProcCreateOperation;
POB_CALLBACK_REGISTRATION ProcCreateCallBack;

REG_CONTEXT *hRegistrationContext;
hRegistrationContext = MALLOC(sizeof(REG_CONTEXT));
hRegistrationContext->ulIndex = 1;

ProcCreateOperation = MALLOC(sizeof(OB_OPERATION_REGISTRATION));
ProcCreateCallBack = MALLOC(sizeof(OB_CALLBACK_REGISTRATION));

if (filterVersion == OB_FLT_REGISTRATION_VERSION)
{
KDPRINT((“Filter Version is correct.”));

ProcCreateOperation->ObjectType = PsProcessType;
ProcCreateOperation->Operations = OB_OPERATION_HANDLE_CREATE;
ProcCreateOperation->PreOperation = PreProcCreateRoutine;
ProcCreateOperation->PostOperation = PostProcCreateRoutine;

ProcCreateCallBack->Version = OB_FLT_REGISTRATION_VERSION;
ProcCreateCallBack->OperationRegistrationCount = registrationCount;

RtlInitUnicodeString(&Altitude, L"123456");
ProcCreateCallBack->Altitude = Altitude;

ProcCreateCallBack->RegistrationContext = hRegistrationContext;
ProcCreateCallBack->OperationRegistration = ProcCreateOperation;

ntStatus = ObRegisterCallbacks(ProcCreateCallBack, g_hProcCreateHandle);
if (ntStatus == STATUS_SUCCESS)
{
KDPRINT((“Register Callback Function Successful…”));
} else {
if (ntStatus == STATUS_FLT_INSTANCE_ALTITUDE_COLLISION)
{
KDPRINT((“Status Filter Instance Altitude Collision”));
}
if (ntStatus == STATUS_INVALID_PARAMETER)
{
KDPRINT((“Status Invalid Parameter”));
}
if (ntStatus == STATUS_INSUFFICIENT_RESOURCES )
{
KDPRINT((“Status Allocate Memory Failed.”));
}

KDPRINT((“Register Callback Function Failed with 0x%08x”, ntStatus));
}

} else {
KDPRINT(("Filter Version is not supported. "));
}

return ntStatus;
}

//
// FREE PROC FILTER
//
NTSTATUS FreeProcFilter()
{
ObUnRegisterCallbacks(g_hProcCreateHandle);

return STATUS_SUCCESS;
}

//
// INIT PROC FILTER
//
NTSTATUS InitProcFilter()
{
if (RegisteCallbackFunction() == STATUS_SUCCESS)
{
KDPRINT((“Register Callback Function Successfully…”));
}

return STATUS_SUCCESS;
}

//
// IOCTL
//
NTSTATUS DoDeviceIoControl(IN PDEVICE_OBJECT pDriverObject, IN PIRP pIrp)
{
NTSTATUS ntStatus = STATUS_SUCCESS;
PIO_STACK_LOCATION irpStack = IoGetCurrentIrpStackLocation(pIrp);
ULONG ulIoctlCode;

ulIoctlCode = irpStack->Parameters.DeviceIoControl.IoControlCode;
switch(ulIoctlCode)
{
case IOCTL_HOOK_SYSTEM_CALL:
InitProcFilter();
break;

case IOCTL_UNHOOK_SYSTEM_CALL:
FreeProcFilter();
break;
}
return ntStatus;
}


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

must user mode program be signed ?

no.

xxxxx@msn.com wrote:

must user mode program be signed ?

I signed my driver and driver can be installed, but I got the C0000022 still.
are there something with the paramenter: Altitude?
the altitude value that I used belongs to a fsfilter driver, will my driver placed into a fsfilter stack? so that my driver can not call the new API?

STATUS_ACCESS_DENIED - it would appear that your call to
ObRegisterCallbacks does not have the correct permissions. In the world
of Longhonr/Vista you never have permission to do anything. Perhaps
registration should be handed off to a worker thread?

Regarding altitudes, you are supposed to go and get a unique one just
like a minifilter.

Have you read this?
http://download.microsoft.com/download/4/4/b/44bb7147-f058-4002-9ab2-ed2
2870e3fe9/Kernal%20Data%20and%20Filtering%20Support%20for%20Windows%20Se
rver%202008.doc

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@msn.com
Sent: Monday, November 05, 2007 8:01 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Return 0xC0000022 by Calling of
ObRegisterCallbacks()

I signed my driver and driver can be installed, but I got the C0000022
still.
are there something with the paramenter: Altitude?
the altitude value that I used belongs to a fsfilter driver, will my
driver placed into a fsfilter stack? so that my driver can not call the
new API?


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

>I signed my driver and driver can be installed, but I got the C0000022

still.

You also need to use the /INTEGRITYCHECK linker switch.


This posting is provided “AS IS” with no warranties, and confers no
rights.