您的位置:首页 > 服装鞋帽 > 男鞋 > Buffer Overrun Memory Corruptions an...

Buffer Overrun Memory Corruptions an...

luyued 发布于 2011-05-27 18:34   浏览 N 次  

  没有什么不可能,一天一点积累。。。。。。

  

  

  

  

  

  

  

  

  

  Buffer Overrun, Memory Corruptions, and Special Pool By far the most common source of crashes on Windows is pool corruption. Pool corruption usually occurs when a driver suffers from a buffer overrun or buffer underrun bug that causes it to overwrite data past either the end or start of a buffer it has allocated from paged or nonpaged pool. The Executive's pool-tracking structures reside on either side of a pool buffer and separate buffers from each other. These bugs, therefore, cause corruption to the pool tracking structures, to buffers owned by other drivers, or to both. You can often catch the culprit of a pool overrun by using the !pool command to examine the surrounding pool tags. Find the address at which the corruption occurred and use !pool address_of_corruption. This command will display all the pool allocations that are on the same page as the corruption. Looking in the left column, find the range of the corrupted address and then look at the allocation just previous to it and find its pool tag. This will likely be the culprit in a buffer overrun. You can use the pooltag.txt file in the Triage folder of the Debugging Tools for Windows installation directory to find the driver that owns the pool tag, or use the Strings utility from Sysinternals. Pool corruption can also occur when a driver writes to pool it had previously owned but subsequently freed. This is called a use after free bug and is usually caused by a race condition in a driver. These bugs are particularly hard to debug because the driver that corrupts memory no longer has any traceable ties to the memory, such as a neighboring pool tag as in a buffer overrun. Another fairly common cause of pool corruption is direct memory access (DMA). DMA occurs when hardware writes directly to RAM instead of going through a driver; however, the driver is still responsible for coordinating the whole process by allocating the memory that the hardware will write to and programming the hardware registers of the device with the details of the operation. If a driver has a bug that releases the memory it is using for DMA before the hardware writes to it, the memory can be given to another driver or even to a user-mode application, which will certainly not expect to have hardware writing to it. The crashes caused by pool corruption are virtually impossible to debug because the system crashes when corrupted data is referenced, not when the corruption occurs. However, sometimes you can take steps to at least obtain a clue about what corrupted the memory. The first step is to try to determine the size of the corruption by looking at the corrupted data. If the corruption is a single bit, it was likely caused by bad RAM. If the corruption is fairly small, it could be caused by hardware or software, and finding a root cause will be nearly impossible. In the case of large corruptions, you can look for patterns in the corruption, like strings (for example, HTTP packet payloads, file contents of text-based files, and so on) or audio/video data (usually patterns of integers less than 1,024). Open an MP3 file in a hex editor to get an idea of what audio data looks like in memory. Note To assist in catching pool corruptions, Windows checks the consistency of a buffer's pooltracking structures, and those of the buffer's immediate neighbors, on every pool allocation and free operation. Thus, buffer overruns are likely to be detected shortly after the corruption and identified with a crash that has the BAD_POOL_HEADER stop code. You can generate a pool corruption crash by running Notmyfault and selecting the Buffer Overflow bug. This causes Myfault to allocate a buffer and then overwrite the 40 bytes following the buffer. There can be a significant delay between the time you click the Do Bug button and when a crash occurs, and you might even have to generate pool usage by exercising applications before a crash occurs, which highlights the distance between a corruption and its effect on system stability. An analysis of the resultant crash almost always reports Ntoskrnl or another driver as being the likely cause, which demonstrates the usefulness of a verbose analysis with its description of the stop code: 1 DRIVER_CORRUPTED_EXPOOL (c5) 2 An attempt was made to access a pageable (or completely invalid) address at an 3 interrupt request level (IRQL) that is too high. This is 4 caused by drivers that have corrupted the system pool. Run the driver 5 verifier against any new (or suspect) drivers, and if that doesn't turn up 6 the culprit, then use gflags to enable special pool. 7 Arguments: 8 Arg1: 4f4f4f53, memory referenced 9 Arg2: 00000002, IRQL 10 Arg3: 00000001, value 0 = read operation, 1 = write operation 11 Arg4: 81926886, address which referenced memory The advice in the description is to run the Driver Verifier against any new or suspect drivers or to use Gflags to enable special pool. Both accomplish the same thing: to have the system detect a potential corruption when it occurs and crash the system in a way that makes the automated analysis point at the driver causing the corruption. If the Driver Verifier's special pool option is enabled, verified drivers use special pool, rather than paged or nonpaged pool, for any allocations they make for buffers slightly less than a page in size. A buffer allocated from special pool is sandwiched between two invalid pages and by default is aligned against the top of the page. The special pool routines also fill the unused portions of the page in which the buffer resides with a random pattern. Figure 14-9 depicts a special pool allocation. The system detects any buffer overruns of under a page in size at the time of the overrun because they cause a page fault on the invalid page following the buffer. The signature serves to catch buffer underruns at the time the driver frees a buffer because the integrity of the pattern placed there at the time of allocation will have been compromised.

  

  To see how the use of special pool causes a crash that the analysis engine easily diagnoses, run the Driver Verifier Manager. Choose the Create Custom Settings (For Code Developers) option on the first page of the wizard, choose Select Individual Settings From A Full List on the second, and then select Special Pool. Choose the Select Drivers From A List option on the subsequent page, and on the page that lists drivers press the button to add unloaded drivers, and then type myfault.sys into the File Find dialog box. (You do not have to find myfault.sys in the File Find dialog box; just enter its name.) Then check the myfault.sys driver, exit the wizard, and reboot. When you run Notmyfault and cause a buffer overflow, the system will immediately crash and the analysis of the dump reports this: 12 Probably caused by : myfault.sys ( myfault+3f1 ) A verbose analysis describes the stop code like this: 13 DRIVER_PAGE_FAULT_BEYOND_END_OF_ALLOCATION (d6) 14 N bytes of memory was allocated and more than N bytes are being referenced. 15 This cannot be protected by try-except. 16 When possible, the guilty driver's name (Unicode string) is printed on 17 the bugcheck screen and saved in KiBugCheckDriver. 18 Arguments: 19 Arg1: beb50000, memory referenced 20 Arg2: 00000001, value 0 = read operation, 1 = write operation 21 Arg3: ec3473f1, if non-zero, the address which referenced memory. 22 Arg4: 00000000, (reserved) Special pool made an elusive bug into one that instantly reveals itself and makes the analysis trivial. 有空翻译下,郁闷遇到这个错误,不过貌似找到地方了,不严格的判断后CopyMemory

广告赞助商