Data abort Locating Method

Source: Internet
Author: User

Data abort Locating Method

Note: This method can only locate explicit leaks. The C statements that are located must have been leaked, but it may be a "Theoretically" code that won't go wrong. this is because other code leaks in the same process affect the heap or stack of the process (implicit leakage, the local side will not produce data abort exception ), then the identified code is passively exposed. generate data abort. at the end of this article, I will provide code examples to illustrate this situation.

-----------------------
First of all, we should know how to locate data abort in the debug version. I will not talk nonsense. Platformbuilder, vs2005, EVC, and other ide tools will automatically stop at the wrong sentence in debug mode, which is obvious.

The leakage in the release version is a little troublesome. How can we quickly locate it?

Case 1: leakage of applications compiled with EVC

First, I made a program for Memory leakage, walzer_leak.exe, which made a function for leakage.
Void doleak ()
{
Int * P = (int x) 0x81000000;
* P = 10;
}

During compilation, check "generate mapfile" on the Link Page of the Project settings to generate a map file. For example

Put the compiled release version executable file to run on the ce5 platform. When an error occurs, the serial port prints a sentence.

Data ABORT: thread = 83ad1d38 proc = 820266d0 'walzer_leak.exe'
Aky = 00000021 PC 000000011008(walzer_leak.exe + 0x00001008) ra000000011030(walzer_leak.exe + 0x00001030) BVA = 81000000 FSR = 0000000d

This sentence is automatically output by the system. We get a key message: PC pointer. The offset of the pc in walzer_leak.exe. Then open the walzer_leak.map file generated during compilation.
The file is not long. I will paste it.

**************************************** ********************
Walzer_leak

Timestamp is 46fcbb17 (Fri Sep 28 16:28:07 2007)

Preferred load address is 00010000

Start length name class
00000000000 00000258 H. Text code
000:00000000 00000014 H. xdata data
00000000014 00000014 H. idata $2 Data
00000000028 00000014 H. idata $3 data
0002: 0000003c 00000010 H. idata $4 Data
0002: 0000004c 0000000ch. idata $6 data
000:00000058 00000000 H. edata
0003:00000000 00000010 H. idata $5 Data
0003:00000010 00000004 H. CRT $ xca data
0003:00000014 00000004 H. CRT $ xcz data
0003:00000018 00000004 H. CRT $ Xia data
0003: 0000001c 00000004 H. CRT $ xiz data
0003:00000020 00000004 H. CRT $ xpa data
0003:00000024 00000004 H. CRT $ xpz data
0003:00000028 00000004 H. CRT $ xta data
0003: 0000002c 00000004 H. CRT $ xtz data
0003:00000030 00000009 H. BSS data
0004:00000000 00000038 H. pdata
0005:00000000 00000010 H. rsrc $01 data
0005:00000010 00000000 H. rsrc $02 data

Address publics by value RVA + base Lib: Object

0001:00000000? Doleak @ yaxxz 00011000 F walzer_leak.obj
0001:00000010 winmain 00011010 F walzer_leak.obj
0001: 0000002c winmaincrtstartup 0001102c F corelibc: pegwmain. OBJ
0001: 000000a0 _ cinit 000110a0 F corelibc: crt0dat. OBJ
000:00000210 exit 00011210 F corelibc: crt0dat. OBJ
000:00000228 _ xcptfilter 00011228 F coredll: coredll. dll
000:00000238 _ c_specific_handler 00011238 F coredll: coredll. dll
000000248 localfree 00011248 F coredll: coredll. dll
000:00000014 _ import_descriptor_coredll 00012014 coredll: coredll. dll
000:00000028 _ null_import_descriptor 00012028 coredll: coredll. dll
0003:00000000 _ imp ___ c_specific_handler 00013000 coredll: coredll. dll
0003:00000004 _ imp_localfree 00013004 coredll: coredll. dll
0003:00000008 _ imp _ xcptfilter 00013008 coredll: coredll. dll
0003: 0000000c/177coredll_null_thunk_data 0001300c coredll: coredll. dll
0003:00000010 _ xc_a 00013010 corelibc: crt0init. OBJ
0003100000014 _ xc_z 00013014 corelibc: crt0init. OBJ
0003:00000018 _ xi_a 00013018 corelibc: crt0init. OBJ
0003: 0000001c _ xi_z 0001301c corelibc: crt0init. OBJ
0003:00000020 _ xp_a 00013020 corelibc: crt0init. OBJ
0003:00000024 _ xp_z 00013024 corelibc: crt0init. OBJ
0003:00000028 _ xt_a 00013028 corelibc: crt0init. OBJ
0003: 0000002c _ xt_z 0001302c corelibc: crt0init. OBJ
0003:00000030 _ onexitend 00013030 <Common>
0003:00000034 _ onexitbegin 00013034 <Common>
0003:00000038 _ exitflag 00013038 <Common>

Entry point at 0001: 0000002c

Static symbols

0001: 0000010c doexit 0001110c F corelibc: crt0dat. OBJ
**************************************** ********************

OK. First, there is a "preferred load address is 00010000", which means that the pc000000011008(walzer_leak.exe + 0x00001008) of the data abort, which must be

0x11008 is obtained by adding the offset of the load address to 0x1008 (note that the PC cannot be used directly, and you will know the case later ), then, let's look at the RVA + base in the function offset list.

In this column, 0x11008 is found in the address range of the doleak function, so the doleak function is leaked.

Case 2: A leaked function is implemented on the oal layer. The releaseversion is translated using platform builderand linked to nk.exe. then the application call_leak.exe calls this function, causing leakage.

The procedure is similar, but platform builder generates a. map file in the release directory by default. When the application calls the leaked oal function

Data ABORT: thread = 822fc000 proc = 820267c0 'call_leak.exe'
Aky = 00000041 Pc = 8023e3c8 (NK. EXE + 0x0003e3c8) Ra = 8023e1d4 (NK. EXE + 0x0003e1d4)
BVA = 8e000000 fsrs = 00000005

Note that this is a leakage in NK. EXE, so the PC pointer is not in the slot 0 low address such as 0x00011008, but in the kernel area above 0x80000000.
NK. map is very long. I chose key paragraphs for posting.

**************************************** ********************
Kern

Timestamp is 46fca696 (Fri Sep 28 15:00:38 2007)

Preferred load address is 00010000

...
0001: 0003d2c8 oalioctlhal_getdeviceid 0004e2c8 F oal_ioctl: DeviceID. OBJ
0001: 0003d398 oalioctlhal_doleak 0004e398 F oal_ioctl: leaktest. OBJ
0001: 0003d438 oalioctlhal_ddkcall 0004e438 F oal_io: IOCTL. OBJ
...
**************************************** ********************

So NK. EXE + 0x0003e3c8 = 0x10000 (preferred load address) + 0x0003e3c8 = 0x4e3c8, which falls into the oalioctlhal_doleak Function

Conclusion: In principle, it is very simple to use the Pc value in the Data abort message and use the map file to quickly locate the leaked function. After locating, hey, who is the leak and who is the guest.

-------------------------------
Supplement:

Using the above method, not only did the netizen Kevin fail to identify the cause of the leak (see the reply below, and he located the MDD layer code of Microsoft usbfn ), I have not caught the cause in this project team (locate the loadlibrary function-related code in private ). I thought about it last night. This method does have a vulnerability. In the morning, I did a test and set up a dialogbox. The number of main processing functions is as follows:

Static DWORD * g_ptest = NULL;

Int callback leakproc (hwnd hdlg, uint umsg, wparam, lparam)
{
Switch (umsg)
{
Case wm_initdialog:
G_ptest = (DWORD *) malloc (1 );
Break;
Case wm_command:
Switch (wparam)
{
Case id_leak:
* (Int *) 0x1a013860) = 0x1c000000;
Break;
Case id_close:
If (g_ptest)
{
* G_ptest = 1;
}
Enddialog (hdlg, 0 );
Break;
}
Break;
}
Return false;
}

I run it several times. The baseaddr of the process is 0x1a000000 each time, and the & g_ptest = 0x1a013860 is in the global variable area of the process. After malloc, g_ptest = 0x00030230 is in the heap area of the process. So I
(1) After pressing the id_leak button, simulate a memory leak and directly rewrite the value on the & g_ptest address, and change 0x00030230 after malloc to 0x00000000, note that although the data has been leaked, no data abort exception is generated.
(2) After the id_close button is pressed, the loader does not know the previous leak. The Code style strictly determines whether the pointer is null, then I tried to write a value on the address 0x00030230 In the heap zone obtained by malloc. However, the pointer g_ptest has been rewritten to point to other process spaces, therefore, the * g_ptest = 1 Clause generates a data abort exception and stops.
(3) Therefore, according to the above method, only the * g_ptest = 1 sentence can be caught, but in fact this sentence is innocent, the real culprit * (int *) 0x1a013860) = 0x1c000000 is not caught.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.