Method and apparatus for managing dynamic memory, computer-readable storage medium
Patent Information
- Application Number
- KR1020210185640
- Authority / Receiving Office
- KR · KR
- Patent Type
- Patents
- Current Assignee / Owner
- Filing Date
- 2021-12-23
- Publication Date
- 2026-09-18
- Estimated Expiration
- 2041-12-23
Smart Images

Figure 112021149071964-PAT00001_ABST
Abstract
Description
Technology Field
[0001] The present invention relates to a dynamic memory management method and apparatus for dynamic memory management. Background Technology
[0002] Generally, memory management is one of the critical factors regarding the performance of embedded systems with built-in microprocessors. To enable various applications to run within the microprocessor, it performs the operations of allocating and deallocating memory space within the system for each program. Memory allocation operations are primarily classified into static memory allocation and dynamic memory allocation.
[0003] Static memory allocation is a method of allocating memory with a fixed size in advance. In such cases, memory must be allocated at a size larger than the maximum amount of memory used, resulting in wasted memory usage within the system. Consequently, dynamic memory allocation for applications is required in embedded systems that use memory of a limited size.
[0004] Meanwhile, it is known that most attacks on computing systems exploit memory vulnerabilities such as Buffer Overflow (BOF) and Use After Free (UAF). A representative attack among these is Control Flow Hijacking. Control flow hijacking is an attack method that involves modifying function pointers or return addresses to generate unintended control flow and execute code desired by the attacker.
[0005] Conventional UAF vulnerability detection technologies include red zone insertion and coloring techniques. However, conventional UAF vulnerability detection technologies incur performance overhead due to an increase in instructions and memory overhead because large memory areas are allocated for vulnerability detection.
[0006] Furthermore, while various security mechanisms are provided to address security vulnerabilities, attackers are bypassing DFB detection to carry out attacks. The problem to be solved
[0007] The objective of the present invention is to provide a dynamic memory management method and apparatus for preventing performance overhead and memory overhead from occurring when detecting memory vulnerabilities.
[0008] In addition, the objective of the present invention is to provide a dynamic memory management method and apparatus for increasing the security strength of memory. means of solving the problem
[0009] A dynamic memory management method according to the present invention for achieving the above-mentioned purpose may include the steps of defining a shadow region mapped to a memory region, setting a coloring value in the shadow region, and allowing or blocking access to the memory region based on the coloring value when accessing the memory region.
[0010] In the step of allowing or blocking access to the memory area, when the free() function is executed and the freeing of the heap chunk in the memory area is completed, access to the data area of the freed heap chunk can be blocked based on the coloring value of the shadow area. Here, when the free() function is executed, the information of the freed heap chunk is stored in the memory management area (tcache_entry), and fd and bk are stored in the data area of the freed heap chunk, thereby completing the freeing of the heap chunk.
[0011] In the step of allowing or blocking access to the memory area, when the malloc() function is executed and allocation for a heap chunk in the memory area is requested, access to the data area of the allocated heap chunk can be allowed based on the coloring value of the shadow area.
[0012] The shadow area above can be physically separated from the memory area.
[0013] The above shadow area can allocate 1 byte of the 16 bytes of the memory area.
[0014] The access permission setting area of the above shadow area can be defined as 2 bits.
[0015] In addition, the dynamic memory management device of the embodiment may include a shadow area definition unit that defines a shadow area mapped to a memory area, a coloring value setting unit that sets a coloring value in the shadow area, and a memory access determination unit that allows or blocks access to the memory area based on the coloring value when accessing the memory area.
[0016] The memory access determination unit can block access to the data area of the released heap chunk based on the coloring value of the shadow area when the free() function is executed and the release of the heap chunk in the memory area is completed.
[0017] When the above memory access determination unit performs the above free() function, the freed heap chunk information is stored in the memory management area (tcache_entry), and fd and bk are stored in the data area of the above freed heap chunk, so that the freeing of the above heap chunk can be completed.
[0018] The memory access determination unit can allow access to the data area of the allocated heap chunk based on the coloring value of the shadow area when the malloc() function is executed and allocation for the heap chunk in the memory area is requested.
[0019] The shadow area above can be physically separated from the memory area.
[0020] The above shadow area can allocate 1 byte of the 16 bytes of the memory area.
[0021] The access permission setting area of the above shadow area can be defined as 2 bits.
[0022] Additionally, the embodiment is a computer-readable recording medium storing a computer program, wherein the computer program may include instructions for the processor to perform operations including the steps of defining a shadow area mapped to a memory area when executed by a processor, setting a coloring value in the shadow area, and allowing or blocking access to the memory area based on the coloring value when accessing the memory area. Effects of the invention
[0023] According to the present invention, by allocating dynamic memory and then releasing the allocated memory area, and subsequently blocking access to the data area of the released memory, attacks utilizing memory vulnerabilities of UAF and DFB can be effectively blocked.
[0024] In addition, the present invention enables safer dynamic memory management by blocking user access to a metadata area that allocates dynamic memory and manages a data area, and by allowing the size of an allocated heap chunk or the entire size of the heap chunk area to be changed only by a dynamic memory manager.
[0025] In addition, the present invention can increase security strength by defining a shadow region mapped to memory and determining whether to access memory through the shadow region. Brief explanation of the drawing
[0026] FIG. 1 is a flowchart illustrating a dynamic memory management method according to an embodiment of the present invention. FIG. 2 is a diagram showing a memory structure used for dynamic memory allocation and deallocation according to an embodiment of the present invention. FIG. 3 is a diagram showing an actual memory area where a heap chunk is allocated in memory according to an embodiment of the present invention. Figure 4 is a diagram showing the access rights values for the shadow area mapped to the memory area of Figure 3. Figure 5 is a diagram showing the definition of access rights according to the coloring value of the shadow area. FIG. 6 is a diagram showing an actual memory area where a heap chunk is allocated in memory according to another embodiment of the present invention. Figure 7 is a diagram showing the access rights values for the shadow area mapped to the memory area of Figure 6. FIG. 8 is a diagram showing an actual memory area in which a heap chunk is released in memory according to an embodiment of the present invention. Figure 9 is a diagram showing the access rights values for the shadow area mapped to the memory area of Figure 8. FIG. 10 is a diagram showing an actual memory area in which a heap chunk is released in memory according to another embodiment of the present invention. Figure 11 is a diagram showing the access rights values for the shadow area mapped to the memory area of Figure 10. Figure 12 is a diagram showing a memory area that frees the heap chunk after reallocating the heap chunk in memory. Figure 13 is a diagram showing the access rights values for the shadow area mapped to the memory area of Figure 12. FIG. 14 is a block diagram showing the configuration of a dynamic memory management device according to one embodiment of the present invention. FIG. 15 is a block diagram showing the configuration of a computer system according to one embodiment of the present invention. Specific details for implementing the invention
[0027] The advantages and features of the present invention and the methods for achieving them will become clear by referring to the embodiments described below in detail together with the accompanying drawings. However, the present invention is not limited to the embodiments disclosed below but may be implemented in various different forms. These embodiments are provided merely to ensure that the disclosure of the present invention is complete and to fully inform those skilled in the art of the scope of the invention, and the present invention is defined only by the scope of the claims. Throughout the specification, the same reference numerals refer to the same components.
[0028] Although terms such as "first" or "second" are used to describe various components, these components are not limited by such terms. Such terms may be used merely to distinguish one component from another. Accordingly, the first component mentioned below may be the second component within the technical scope of the present invention.
[0029] The terms used herein are for describing embodiments and are not intended to limit the invention. In this specification, the singular form includes the plural form unless specifically stated otherwise in the text. As used in this specification, "comprises" or "comprising" implies that the mentioned component or step does not exclude the presence or addition of one or more other components or steps.
[0030] Unless otherwise defined, all terms used in this specification may be interpreted in a sense that is commonly understood by those skilled in the art to which the present invention pertains. Additionally, terms defined in commonly used dictionaries are not to be interpreted ideally or excessively unless explicitly and specifically defined otherwise.
[0031] Hereinafter, embodiments of the present invention will be described in detail with reference to the attached drawings. When describing with reference to the drawings, identical or corresponding components are given the same reference numerals, and redundant descriptions thereof will be omitted.
[0032] FIG. 1 is a flowchart illustrating a dynamic memory management method according to an embodiment of the present invention.
[0033] Referring to FIG. 1, a dynamic memory management method according to one embodiment of the present invention may include a step (S100) of defining a shadow area mapped to a memory area, a step (S200) of setting a coloring value in the shadow area, and a step (S300) of allowing or blocking access to the memory area based on the coloring value. Here, the dynamic memory management method may be performed in a dynamic memory management device (300) of FIG. 14, which will be described later.
[0034] FIG. 2 is a diagram showing a memory structure used for dynamic memory allocation and deallocation according to an embodiment of the present invention.
[0035] Referring to FIG. 2, the memory (100) may include a memory allocation area (110) of a heap chunk structure created when dynamic memory is allocated, a memory deallocation area (130) of a heap chunk structure created when dynamic memory is deallocated, and a memory management area (tcache_entry, 150) of a heap chunk structure that manages the deallocation / reallocation of memory. Here, 170 may refer to the remaining area excluding the memory allocation area, the memory deallocation area, and the memory management area.
[0036] prev_size may be a space that stores the size of the freed heap chunk (HC) when the previous heap chunk (HC) is freed. size may be a space that stores the size of the currently allocated heap chunk (HC). fd (forward pointer) may represent the address of the next heap chunk (HC) in the same bin when memory is freed. bk (backward pointer) may represent the address of the previous heap chunk (HC) in the same bin. Additionally, a heap chunk (HC) may consist of a body (Cb) and a header (Ch).
[0037] If we look at the operation, when requesting the desired size using the malloc() function for dynamic memory allocation, the address of the dynamically allocated pointer is returned, and that address becomes the starting address of the chunk body, not the chunk header.
[0038] When dynamic memory is freed using the free() function after dynamic memory allocation, the process of storing fd and bk in the data area (data) and registering the freed memory area as a reallocable memory area in the memory management area (150) located at the top of the memory area (100) can be performed.
[0039] The memory management area (150) searches for a reallocable memory area and reallocates it.
[0040] In step (S100), the dynamic memory management device (300) may define a shadow region mapped to the memory region (100). The dynamic memory management device (300) may define a shadow region so as to be physically separated from the memory region (100).
[0041] FIG. 3 is a diagram showing an actual memory area where a heap chunk is allocated in memory according to an embodiment of the present invention, FIG. 4 is a diagram showing access permission values for a shadow area mapped to the memory area of FIG. 3, and FIG. 5 is a diagram showing the definition of access permission according to the coloring value of the shadow area.
[0042] As illustrated in FIG. 3, when two malloc() functions are executed for dynamic memory allocation of the same size (0x20), the dynamic memory allocation request is allocated to a memory management area (150), and the memory management area (150) searches for a reallocable memory area to create two heap chunks (HC). Here, size can be '0x31', including the size of the body (Cb) and header (Ch) of the allocated heap chunk (HC).
[0043] As illustrated in FIG. 4, the shadow area (200) can be defined as '0x3000_0000' to '0x3fff_ffff'. The mapping between the memory area (100) and the shadow area (200) can be achieved by performing a '>> 4-bit' shift operation on the lower byte of the actual memory address and adding '0x3000_0000', which is the base address of the shadow area (200). This is because the lower 4-bit value of the address is meaningless since heap chunk allocation is performed in 16-byte units on a 64-bit machine.
[0044] Accordingly, the dynamic memory management device (300) allocates 16 bytes of memory area as 1 byte of shadow area, and the value for access rights can be defined in 2-bit units. The value of the shadow area (200) can be defined in 4 values in 2-bit units, such as '00(2)', '01(2)', '10(2)', '11(2)'.
[0045] The dynamic memory management device (300) can set a coloring value for memory access rights in the shadow area (200) (S200). Additionally, the dynamic memory management device (300) can allow or block access to the memory area (100) based on the coloring value (S300).
[0046] As illustrated in FIG. 5, the shadow area (200) may include a first area (210) with a coloring value of '1010_1010(2)', a second area (230) with a coloring value of '0101_0101(2)', a third area (250) with a coloring value of '0000_0000(2)', and a fourth area (270) with a coloring value of '1111_1111(2)'.
[0047] Returning to FIGS. 3 and 4, the first area (210) of the shadow area (200) corresponds to the header portion of the heap chunk (HC), including the memory management area (150), and access may be blocked after the heap chunk (HC) is allocated. The second area (230) of the shadow area (200) corresponds to the management area for the freed heap chunk (HC) and corresponds to the heap chunk free / allocation, and access may be blocked after the heap chunk (HC) is allocated and freed. The third area (250) of the shadow area (200) corresponds to the data area (Data) of the freed heap chunk (HC) after the heap chunk (HC) is freed, and access may be blocked after the heap chunk (HC) is freed. The fourth area (270) of the shadow area (200) corresponds to the data area (Data) of the heap chunk (HC) after the heap chunk (HC) allocation, and access is allowed after the heap chunk (HC) allocation.
[0048] Therefore, the shadow area (200) is configured so that the user can only access the data area (Data) of the heap chunk (HC) allocated through two malloc functions, and does not allow access to addresses outside of this.
[0049] FIG. 6 is a diagram showing an actual memory area where a heap chunk is allocated in memory according to another embodiment of the present invention, and FIG. 7 is a diagram showing access permission values for a shadow area mapped to the memory area of FIG. 6.
[0050] As illustrated in FIG. 6, if two malloc() functions are executed for dynamic memory allocation of the same size (0x20), two heap chunks (HC) can be created in the memory area (100).
[0051] Afterwards, when the free() function is executed, information about the freed heap chunk (HC) is stored in the memory management area (150), and fb and bk can be stored in the data area (Data) of the freed heap chunk (HC).
[0052] As illustrated in FIG. 7, when the release of the heap chunk (HC) in the memory area (100) is completed, a coloring value of 0000_0000 (2), corresponding to the data area of the released heap chunk (HC), can be set in the third area (250) of the shadow area (200) mapped to the memory area (100).
[0053] Therefore, after freeing a heap chunk (HC) by performing the free() function, access to the data area (Data) of the freed heap chunk (HC) may be blocked.
[0054] FIG. 8 is a diagram showing an actual memory area where a heap chunk is released in memory according to an embodiment of the present invention, and FIG. 9 is a diagram showing access rights values for a shadow area mapped to the memory area of FIG. 8.
[0055] As illustrated in FIG. 8, after the first free() function is executed, the second free() function is executed, and information about the freed heap chunk (HC) is stored in the memory management area (150), and fd and bk can be stored in the data area (Data) of the freed heap chunk (HC).
[0056] As illustrated in FIG. 9, when the release of the heap chunk (HC) in the memory area (100) is completed, a coloring value of 0000_0000 (2), corresponding to the data area of the released heap chunk (HC), can be set in the third area (250) of the shadow area (200) mapped to the memory area (100).
[0057] Therefore, after freeing a heap chunk (HC) by performing the free() function, access to the data area (Data) of the freed heap chunk (HC) may be blocked.
[0058] FIG. 10 is a diagram showing an actual memory area where a heap chunk is released in memory according to another embodiment of the present invention, and FIG. 11 is a diagram showing access rights values for a shadow area mapped to the memory area of FIG. 10.
[0059] As illustrated in FIG. 10, after freeing a heap chunk (HC) using a second free() function, if a request for allocation of a heap chunk (HC) of the same size is made again, the memory management area (150) can search for available freed heap chunks. If there are freed heap chunks (HC), the memory management area (150) can perform reallocation. At this time, the number of available heap chunks (HC) is reduced to '1', and the address of the available heap chunk (HC) can be changed to '0x00005555_555592a0'.
[0060] As illustrated in FIG. 11, when the reallocation of the requested heap chunk (HC) in the memory area (100) is completed, the fourth area (270) of the shadow area (200) mapped to the memory area (100) may be set to a coloring value of '1111_1111 (2)', which is a value that allows access to the data area of the reallocated heap chunk (HC).
[0061] Therefore, when a heap chunk (HC) is reallocated by executing the malloc() function, access to the data area (Data) of the allocated heap chunk (HC) can be allowed again.
[0062] FIG. 12 is a diagram showing an actual memory area that frees a heap chunk after reallocating a heap chunk in memory, and FIG. 13 is a diagram showing access permission values for a shadow area mapped to the memory area of FIG. 12.
[0063] As illustrated in FIG. 12, after reallocating a heap chunk (HC) using the malloc() function, if the free() function is executed, information about the freed heap chunk (HC) is stored in the memory management area (150), and fd and bk can be stored in the data area (Data) of the heap chunk (HC). Here, the number of reallocable heap chunks (HC) is increased to '2' by adding the freed heap chunk (HC) in the memory management area (150), and the address of the reallocable heap chunk (HC) is changed to '0x00005555_555592d0'.
[0064] As illustrated in FIG. 13, when the release of the heap chunk (HC) in the memory area (100) is completed, the fourth area (270) of the shadow area (200) may be set to a coloring value of '0000_0000(2)', which blocks access to the data area (Data) of the released heap chunk (HC).
[0065] Therefore, after freeing a heap chunk (HC) by performing the free() function, access may be blocked again because it is the data area (Data) of the freed heap chunk (HC).
[0066] FIG. 14 is a block diagram showing the configuration of a dynamic memory management device according to one embodiment of the present invention.
[0067] Referring to FIG. 14, a dynamic memory management device (300) according to an embodiment may include a shadow area definition unit (310), a coloring value setting unit (330), and a memory access determination unit (350).
[0068] The shadow area definition unit (310) can define a shadow area mapped to a memory area. The coloring value setting unit (330) can set a coloring value to grant access rights to the shadow area. The memory access determination unit (350) can allow or block access to the memory area based on the coloring value.
[0069] The shadow area can be physically separated from the memory area. The shadow area can be allocated 1 byte of the 16 bytes of the memory area. The access permission setting area of the shadow area can be defined by 2 bits.
[0070] The operation of the shadow area during dynamic memory allocation and deallocation has been explained in FIGS. 3 to 13, so a detailed description thereof will be omitted.
[0071] A device protection device according to an embodiment can be implemented in a computer system (1000), such as a computer-readable recording medium.
[0072] FIG. 15 is a block diagram showing the configuration of a computer system according to one embodiment of the present invention.
[0073] Referring to FIG. 15, a computer system (1000) according to an embodiment may include one or more processors (1010), memory (1030), user interface input device (1040), user interface output device (1050), and storage (1060) that communicate with each other through a bus (1020). Additionally, the computer system (1000) may further include a network interface (1070) connected to a network.
[0074] The processor (1010) may be a semiconductor device that executes programs or processing instructions stored in a central processing unit or in memory or storage. The memory (1030) and storage (1060) may be storage media comprising at least one of a volatile medium, a non-volatile medium, a removable medium, a non-removable medium, a communication medium, or an information transfer medium. For example, the memory (1030) may include a ROM (1031) or a RAM (1032).
[0075] That is, a computer-readable recording medium storing a computer program may include instructions for a processor to perform a method including defining a shadow area mapped to a memory area, setting a coloring value in the shadow area, and allowing or blocking access to the memory area based on the coloring value.
[0076] In addition, according to one embodiment, a computer program stored on a computer-readable recording medium may include instructions for a processor to perform a method including an operation of defining a shadow area mapped to a memory area, an operation of setting a coloring value in the shadow area, and an operation of allowing or blocking access to the memory area based on the coloring value.
[0077] The specific embodiments described in this invention are examples and do not limit the scope of the invention in any way. For the sake of brevity of the specification, descriptions of prior electronic configurations, control systems, software, and other functional aspects of said systems may be omitted. Additionally, the connections of lines or connecting members between components shown in the drawings are illustrative of functional connections and / or physical or circuit connections, and may be replaced or additionally represented as various functional connections, physical connections, or circuit connections in actual devices. Furthermore, unless specifically stated as "essential," "importantly," etc., a component may not be strictly necessary for the application of the invention.
[0078] Accordingly, the scope of the present invention should not be limited to the embodiments described above, and all scopes equivalent to or equivalently modified from the claims set forth below, as well as the claims set forth below, shall be considered to fall within the scope of the concept of the present invention. Explanation of the symbols
[0079] 100: Memory area 200: Shadow area 300: Dynamic Memory Management Unit 310: Shadow Area Definition 330: Coloring value setting section 350: Memory access decision unit
Claims
Claim 1 A dynamic memory management method in which each step is performed by a dynamic memory management device, comprising: a step of defining a shadow area mapped to a memory area; a step of setting a coloring value in the shadow area; and a step of allowing or blocking access to the memory area based on the coloring value when accessing the memory area; wherein the shadow area allocates 16 bytes of the memory area as 1 byte, and the access permission setting area of the shadow area is defined as 2 bits. Claim 2 A dynamic memory management method according to claim 1, wherein, in the step of allowing or blocking access to the memory region, when the freeing of the heap chunk in the memory region is completed by performing a free() function, access to the data region of the freed heap chunk is blocked based on the coloring value of the shadow region. Claim 3 A dynamic memory management method according to claim 2, wherein, in the step of allowing or blocking access to the memory area, when the free() function is executed, information about the freed heap chunk is stored in the memory management area (tcache_entry), and fd and bk are stored in the data area of the freed heap chunk, thereby completing the freeing of the heap chunk. Claim 4 A dynamic memory management method according to claim 1, wherein, in the step of allowing or blocking access to the memory region, when an allocation for a heap chunk is requested in the memory region by performing a malloc() function, access to the data region of the allocated heap chunk is allowed based on the coloring value of the shadow region. Claim 5 A dynamic memory management method according to claim 1, wherein the shadow region is physically separated from the memory region. Claim 6 delete Claim 7 delete Claim 8 A dynamic memory management device comprising: a shadow area definition unit that defines a shadow area mapped to a memory area; a coloring value setting unit that sets a coloring value in the shadow area; and a memory access determination unit that allows or blocks access to the memory area based on the coloring value when accessing the memory area, wherein the shadow area allocates 16 bytes of the memory area as 1 byte, and the access permission setting area of the shadow area is defined as 2 bits. Claim 9 A dynamic memory management device according to claim 8, wherein the memory access determination unit blocks access to the data area of the released heap chunk based on the coloring value of the shadow area when the release of the heap chunk in the memory area is completed by performing the free() function. Claim 10 A dynamic memory management device according to claim 9, wherein the memory access determination unit, when the free() function is executed, stores freed heap chunk information in a memory management area (tcache_entry), and stores fd and bk in the data area of the freed heap chunk, thereby completing the freeing of the heap chunk. Claim 11 A dynamic memory management device according to claim 8, wherein the memory access determination unit allows access to the data area of the allocated heap chunk based on the coloring value of the shadow area when allocation for the heap chunk in the memory area is requested by performing the malloc() function. Claim 12 In claim 8, the shadow region is a dynamic memory management device physically separated from the memory region. Claim 13 delete Claim 14 delete Claim 15 A computer-readable recording medium storing a computer program, wherein the computer program includes instructions for causing the processor to perform operations including: defining a shadow area mapped to a memory area when executed by a processor; setting a coloring value in the shadow area; and allowing or blocking access to the memory area based on the coloring value when accessing the memory area, wherein the shadow area allocates 16 bytes of the memory area as 1 byte, and the access permission setting area of the shadow area is defined as 2 bits.
Citation Information
Patent Citations
Multi-core processor system and multi-core processor
US20120042133A1
Dynamic memory management system and the management methods for defense against heap attacks
KR101166051B1
Metadata processing technology
KR1020190029501A
Page coloring to associate memory pages with programs
US20070157003A1
Method and apparatus for detecting memory access faults
US20120278665A1
