阅读:1613回复:3
一段文件审计操作的驱动运行一段时间后系统资源不足,而不蓝屏,我真的没办法了盼牛牛们~~~
功能:写了一个HOOK文件操作的驱动,上层接收操作动作,进行过滤和审计.
问题:运行的时候,如果我循环的对一个文件进行建立->写->关闭.时间长了后,这个测试代码会出错,用来进行审计的应用程序也会出错.出错后再对系统进行操作时会显示"资源不足".但是不蓝屏,只是在驱动中开配ExAllocatePool(PagedPool,1024)是,会得到NULL值.我查了驱动里面所有的内存都合法配放了的.下面是驱动里面的主要代码和应用层接收日志的主要代码: 驱动层 得到文件操作: do { pFileOperInfo=(FILEOPER_INFO*)ExAllocatePool(PagedPool, sizeof(FILEOPER_INFO)); if( nType == TFILE_CREATE || nType == TFILE_OPEN) { // 取得全路径 wstrBuf = (WCHAR*)ExAllocatePool(PagedPool, MY_MAX_PATH); if( wstrBuf == NULL) { ExFreePool( pFileOperInfo); break; } RtlZeroMemory( wstrBuf, MY_MAX_PATH); retLen = MyGetFullPath(wstrBuf, MY_MAX_PATH, ObjectAttributes); RtlInitUnicodeString( &uniFileName, wstrBuf); if( retLen <=4) { KdPrint(( "MyGetFullPath: <=4 \n")); ExFreePool( pFileOperInfo); break; } if( RtlUnicodeStringToAnsiString( &ansiFileName, &uniFileName, TRUE) !=STATUS_SUCCESS) { ExFreePool( pFileOperInfo); break; } } bIsAddList = TRUE; AddFileInfoToList( pFileOperInfo); } while(FALSE); if( ansiFileName.Buffer !=NULL) RtlFreeAnsiString(&ansiFileName); if( uniFileName.Buffer !=NULL) RtlFreeUnicodeString(&uniFileName); // // 通知上层事件,可以取新的审计操作信息 // if( pFSpyEventEx !=NULL && bIsAddList) KeSetEvent(pFSpyEventEx, 0, FALSE); KeSetEvent(&event,0,0); 返回审计内容: NTSTATUS IOGetList( PIRP Irp ) { PIO_STACK_LOCATION irpStack; PVOID ioBuffer; ULONG outputBufferLength; PFILEOPER_INFO pFileOperInfo = NULL; int nCurrentLen; ULONG nBufLen; BYTE *pBuf = NULL; int Status=STATUS_SUCCESS; irpStack = IoGetCurrentIrpStackLocation(Irp); ioBuffer = Irp->AssociatedIrp.SystemBuffer; outputBufferLength = irpStack->Parameters.DeviceIoControl.OutputBufferLength; // // 同步,防止正在加入操作数据的时候,试图去删除链表指针 // KeWaitForSingleObject(&event,Executive,KernelMode,0,NULL); pFileOperInfo = RemoveFileOperHead(); if( pFileOperInfo ==NULL) { KeSetEvent(&event,0,0); KeResetEvent( pFSpyEventEx); return STATUS_INSUFFICIENT_RESOURCES; } // // 计算要传送数据长度(PID+nType+fileHandle+ProName+SrcFile+DesFile // nBufLen = sizeof(ULONG)+sizeof(int)+sizeof(ULONG)+ sizeof(int)+pFileOperInfo->nProNameLen+ sizeof(int)+pFileOperInfo->nSrcLen+ sizeof(int)+pFileOperInfo->nDesLen; do { if( outputBufferLength < nBufLen) { KdPrint( ("outputBufferLength < sizeof( FILEOPER_INFO)\n")); Status = STATUS_INSUFFICIENT_RESOURCES; break; } // // 组合需要传送的数据 // pBuf = (BYTE *)ExAllocatePool(PagedPool, nBufLen); .... NdisMoveMemory( ioBuffer, pBuf, nBufLen); Irp->IoStatus.Information = nBufLen; } while(FALSE); if( pBuf !=NULL) ExFreePool( pBuf); if( pFileOperInfo->pProName != NULL) ExFreePool( pFileOperInfo->pProName); if( pFileOperInfo->pSrcFileName != NULL) ExFreePool( pFileOperInfo->pSrcFileName); if( pFileOperInfo->pDesFileName != NULL) ExFreePool( pFileOperInfo->pDesFileName); ExFreePool( pFileOperInfo); KeSetEvent(&event,0,0); KeResetEvent( pFSpyEventEx); return Status; } 应用层收取审计信息: hDrvLink = CreateFile( STR_LINK_NAME, GENERIC_READ| GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL ); m_eventList.SetEvent(); while (bIsGetLogEx) { memset( pBuf, 0, nMaxBufLen); DWORD BytesReturned=0x0; if( !DeviceIoControl( hDrvLink, IOCTL_EVENT_GETOPER, NULL, 0, pBuf, nMaxBufLen, &BytesReturned, NULL)) { ::WaitForSingleObject( hLogEventEx, INFINITE); continue; } // continue; ::WaitForSingleObject( m_eventList.m_hObject, INFINITE); |
|
沙发#
发布于:2007-03-28 13:31
没仔细看代码,不过用LookAsideList分配内存会不会好一点?
|
|
驱动小牛
![]() |
板凳#
发布于:2007-03-28 13:36
没找到问题,lookaside list也没用,资源不足多半是内存泄露.
|
|
地板#
发布于:2007-03-28 17:30
这个用lookaside list分配不了的,我是需要写入链表中.
到现在还没搞明白哪里出的问题,很想不通~~~ |
|