A memory defect location method based on extended address identification

By expanding address identification information and constructing auxiliary tags during the memory allocation process, combined with Hook functions and binary code decompilation analysis, the problem of locating memory defects in the Windows kernel is solved, achieving precise location of memory defects and improving system stability.

CN118585456BActive Publication Date: 2024-10-25北京麟卓信息科技有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411052585.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-08-02
Publication Date
2024-10-25
Estimated Expiration
2044-08-02

AI Technical Summary

Technical Problem

It is difficult to pinpoint memory defects in the Windows kernel with existing technology, especially in virtual memory implementation errors, memory corruption in the physical address extension kernel, and memory leaks in specific services, leading to system instability and performance degradation.

Method used

By expanding the address identification information during the memory allocation process, including source code file names, function names and code line instruction addresses, dynamically constructing auxiliary labels and memory space attributes, combined with Hook functions and binary code decompilation analysis, precise location of memory defects is achieved.

Benefits of technology

Effectively supports error memory traceability of the system under test, improves memory defect location accuracy and debugging efficiency, and reduces the complexity of system fault recovery.

✦ Generated by Eureka AI based on patent content.
Patent Text Reader

Abstract

The invention discloses a memory defect positioning method based on extended address identification. According to whether the source code can be obtained, the kernel module is divided into two cases, namely, a case with source code and a case without source code. For the case with source code, the source code file name, function name and other positioning information of the main calling function are extended and added in the process of memory allocation by redefining the standard memory allocation function. For the case without source code, the kernel module address, the memory allocation instruction address and the memory address for changing the memory space attribute are obtained by constructing a Hook function for the relevant function. According to the subordinate relationship between the memory allocation instruction address and the kernel module address and the memory address for changing the memory space attribute, the corresponding positioning information is extended and added in the process of memory allocation. When an exception occurs in the system to be tested, the positioning information is extracted according to the abnormal instruction address to realize the accurate positioning of the memory defect, thereby providing effective support for the tracing of the error memory of the system to be tested.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the technical field of computer software development, and in particular relates to a memory defect locating method based on extended address identification. Background Art

[0002] Kernel memory bugs are errors related to memory allocation, usage, and management that can lead to system instability, performance degradation, or data loss. Windows kernel memory bugs primarily involve virtual memory implementation errors, memory corruption issues in the physical address extension kernel, and memory leaks in specific services or features.

[0003] A bug in the implementation of virtual memory means that, in certain circumstances, such as when running an application that references kernel virtual memory, you may experience graphics corruption issues. This is because of a bug in the kernel virtual memory implementation. Memory corruption in the physical address extension kernel: In Microsoft Windows Server 2003, any user-mode process or kernel-mode component that connects to a driver that runs in the physical address extension kernel may experience memory corruption. This may cause the computer to stop responding unpredictably. Memory leaks in specific services or features: For example, the PPTP service in Windows NT 4.0 has a bug in the code that handles a specific type of packet, which causes a kernel memory leak. If an affected server receives a sufficient number of packets that contain a specific format, kernel memory will eventually be exhausted, which may cause the server to completely hang or fail. These bugs may be resolved by obtaining the latest service pack, or in certain circumstances, you may need to restart the computer to resume normal operation.

[0004] To assist in locating the above problem, the Windows kernel introduces functions such as ExAllocatePoolWithTag. These functions can add tags to each allocated memory pool. When analyzing the dump file generated by the system failure, these tags can be used to roughly analyze which kernel module the problematic memory belongs to. However, the specific location cannot be located, which increases the difficulty of subsequent debugging and problem solving. Summary of the invention

[0005] In view of this, the present invention provides a memory defect locating method based on extended address identification, which realizes dynamic pre-production of locating information and dynamic and accurate locating of memory defects based on the locating information.

[0006] The present invention provides a memory defect location method based on extended address identification, which specifically includes the following steps:

[0007] In the case of source code, when the system under test executes memory allocation, the function that calls the first memory allocation function is recorded as the first main calling function, and the source code file name, function name, source code line number and code line instruction address of the first main calling function are obtained. The first address information is composed of the first address information size, the source code file name, function name, source code line number and code line instruction address, wherein the value of the first address information size is the sum of the length of the source code file name, function name and code line instruction address and the prefabricated fixed space;

[0008] The memory space allocated by the first memory allocation function is the first memory space with the auxiliary tag, the size of the first memory space is the size of the first memory space, the value of the size of the first memory space is the sum of the memory space allocated by the standard memory allocation function, the length of the auxiliary tag, the length of the address information type and the length of the first address information, and the address information type is the source code address type; the address range of the memory space allocated by the first memory allocation function takes the allocation address of the standard memory allocation function as the starting point and the size of the first memory space as the offset;

[0009] In the case of no source code, when the system to be tested is running, the base address of the kernel module is added to the kernel module list, and the base address and address range size of the memory page that is modified to contain the memory space of the executable protection type are added to the executable memory space list; when executing memory allocation, the function that calls the second memory allocation function is recorded as the second main calling function, the instruction address of the second main calling function entry is recorded as the second main calling instruction address, and the instruction address of the memory allocation is recorded as the second memory allocation instruction address;

[0010] When the second memory allocation instruction address is located in the kernel module list, its offset relative to the base address of the kernel module to which it belongs is calculated and recorded as the second offset, and the second memory allocation instruction address information size, address information type, main call address information type, second offset and kernel module name are used as the second memory allocation instruction address information, the address information type is a sourceless address type, and the main call address information type is a kernel module address type; the memory space allocated by the second memory allocation function is a second memory space with an auxiliary label, and its size is the size of the second memory space, and the value of the second memory space size is the sum of the memory space allocated by the standard memory allocation function, the length of the auxiliary label, the length of the address information type, the length of the main call address information type and the length of the second memory allocation instruction address information; the address range of the memory space allocated by the second memory allocation function takes the allocation address of the standard memory allocation function as the starting point and the size of the second memory space as the offset;

[0011] When the second memory allocation instruction address is located in the executable memory space list, the offset of the second memory allocation instruction address relative to the base address of the memory page to which it belongs is recorded as the second dynamic offset, and the second dynamic address information size, the address information type, the main call address information type, the second dynamic offset and the second main call instruction address are used as the second dynamic address information, the address information type is a sourceless address type, and the main call address information type is a dynamic code address type; the value of the second memory space size is the sum of the memory space allocated by the standard memory allocation function, the length of the auxiliary label, the length of the address information type, the length of the main call address information type and the length of the second dynamic address information; the address range of the memory space allocated by the second memory allocation function takes the allocation address of the standard memory allocation function as the starting point and the second memory space size as the offset;

[0012] When the system under test executes memory release, the standard tag and the auxiliary tag are obtained to determine that the memory space is an allocated memory space, the memory space to be released is calculated according to the size of the corresponding first memory space or second memory space, and the release operation is performed on the memory space;

[0013] When an exception occurs in the system to be tested, the exception instruction address is obtained, the exception instruction address in the dump file is searched, and the address information type is read when the auxiliary label is read forward after the standard label. When the address information type is a source code address type, the source code is loaded according to the source code file name in the first address information. If the loading is successful, jump to the corresponding position, otherwise output the source code file name, function name, source code line number and code line instruction address; when the address information type is a non-source code address type, the information is read according to the second memory allocation instruction address information size in the second memory allocation instruction address information, and the second memory allocation instruction address information is obtained. If the main call address information type is a kernel module address type, the second offset and the kernel module name are output. If the main call address information type is a dynamic code address type, the second dynamic offset, the second memory allocation instruction address and the second main call instruction address are output.

[0014] Furthermore, the source code file name and the function name are stored in a static array, and the first address information stores the index of the source code file name and the function name in the static array.

[0015] Furthermore, the length of the auxiliary tag is 16 bytes, and the data type of the address information type is a 32-bit integer.

[0016] Furthermore, the prefabricated fixed space is the memory space occupied by the first address information size and the source code line number.

[0017] Furthermore, the prefabricated fixed space is 8 bytes.

[0018] Furthermore, the size of the second memory allocation instruction address information is a 32-bit integer, and the size of the second dynamic address information is a 32-bit integer.

[0019] Furthermore, according to the second offset and the kernel module name, a binary code decompilation analysis engine is used to reverse the binary code to display the code of the abnormal memory allocation function. Beneficial Effects

[0020] The present invention divides kernel modules into two cases, one with source code and the other without source code, according to whether source code can be obtained. For the case with source code, the source code file name, function name and other positioning information of the main calling function are extended and added in the process of memory allocation by redefining the standard memory allocation function. For the case without source code, the kernel module address, the memory allocation instruction address and the memory address for changing the attribute of the memory space are obtained by constructing a Hook function for the relevant function. During the process of memory allocation, the corresponding positioning information is extended and added according to the subordinate relationship between the memory allocation instruction address and the kernel module address and the memory address for changing the attribute of the memory space. When an exception occurs in the system to be tested, the positioning information is extracted according to the abnormal instruction address to realize the accurate positioning of the memory defect, thereby providing effective support for the tracing of the error memory of the system to be tested. DETAILED DESCRIPTION

[0021] The present invention is described in detail with reference to the following embodiments.

[0022] The present invention provides a memory defect location method based on extended address identification, and its core idea is: according to whether the source code can be obtained, the kernel module is divided into two cases: with source code and without source code. For the case with source code, the source code file name, function name and other location information of the main calling function are expanded and added during the memory allocation process by redefining the standard memory allocation function. For the case without source code, the kernel module address, memory allocation instruction address and memory address that changes the memory space attribute are obtained by constructing a Hook function for the relevant function. During the memory allocation process, the corresponding location information is expanded and added according to the subordinate relationship between the memory allocation instruction address and the kernel module address and the memory address that changes the memory space attribute. When an exception occurs in the system to be tested, the location information is extracted according to the abnormal instruction address to realize the precise location of the memory defect.

[0023] The present invention provides a memory defect location method based on extended address identification, which specifically includes the following steps:

[0024] For the kernel module whose source code can be obtained, the standard memory allocation function is modified into the first memory allocation function, and the standard memory release function is modified into the first memory release function. Wherein, the standard memory allocation function and the standard memory release function are both existing functions of the kernel module.

[0025] The present invention realizes the redefinition of functions by modifying the header file, and then compiling and executing it, and the system to be tested can adopt the function constructed by the present invention to replace the corresponding standard function.

[0026] When the system under test executes memory allocation, the function that calls the first memory allocation function is recorded as the first main calling function, and the source code file name, function name, source code line number and code line instruction address of the first main calling function are obtained. The first address information is composed of the first address information size, the source code file name, function name, source code line number and code line instruction address, wherein the value of the first address information size changes dynamically, specifically the sum of the length of the source code file name, function name and code line instruction address and the prefabricated fixed space, the prefabricated fixed space is the memory space occupied by the first address information size and the source code line number, generally 8 bytes, and the first address information size and the source code line number are 4 bytes each;

[0027] The memory space allocated by the first memory allocation function has a specific label recorded as an auxiliary label. The memory space allocated by the first memory allocation function is the first memory space, and its size is recorded as the first memory space size. The value of the first memory space size is the sum of the memory space allocated by the standard memory allocation function, the length of the auxiliary label, the length of the address information type and the length of the first address information. The address information type is a source code address type. The address range of the memory space allocated by the first memory allocation function starts with the allocation address of the standard memory allocation function and uses the first memory space size as an offset.

[0028] The memory space allocated by the standard memory allocation function is the sum of the memory space requested by the first calling function and the length of the standard tag. The length of the auxiliary tag is 16 bytes. The data type of the address information type is a 32-bit integer, including two types: source code address type and non-source code address type.

[0029] In order to further reduce the space occupied by information and improve the efficiency of memory space use, the present invention can save the source code file name and the function name therein in a static array, and the first address information only saves the index of the source code file name and the function name in the static array.

[0030] When the system under test executes memory release, the first memory release function obtains the standard tag and the auxiliary tag to determine that the memory space is the memory space allocated by the present invention, calculates the memory space to be released according to the size of the first memory space, and performs a release operation on the memory space.

[0031] For kernel modules whose source code cannot be obtained, a Hook function is established in the system to be tested for the standard memory allocation function to implement the use of the second memory allocation function to allocate memory space, a Hook function is established for the standard memory release function to implement the use of the second memory release function to release memory space, and a Hook function is established for the function that sets the memory address range protection type to obtain the properties of the memory space.

[0032] When the system under test is running, the base address and module size of the kernel module are recorded and added to the kernel module list; the memory space whose protection type is modified is monitored, and the base address and address range size of the memory page modified to contain the memory space of the executable protection type are added to the executable memory space list;

[0033] When the system under test executes memory allocation, the function that calls the second memory allocation function is recorded as the second main calling function, the instruction address for obtaining the entry of the second main calling function is recorded as the second main calling instruction address, and the instruction address for obtaining the memory allocation is recorded as the second memory allocation instruction address;

[0034] When the second memory allocation instruction address is located within the address range of a kernel module in the kernel module list, the offset of the second memory allocation instruction address relative to the base address of the kernel module to which it belongs is calculated and recorded as the second offset, and the second memory allocation instruction address information size, address information type, main call address information type, second offset and kernel module name are used as the second memory allocation instruction address information, the address information type is a sourceless address type, and the main call address information type is a kernel module address type, wherein the second memory allocation instruction address information size is a 32-bit integer, and its value is the size of the memory space occupied by the second memory allocation instruction address information; the memory space allocated by the second memory allocation function has a specific label recorded as an auxiliary label, and the size of the memory space allocated by the second memory allocation function is recorded as the second memory space size, and the value of the second memory space size is the sum of the memory space allocated by the standard memory allocation function, the length of the auxiliary label, the length of the address information type, the length of the main call address information type and the length of the second memory allocation instruction address information; the address range of the memory space allocated by the second memory allocation function takes the allocation address of the standard memory allocation function as the starting point and the second memory space size as the offset;

[0035] When the second memory allocation instruction address is located in the executable memory space list, it means that the second memory allocation function is located in a dynamically allocated memory page with executable attributes. The offset of the second memory allocation instruction address relative to the base address of the memory page to which it belongs is calculated and recorded as the second dynamic offset. The second dynamic address information size, the address information type, the main call address information type, the second dynamic offset and the second main call instruction address are used as the second dynamic address information. The address information type is a sourceless address type, and the main call address information type is a dynamic code address type. The second dynamic address information size is a 32-bit integer, and its value is the size of the memory space occupied by the second dynamic address information. The memory space allocated by the second memory allocation function has a specific label recorded as an auxiliary label. The size of the memory space allocated by the second memory allocation function is recorded as the second memory space size. The value of the second memory space size is the sum of the memory space allocated by the standard memory allocation function, the length of the auxiliary label, the length of the address information type, the length of the main call address information type and the length of the second dynamic address information. The address range of the memory space allocated by the second memory allocation function starts with the allocation address of the standard memory allocation function and takes the second memory space size as the offset.

[0036] The main call address information type includes a kernel module address type and a dynamic code address type.

[0037] When the system under test executes memory release, the second memory release function obtains the standard tag and the auxiliary tag to determine that the memory space is the memory space allocated by the present invention, calculates the memory space to be released according to the size of the second memory space, and performs a release operation on the memory space.

[0038] When an exception occurs in the system to be tested, the exception instruction address is obtained, the exception instruction address in the dump file generated by the system to be tested is searched, the standard label is read and then the information is read forward, and the address information type is read when the auxiliary label is read. For information whose address information type is a source code address type, the source code is loaded according to the source code file name in the first address information. If the loading is successful, the corresponding position is jumped to according to the function name and source code line number in the first address information, otherwise the source code file name, function name, source code line number and code line instruction address in the first address information are output; for information whose address information type is a non-source code address type, according to the size of the second memory allocation instruction address information in the second memory allocation instruction address information, the information in the memory space of the same size is read to obtain the second memory allocation instruction address information, if the main calling address information type in the second memory allocation instruction address information is a kernel module address type, the second offset and the kernel module name are output, and if the main calling address information type is a dynamic code address type, the second dynamic offset, the second memory allocation instruction address and the second main calling instruction address are output.

[0039] In the present invention, based on the output second calling instruction address, backtracking from dynamically generated code to static code can be achieved, providing a basis for locating memory defects in dynamic code.

[0040] Furthermore, according to the second offset and the kernel module name, a binary code decompilation analysis engine may be used to reverse the binary code to display the relevant code of the abnormal memory allocation function. Example

[0041] In this embodiment, a memory defect location method based on extended address identification provided by the present invention is adopted to realize the location of memory defects in the Windows system, which specifically includes:

[0042] S1. For the system under test with source code, perform the following steps:

[0043] S1.1. Redefine each standard memory allocation function of the kernel, such as ExAllocatePool, ExAllocatePool2, ExAllocatePool3, etc., by using C / C++ macros, so as to replace the calls to these functions with the calls to the MyExAllocatePoolXXX and other functions defined in the present invention; redefine the standard memory release functions of the kernel, such as ExFreePool, ExFreePool2, etc., so as to replace the calls to these functions with the calls to the MyExFreePoolXXX and other functions defined in the present invention.

[0044] S1.2, MyExAllocatePoolXXX includes the following steps:

[0045] S1.2.1, MyExAllocatePoolXXX adds four parameters in addition to the parameters of the corresponding standard memory allocation function, including: source code file name __FILE__, function name __FUNCTION__, source code line number __LINE__ and current code line instruction address ReturnAddress, that is, the statement used when calling MyExAllocatePoolXXX should be:

[0046] MyExAllocatePoolXXX(XX, XX, __FILE__, __FUNCTION__, __LINE__, _ReturnAddress());

[0047] Among them, _ReturnAddress() is an extended inline function of Visual C++, which returns the return address when the function is called, that is, the instruction address of the code line that calls MyExAllocatePoolXXX.

[0048] S1.2.2. Generate a 16-byte UUID as an auxiliary tag, denoted as uuidTag.

[0049] S1.2.3. Call ExAllocatePool to allocate an additional memory space outside the standard tag. This memory space is used to save the source code related information of calling MyExAllocatePoolXXX, that is, the first address information, recorded as pdbAddressInfo. The actual memory space size required to allocate MyExAllocatePoolXXX is calculated and recorded as bytesToAllocate, bytesToAllocate = the memory space size requested when calling the standard memory allocation function + sizeof (standard tag) + sizeof (uuidTag) + sizeof (address information type) + sizeof (pdbAddressInfo).

[0050] The information saved in pdbAddressInfo includes: pdbAddressInfo size, source code file name, function name, source code line number, and code line instruction address. Among them, the pdbAddressInfo size is the number of bytes occupied by pdbAddressInfo, and its value changes dynamically, which is equal to sizeof (int32) + source code file name length + function name length + sizeof (int32) + sizeof (code line instruction address), and sizeof (code line instruction address) is 64 bits.

[0051] S1.2.4. Return the address range of the allocated memory space, specifically: the address returned by the standard memory allocation function + sizeof (standard tag) + sizeof (uuidTag) + sizeof (address information type) + sizeof (pdbAddressInfo).

[0052] S1.3, MyExFreePoolWithTag includes the following steps:

[0053] In addition to displaying the standard tag forward, forward judgment is performed. When the information is uuidTag, the address information type is read forward, and then the actual address information data structure length is calculated according to the address information type. Finally, the base address of the memory that should be released is calculated to determine the memory space, and the standard release operation is performed on the memory space.

[0054] S2. For drivers without source code, perform the following steps:

[0055] S2.1. Monitor the loading process of kernel modules in the system under test and record the base address and module size of each kernel module:

[0056] S2.1.1. Call the Windows kernel interface PsSetLoadImageNotifyRoutine to register a callback function. When the kernel module (including the driver) is loaded, the callback function is called. Based on this mechanism, the monitoring of the kernel module loading is realized.

[0057] S2.1.2, Assume that the registered callback function is LoadImageNotifyRoutine, and implement the analysis and reconstruction of the information related to the loaded kernel module in this function. The specific steps are as follows:

[0058] LoadImageNotifyRoutine(

[0059] _In_opt_ PUNICODE_STRING FullImageName,

[0060] _In_ HANDLE ProcessId,

[0061] _In_ IMAGE_INFO ImageInfo )

[0063] The definition of IMAGE_INFO is as follows:

[0064] typedef struct _IMAGE_INFO {

[0065] union {

[0066] ULONG Properties;

[0067] struct {

[0068] ULONGImageAddressingMode: 8;

[0069] ULONG SystemModeImage : 1;

[0070] ULONGImageMappedToAllPids : 1;

[0071] ULONGExtendedInfoPresent: 1;

[0072] ULONG MachineTypeMismatch: 1;

[0073] ULONGImageSignatureLevel: 4;

[0074] ULONG ImageSignatureType : 3;

[0075] ULONG ImagePartialMap : 1;

[0076] ULONG Reserved: 12;

[0077] };

[0078] };

[0079] PVOID ImageBase;

[0080] ULONG ImageSelector;

[0081] SIZE_T ImageSize;

[0082] ULONG ImageSectionNumber;

[0083] } IMAGE_INFO, *PIMAGE_INFO;

[0084] Build the memory layout information of each module of the Windows kernel based on the ImageBase, ImageSize and other information in IMAGE_INFO, that is, the base address and module size of each module;

[0085] Get the full path of the system file represented by FullImageName;

[0086] Add the above information to the list listKernelDriverImageInfo.

[0087] S2.2. A corresponding Hook function is constructed for each standard memory allocation function to redirect the standard memory allocation function to the customized MyExAllocatePoolXXX of the present invention; a corresponding Hook function is constructed for each standard memory release function to redirect all standard memory release functions to the customized MyExFreePoolXXX.

[0088] S2.3. When the system creates dynamic code, the initial state of the memory page that needs to be dynamically allocated is usually non-executable. Therefore, when creating dynamic code, the attributes of the corresponding memory page need to be set to include executable attributes. Track the allocation and release of memory pages marked as executable attributes, as follows:

[0089] S2.3.1. Build a Hook function for MmProtectMdlSystemAddress, obtain the kernel address to be modified according to the first parameter of MmProtectMdlSystemAddress, and obtain the memory attribute to be modified according to its second parameter;

[0090] S2.3.2. If the attribute to be modified is to add the executable attribute, the base address and length of the kernel address range processed by MmProtectMdlSystemAddress are added to listExecutableMemRange.

[0091] S2.4, MyExAllocatePoolXXX includes the following steps:

[0092] S2.4.1. In addition to the standard label, additional memory space is allocated. The instruction address of the instruction that calls the memory allocation function is obtained by backtracing the call stack. The instruction address is recorded as callerInstrAddress. The return address can be obtained by inline assembly, such as mov eax, [rbp+8].

[0093] When the dynamically generated code at runtime calls the memory allocation function established by the present invention, the instruction address of the dynamically generated code cannot be traced back to a memory address corresponding to the binary code. Therefore, the present invention determines the specific location by tracing back to the static code before the dynamically generated code. If the instruction address is within the address range corresponding to the kernel module, it means that the code corresponding to the instruction address is not dynamically generated. On the contrary, if the instruction address is within the listExecutableMemRange, it means that the code corresponding to the instruction address is dynamically generated.

[0094] S2.4.2. According to listKernelDriverImageInfo, when the instruction address is within the image address range of a kernel module in listKernelDriverImageInfo, the offset of callerInstrAddress relative to the kernel module base address is calculated and recorded as callerInstrAddressOffset. The codeAddressInfo size, address information type, main call address information type, callerInstrAddressOffset and kernel module name are saved in codeAddressInfo.

[0095] Among them, the address information type is a non-source code address type, and the main call address information type is a kernel module address type.

[0096] S2.4.3. According to listExecutableMemRange, when the instruction address is located in a dynamically allocated executable memory page codePage recorded in listExecutableMemRange, codeAddressInfo stores the codeAddressInfo size, address information type, caller address information type, the offset of the instruction address relative to the base address of codePage callerInstrAddressOffset, and the address information of the code that allocated codePage previously saved in codePage.

[0097] Among them, the address information type is a non-source code address type, and the main call address information type is a dynamic code address type.

[0098] S2.4.4. Determine the size of the allocated memory space as the size requested when the API is called + sizeof(standard tag) + sizeof(uuidTag) + sizeof(address information type) + sizeof(caller address information type) + sizeof(codeAddressInfo).

[0099] S2.4.5. Determine that the returned address is the address returned by the standard memory allocation function + sizeof (standard tag) + sizeof (uuidTag) + sizeof (address information type) + sizeof (caller address information type) + sizeof (codeAddressInfo).

[0100] S2.4.6. In addition to displaying the standard tag forward, perform forward judgment. When the information is uuidTag, read the address information type forward, calculate the actual address information data structure length according to the address information type, and finally calculate the base address of the memory that should be released to determine the memory space, and perform the standard release operation on the memory space.

[0101] S3. When analyzing the dump file with the extended WinDBG plug-in, such as !analyze -v, the following steps are performed for the memory addresses involved in the abnormal instructions:

[0102] S3.1, read the standard tag, then read the memory of the UUID length forward, if the read value is uuidTag, then read the address information type forward;

[0103] If the address information type is a source code address type, the pdbAddressInfo file information is read and parsed, and then the corresponding source code is tried to be loaded. If the source code is loaded successfully, the corresponding source code line number is jumped to according to the source code information in pdbAddressInfo; otherwise, the information saved in pdbAddressInfo is displayed, such as the source code file name, source code line number, etc.

[0104] If the address information type is a non-source code address type, first read the first member variable of codeAddressInfo, obtain the size of codeAddressInfo, read the memory data of the size of codeAddressInfo forward, obtain the type of codeAddressInfo, and execute:

[0105] If the caller address information type of codeAddressInfo is the kernel module address type, callerInstrAddressOffset and the kernel module name are returned;

[0106] If the calling address information type of codeAddressInfo is a dynamic code address type, the offset callerInstrAddressOffset of the instruction address relative to the base address of codePage and the instruction address information of the code that allocates codePage are displayed, wherein the instruction address information of the code that allocates codePage includes callerInstrAddressOffset and the kernel module name.

[0107] Furthermore, based on callerInstrAddressOffset and the driver name, the binary code decompilation analysis engine can be called to perform reverse engineering to display the function where the code that allocates the problematic memory is located.

[0108] In summary, the above are only preferred embodiments of the present invention and are not intended to limit the protection scope of the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the protection scope of the present invention.

Claims

1. A memory defect location method based on extended address identification, characterized in that: The specific steps include: In the case of source code, when the system under test executes memory allocation, the function that calls the first memory allocation function is recorded as the first main calling function, and the source code file name, function name, source code line number and code line instruction address of the first main calling function are obtained. The first address information is composed of the first address information size, the source code file name, function name, source code line number and code line instruction address, wherein the value of the first address information size is the sum of the length of the source code file name, function name and code line instruction address and the prefabricated fixed space; The memory space allocated by the first memory allocation function is the first memory space with the auxiliary tag, the size of the first memory space is the size of the first memory space, the value of the size of the first memory space is the sum of the memory space allocated by the standard memory allocation function, the length of the auxiliary tag, the length of the address information type and the length of the first address information, and the address information type is the source code address type; the address range of the memory space allocated by the first memory allocation function takes the allocation address of the standard memory allocation function as the starting point and the size of the first memory space as the offset; In the case of no source code, when the system to be tested is running, the base address of the kernel module is added to the kernel module list, and the base address and address range size of the memory page that is modified to contain the memory space of the executable protection type are added to the executable memory space list; when executing memory allocation, the function that calls the second memory allocation function is recorded as the second main calling function, the instruction address of the second main calling function entry is recorded as the second main calling instruction address, and the instruction address of the memory allocation is recorded as the second memory allocation instruction address; When the second memory allocation instruction address is located in the kernel module list, its offset relative to the base address of the kernel module to which it belongs is calculated and recorded as the second offset, and the second memory allocation instruction address information size, address information type, main call address information type, second offset and kernel module name are used as the second memory allocation instruction address information, the address information type is a sourceless address type, and the main call address information type is a kernel module address type; the memory space allocated by the second memory allocation function is a second memory space with an auxiliary label, and its size is the size of the second memory space, and the value of the second memory space size is the sum of the memory space allocated by the standard memory allocation function, the length of the auxiliary label, the length of the address information type, the length of the main call address information type and the length of the second memory allocation instruction address information; the address range of the memory space allocated by the second memory allocation function takes the allocation address of the standard memory allocation function as the starting point and the size of the second memory space as the offset; When the second memory allocation instruction address is located in the executable memory space list, the offset of the second memory allocation instruction address relative to the base address of the memory page to which it belongs is recorded as the second dynamic offset, and the second dynamic address information size, the address information type, the main call address information type, the second dynamic offset and the second main call instruction address are used as the second dynamic address information, the address information type is a sourceless address type, and the main call address information type is a dynamic code address type; the value of the second memory space size is the sum of the memory space allocated by the standard memory allocation function, the length of the auxiliary label, the length of the address information type, the length of the main call address information type and the length of the second dynamic address information; the address range of the memory space allocated by the second memory allocation function takes the allocation address of the standard memory allocation function as the starting point and the second memory space size as the offset; When the system under test executes memory release, the standard tag and the auxiliary tag are obtained to determine that the memory space is an allocated memory space, the memory space to be released is calculated according to the size of the corresponding first memory space or second memory space, and the release operation is performed on the memory space; When an exception occurs in the system to be tested, the exception instruction address is obtained, the exception instruction address in the dump file is searched, and the address information type is read when the auxiliary label is read forward after the standard label. When the address information type is a source code address type, the source code is loaded according to the source code file name in the first address information. If the loading is successful, jump to the corresponding position, otherwise output the source code file name, function name, source code line number and code line instruction address; when the address information type is a non-source code address type, the information is read according to the second memory allocation instruction address information size in the second memory allocation instruction address information, and the second memory allocation instruction address information is obtained. If the main call address information type is a kernel module address type, the second offset and the kernel module name are output. If the main call address information type is a dynamic code address type, the second dynamic offset, the second memory allocation instruction address and the second main call instruction address are output.

2. The memory defect location method according to claim 1, characterized in that: The source code file name and the function name are stored in a static array, and the first address information stores the index of the source code file name and the function name in the static array.

3. The memory defect location method according to claim 1, characterized in that: The length of the auxiliary tag is 16 bytes, and the data type of the address information type is a 32-bit integer.

4. The memory defect location method according to claim 1, characterized in that: The prefabricated fixed space is the memory space occupied by the size of the first address information and the source code line number.

5. The memory defect location method according to claim 4, characterized in that: The prefabricated fixed space is 8 bytes.

6. The memory defect location method according to claim 1, characterized in that: The size of the second memory allocation instruction address information is a 32-bit integer, and the size of the second dynamic address information is a 32-bit integer.

7. The memory defect location method according to claim 1, characterized in that: According to the second offset and the kernel module name, the binary code is reversed using a binary code decompilation analysis engine to display the code of the abnormal memory allocation function.