寫驅動的時候有個地方老是藍屏,看了dump發現數據被非法篡改了.
數據初始化如下
if(record_set_ptr != NULL )
{
record_set_ptr->look_aside_pool_ptr = g_user_control_context.look_aside_pools[type] ;
record_set_ptr->type = type ;
record_set_ptr->buffer_size = notify_count * unit_size_of ;
record_set_ptr->units_count = notify_count ;
record_set_ptr->complete_count = 0 ;
}
然后在調用ExFreeToNPagedLookasideList傳入record_set_ptr->look_aside_pool_ptr 的時候掛了,發現record_set_ptr->look_aside_pool_ptr已經被改了.
為了跟蹤數據在哪里被修改了,先在數據初始化的地方下斷,然后記下record_set_ptr->look_aside_pool_ptr 的地址:0x85c16018
對這個內存下個斷點
1: kd> ba w4 85c16018
w表示在寫入時斷下,4表示監控范圍,單位是字節
整個命令的意思就是讓調試器在系統寫入內存85c16018-85c1601b這個地址范圍的時候中斷
OK,命令下完,F5一下就立馬斷下來了
1: kd> g
Breakpoint 3 hit
nt!memcpy+0x33:
8053b583 f3a5 rep movs dword ptr es:[edi],dword ptr [esi]
此時edi的值: 0x85c16018
最后看一下函數堆棧,發現是字符串拷貝越界覆蓋了后面的數據....
后面又想到,出錯時record_set_ptr->look_aside_pool_ptr 的值是0x005c0065
這么明顯的字符串特征竟然沒意識到....一看出錯值就應該知道是字符串覆蓋造成的.....