(19)
(11)EP 3 299 964 B1

(12)EUROPEAN PATENT SPECIFICATION

(45)Mention of the grant of the patent:
11.11.2020 Bulletin 2020/46

(21)Application number: 16306236.7

(22)Date of filing:  27.09.2016
(51)International Patent Classification (IPC): 
G06F 12/02(2006.01)
G06F 21/52(2013.01)
G06F 21/78(2013.01)
G06F 12/14(2006.01)
G06F 21/54(2013.01)

(54)

A COMPUTER-IMPLEMENTED METHOD AND A SYSTEM FOR ENCODING A HEAP APPLICATION MEMORY STATE USING SHADOW MEMORY

COMPUTERIMPLEMENTIERTES VERFAHREN UND SYSTEM ZUR CODIERUNG EINES HEAP-ANWENDUNGSSPEICHERZUSTANDS MIT EINEM SCHATTENSPEICHER

PROCÉDÉ MIS EN UVRE PAR ORDINATEUR ET SYSTÈME DE CODAGE D'UN ÉTAT DE MÉMOIRE D'APPLICATION EN TAS UTILISANT LA MÉMOIRE FANTÔME


(84)Designated Contracting States:
AL AT BE BG CH CY CZ DE DK EE ES FI FR GB GR HR HU IE IS IT LI LT LU LV MC MK MT NL NO PL PT RO RS SE SI SK SM TR

(43)Date of publication of application:
28.03.2018 Bulletin 2018/13

(73)Proprietor: COMMISSARIAT À L'ÉNERGIE ATOMIQUE ET AUX ÉNERGIES ALTERNATIVES
75015 Paris (FR)

(72)Inventors:
  • VOROBYOV, Kostyantyn
    91120 Palaiseau (FR)
  • KOSMATOV, Nikolay
    78120 Saint-Cyr-L'Ecole (FR)
  • SIGNOLES, Julien
    92260 Fontenay-aux-Roses (FR)

(74)Representative: Marks & Clerk France 
Immeuble "Visium" 22, avenue Aristide Briand
94117 Arcueil Cedex
94117 Arcueil Cedex (FR)


(56)References cited: : 
US-A1- 2003 126 590
US-B2- 8 762 797
US-B1- 6 826 672
  
  • ARVID JAKOBSSON ET AL: "Fast as a shadow, expressive as a tree", PROCEEDINGS OF THE 30TH ANNUAL ACM SYMPOSIUM ON APPLIED COMPUTING, 13 April 2015 (2015-04-13), - 17 April 2015 (2015-04-17), pages 1765-1772, XP055354832, DOI: 10.1145/2695664.2695815 ISBN: 978-1-4503-3196-8
  
Note: Within nine months from the publication of the mention of the grant of the European patent, any person may give notice to the European Patent Office of opposition to the European patent granted. Notice of opposition shall be filed in a written reasoned statement. It shall not be deemed to have been filed until the opposition fee has been paid. (Art. 99(1) European Patent Convention).


Description


[0001] The present invention relates to the field of runtime analysis of an application's memory state. In particular, the invention relates to the field of memory shadowing techniques which associate addresses from the application's memory to values stored in a disjoint memory region (or regions) called shadow memory. An object of the invention is a method for encoding an application's memory state using shadow memory.

[0002] The invention also focuses on using shadow memory to detect attempts by a computer program to access memory that is not properly allocated for such an access.

[0003] The invention also consists in a computer-implemented method and a system for detecting illegal memory accesses by a computer program, where memory access denotes reading a value from a memory location or writing a value to it.

[0004] Computer programs typically execute on computers, or equivalent systems that comprise a processor and a memory. A computer program executed by an operating system can be represented by one or several processes. The physical memory is usually managed by a computer's operating system in order to provide each process with a virtual memory space. The virtual memory space is accessed by applications to write and read values. Each of the processes has its own virtual memory space. Alternately, computer memory can be managed directly, without using a virtual memory. Memory is organized into locations, each having a unique address. Typically, memory is represented by a contiguous array of cells with byte-level addressing.

[0005] Typically, a virtual memory space of an executing process is divided into several memory segments used for different purposes. The segments are disjoint and represented by contiguous memory regions.

[0006] Stack memory is a memory segment generally assigned to saving local variables automatically allocated and de-allocated by programs at runtime. As such, stack memory is reserved for automatic memory allocation at runtime. Also, memory is allocated in memory blocks.

[0007] Heap memory is usually the largest part of the memory and is reserved for dynamically allocated memory blocks. Typically, a program can dynamically allocate memory by calling a dedicated procedure. An example of such a function is the malloc function in the C programming language. When the allocated memory is no longer required, the program can also call an operating system procedure to deallocate the allocated memory so that it can be re-used by the program.

[0008] The invention applies more particularly to heap memory.

[0009] At a source level of programming languages heap memory can be written to or read from using pointers: special variables containing addresses of memory locations. Some pointer p is said to point to a memory block B if p stores an address from B.

[0010] A problem may arise if a program reads from or writes to a memory location that was not properly allocated (e.g., via malloc for example). Another problem may arise when the program accesses an allocated memory location through a pointer which does not point to a memory block containing that location.

[0011] Problems mentioned in the above paragraph are instances of improper use of memory and relate to a broader class of problems commonly known as memory safety, which includes (but not limited to) such issues as access to unallocated memory, memory leaks, illegal dereferences, double free errors, reading uninitialized data. Consequences of such issues differ in severity and range from inconsistent behaviors to issues compromising security of applications and program crashes. It is therefore important to detect such memory violations.

[0012] It is also a general purpose of the invention to provide a shadow-state encoding mechanism that allows analyzing the memory state of an executing program at runtime. In particular, tracking allocated memory can be performed during a program's execution.

[0013] Memory shadowing is a general technique for tracking properties of an application's data at runtime. In its typical use memory shadowing associates addresses from the application's memory to shadow values, stored in a disjoint memory region (or regions) called shadow memory. During a program's execution shadow values act as metadata that store information about the memory addresses they are mapped to.

[0014] Memory shadowing has many applications, one of them is memory analysis where shadow values are used to track memory and detect safety problems. Examples of such existing mechanisms are described in particular in references [1] and [2].

[0015] Shadow state encoding refers to the process of designing the structure of shadow values and their interpretation. The prior art contains shadow state encoding mechanisms that vary across different tools. Some implementations use shadow values to store bit-level states of the memory locations they aim to characterize.

[0016] Reference [3] discloses a tool using shadow state encoding focused on detection of information leakage at runtime. The proposed method uses one bit to tag each addressable byte from an application's memory as public or private. Another method disclosed in reference [4] relates to a memory debugger used to shadow one byte by two bits that indicate whether that byte is allocated and initialized. Reference [2] introduces a method that uses bit-to-bit shadowing to track initialization status of every bit. Reference [5] proposes to customize memory allocation to ensure that memory blocks are allocated at an 8-byte boundary, and to track aligned 8-byte sequences by one shadow byte. American patent publication US 8762797 B2 also describes the same method as reference [5]. US 6826672 B1 discloses detection of out-of-bounds memory accesses using a metadata structure, capability. US 2003126590 A1 discloses detection of uninitialized, unallocated, out-of-bound memory accesses using a shadow memory, wherein the encoded shadow value represents uninitialized/unallocated addresses and the data type. XP055354832, "Fast as a shadow, expressive as a tree", Arvid Jakobsson et al, proceedings of the 30th annual ACM symposium on applied computing, discloses a metadata structure including length, base address, offset, validity and initialization information for every allocated object.

[0017] The shadow state encoding methods of prior art have been proven useful for tracking memory at bit-level and byte-level. These methods, however, are limited in their capacity to identify properties with respect to memory blocks. More particularly, the existing tools using shadow memory do not capture enough metadata to identify the bounds and the length of a memory block a given address belongs to. Therefore, existing methods cannot detect a memory violation concerning an access to an allocated memory location through a pointer which does not point to a memory block the location belongs to.

[0018] The present invention is proposed in the view of the above problem and relates to the use of shadow memory during runtime memory-safety analysis of computer programs. The invention aims at resolving the limitations of the prior art's shadow state encoding methods with a new method that allows tracking boundaries of allocated memory blocks while still capturing byte-level properties. This is achieved with a particular shadow memory encoding scheme which captures boundaries and lengths of allocated memory blocks. Analyzing the content of the shadow memory allows detecting memory safety issues.

[0019] In particular, for a memory location given by its address a, the proposed invention allows computing the following information regarding the address a: whether a has been allocated, whether a has been initialized, the start (base) address of the memory block a belongs to, the byte-length of the memory block a belongs to, the byte offset of a within its block. Such information allows for detection of specific memory safety issues at runtime.

[0020] The invention relates to a computer-implemented method for encoding an application memory that a program, executed on a computer, has access to, using a shadow memory corresponding to the application memory, the method comprising:
  • creating and initializing a shadow memory divided into a plurality of segments, each segment in the application memory being mapped to a corresponding segment in the shadow memory,
  • for each memory block in the application memory that the program allocates, encoding a corresponding shadow memory block, in the shadow memory, by:
    • defining a meta segment preceding the first segment of the memory block in the application memory, and a corresponding shadow meta segment in the shadow memory block,
    • writing in the shadow meta segment a first value indicative of the size of the memory block,
    • writing, in each subsequent segment of the shadow memory block, a second value indicative of the offset between the segment and the first segment of the shadow memory block.


[0021] In a particular embodiment of the invention, the second value is indicative of the offset from the base address of the shadow memory block to the segment's base address.

[0022] In a particular embodiment of the invention, a meta segment in the application memory is unallocated.

[0023] In a particular embodiment of the invention, the shadow memory is initialized with base values being positive or zero.

[0024] In a particular embodiment of the invention, the method comprises writing a base value in a first part of the shadow meta segment and the first value indicative of the size of the memory block in a second part of the shadow meta segment.

[0025] In a particular embodiment of the invention, the base value is zero and the second value is equal to the offset from the base address of the shadow memory block to the segment's base address incremented by one.

[0026] In a particular embodiment of the invention, the second value is written in a first part of a shadow segment having the same size as the first part of a meta segment.

[0027] In a particular embodiment of the invention, the method comprises writing, in a second part of each shadow segment, a third value indicative of the initialization of all bytes of the corresponding segment in the application memory.

[0028] In a particular embodiment of the invention, the application memory comprises heap memory.

[0029] In a particular embodiment of the invention, the method comprises writing base values to the first part of each segment in a shadow memory block when a corresponding memory block in the application memory is de-allocated by the program.

[0030] Another object of the invention is a computer-implemented method for detecting illegal memory access by a program executed on a computer having a processor and an application memory, the method comprising:
  • executing the method for encoding shadow memory according to any embodiment of the invention and,
  • when the program accesses to an address in an application memory block, analyzing the shadow memory block to determine if the access is illegal.


[0031] In a particular embodiment of the invention, analyzing the shadow memory block to determine if the access is illegal comprises determining the length of the memory block and the offset of the address within the memory block.

[0032] In a particular embodiment of the invention, determining if the access is illegal comprises comparing the offset of the address within the memory block and the length of the memory block.

[0033] In a particular embodiment of the invention, the address is equal to a base address plus an offset value and determining if the access is illegal comprises comparing the offset of the base address within the memory block plus the length of the memory block with the offset value.

[0034] In a particular embodiment of the invention, determining if the access is illegal comprises reading the value of the segment offset in the shadow segment to which the address belongs and comparing said value with a base value.

[0035] In a particular embodiment of the invention, determining the length of the memory block comprises:
  • Determining the offset of the address relative to the base address of the segment it belongs to,
  • Determining the base address of the segment to which the address belongs,
  • Determining the base address of the corresponding shadow segment,
  • Determining the segment offset by reading a value at the base address of the shadow segment,
  • Determining the base address of the shadow memory block,
  • Determining the length of the memory block by reading the shadow meta segment of the shadow memory block.


[0036] In a particular embodiment of the invention, determining the offset of the address within the memory block comprises:
  • Determining the offset of the address relative to the base address of the segment it belongs to,
  • Determining the base address of the segment to which the address belongs,
  • Determining the base address of the corresponding shadow segment,
  • Determining the segment offset by reading a value at the base address of the shadow segment,
  • Determining the base address of the shadow memory block,
  • Determining the base address of the corresponding memory block,
  • Determining the offset of the address within the memory block.


[0037] In a particular embodiment of the invention, the method comprises determining if the address is initialized by evaluating the third value in the second part of the shadow segment corresponding to the segment to which the address belongs.

[0038] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate various embodiments of the invention and, together with the general description of the invention given above, and the detailed description of the embodiments given below, illustrate some embodiments of the invention.
  • Figure 1 shows a representation of a heap memory block and a corresponding shadow memory block according to an embodiment of the invention,
  • Figure 2 shows a flowchart of a method for encoding shadow memory according to an embodiment of the invention,
  • Figure 3 shows a flowchart of a method for determining properties of a memory address by using shadow state memory according to another embodiment of the invention,
  • Figure 4 shows an illustration of a particular use of a shadow memory block when executing the method of Figure 3,
  • Figure 5 shows a flowchart of a method for detecting illegal access of memory by a program according to another embodiment of the invention,
  • Figure 6 shows a first example of application of the invention for detecting illegal memory access,
  • Figure 7 shows a second example of application of the invention for detecting improper access of memory,
  • Figure 8 shows a generic computing system suitable for implementing embodiments of the invention,
  • Figure 9 shows a block diagram of a system including a compiler and instrumentation for performing embodiments of the invention.


[0039] The method according to the invention applies to computer programs that manage memory through dynamic allocation in a virtual memory space of a computer process, where random access memory is represented by a contiguous array of memory cells with byte-level addressing.

[0040] The following paragraphs give general definitions of terms and concepts that will be referred to throughout the description.

[0041] A virtual memory space of a computer process is linear and segmented, consisting of text, stack, heap and potentially other segments. The order of segments is unspecified, however each segment is represented by a contiguous memory region disjoint with any other segment. This document further refers to a heap segment within the virtual memory space of a computer process as to a program's heap.

[0042] Byte-width of a memory address (denoted Aw) refers to the number of bytes sufficient to uniquely represent any memory address in the virtual memory space of a process. Typically Aw is 4 bytes in x86 architecture with 32-bit instruction set.

[0043] At runtime a program allocates memory in units referred to as memory blocks. A memory block is a contiguous memory region described by its start and end addresses. The start address of a memory block, also referred to as its base address, is less than or equal to its end address. The length of the memory block is the difference between the block's end and base addresses increased by 1. A memory address a is said to belong to a memory block B if a is greater than or equal to the base address of B and less than or equal to the end address of B. The byte offset of an address a belonging to a memory block B is given by the difference between a and the base address of B. A memory block B is said to be aligned at a boundary of N, if the base address of B is divisible by N. A memory block B is said to be padded with N bytes if its base address is preceded by at least N bytes of unusable memory.

[0044] At any given moment, memory allocation of an executing computer program consists of disjoint memory blocks allocated statically, dynamically or automatically. Static memory allocation refers to allocation of memory blocks at compile-time and typically represents global variables. Automatically allocated memory refers to memory blocks allocated on a program's stack at runtime. In a typical program stack-allocated memory blocks are unaligned or aligned at a boundary of two and placed one after another. The minimal length of a memory block allocated either statically or automatically is one byte.

[0045] Dynamically allocated memory refers to memory blocks allocated on a program's heap at runtime. Let a segment be a memory block of a fixed length szseg but not less than a doubled byte-width of a memory address (e.g., 8 bytes in x86 architecture with 32-bit instruction set). The base address of each heap memory block is a multiple of szseg and each allocated heap memory block is padded with szseg bytes.

[0046] The invention generally relates to dynamically allocated memory and uses the known concept of shadow memory to track metadata concerning application memory allocation. In the following description, expression "application memory" is used to refer to memory used by a program which can access it to write and read values. Expression "shadow memory" designates memory used to store metadata about allocation of application memory. Shadow memory cannot be used by an application.

[0047] Shadow memory is represented by one or several contiguous memory regions disjoint with the application memory space used by an executing program. The shadowing mapping scheme can be either a direct mapping scheme (known as DMS), where a single memory space is used to shadow the entire address space, or a segmented mapping scheme (known as SMS) that segregates a program's address space into shadow segments.

[0048] Generally, there is a mapping correspondence between application memory and shadow memory. A mapping function is used to translate an address from application memory to shadow memory and vice versa. Reference [6] gives an example of a shadowing mapping scheme that can be used to perform such a mapping function.

[0049] For the purpose of this description, it is assumed that translation from an application memory address addr to a shadow memory address sh is given by the mapping Shadow(addr) = sh, and conversion from sh to addr is given by the mapping Uspace(sh) = addr.

[0050] Figures 1 and 2 show a method for encoding shadow memory according to a first embodiment of the invention.

[0051] Figure 1 shows a representation of an application memory block AM and a corresponding shadow memory block SM. Figure 2 shows a flowchart of a method for encoding shadow memory SM according to an embodiment of the invention.

[0052] A shadow memory block SM is used to store metadata concerning allocation or other information related to an application memory block AM. As such, the application memory block AM and the shadow memory block SM can have the same size.

[0053] According to an embodiment of the invention, application memory space and shadow memory space are both represented using segments of fixed identical size szseg. The size of a shadow segment is a parameter of the invention but cannot be less than the doubled byte-width of a memory address (i.e., 2Aw). Therefore, in the case of a X86 architecture with a 32-bit instruction set, Aw is 4 bytes and the size of a segment szseg is not less than 8 bytes. According to an alternative embodiment, the segments in the shadow memory space are scaled. That is, the size of a segment in the shadow memory space, differ from the size of a corresponding segment in the application memory space. In particular, to limit the space occupied by shadow memory, a shadow memory segment can be smaller than an application memory segment.

[0054] All shadow memory segments are initialized (i.e., filled with) with base values. According to a preferred embodiment, a base value is zero but it can be any value.

[0055] When a computer program allocates an application memory block AM, a software tool or instrument according to the invention executes the encoding method depicted in Figure 2 to encode a corresponding shadow memory block SM in the shadow memory space.

[0056] In the example shown via Figure 1, an application memory block AM comprises N segments, S1AM, S2AM, S3AM, ..., SNAM. The corresponding shadow memory block SM also comprises N segments S1SM, S2SM, S3SM, ..., SNSM. Each segment in the shadow memory block SM is used to track changes in a corresponding segment of the application memory block AM.

[0057] In a first step 201 of the method depicted in Figure 2, the segment MSAM, immediately preceding the first segment S1AM in the application memory block AM, is reserved as unallocated memory. That is, the memory space occupied by the segment MSAM cannot be used by a program. MSAM is further referred to as the meta segment.

[0058] The corresponding segment MSSM in the shadow memory is also called a meta segment and is used to store metadata related to the application memory block AM. Precisely, a first part MSA of the meta-segment MSSM is filled with a base value and the size L of the application memory block AM is written in a second part MSB of the meta-segment MSSM. The first part MSA and the second part MSB are contiguous. The first part MSA starts at the base address of the meta-segment MSSM. The size L is the size of the block comprising the segments S1AM, S2AM, S3AM, ..., SNAM that are effectively allocated without the meta-segment MSAM. In alternative unclaimed the size L of the memory block can be replaced by any information indicative of the size L of the memory block. For example, it can be a value from which the size L can be directly deduced. This information can also be encoded or encrypted to give access to only authorized users.

[0059] In a second step 202 of the method, the first parts S1A, S2A, S3A, ..., SNA of segments S1SM, S2SM, S3SM, ..., SNSM of the shadow memory block SM capture values OFF1, OFF2, OFF3, ..., OFFN, which encode offsets between the base addresses of the segments S1SM, S2SM, S3SM, ..., SNSM and the base address of the shadow memory block SM. Such offsets are further referred to as shadow segment offsets. A shadow segment offset of some segment SNSM in the shadow memory block SM is the difference between the base address of the segment SNsm and the base address of the shadow memory block SM. The first segment S1SM of the shadow memory block SM is also called the base segment. The first parts of S1A, S2A, S3A, ..., SNA start at the base addresses of segments S1SM, S2SM, S3SM, ..., SNSM.

[0060] If a base value is chosen to be zero, then the valuesOFF1, OFF2, OFF3, ..., OFFN are given by the values of the respective shadow segment offsets incremented by one. For instance, OFF3 is given by the difference between the base of the third segment in the shadow memory block SM and the base address of SM. Such choice of encoding OFF1, OFF2, OFF3, ..., OFFN is to differentiate between a base value of zero (which refers to a shadow segment mapped to the unallocated application memory) and the first segment shadow offset (also zero).

[0061] If the base value is chosen to be strictly positive, then the values OFF1, OFF2, OFF3, ..., OFFN are given by the values of respective shadow segment offsets incremented by the base value incremented by one. Otherwise, if the base value is chosen to be strictly negative, the values OFF1, OFF2, OFF3, ..., OFFN are given by the shadow segment offsets themselves. If a value other than zero is used to represent the base value, then the minimal size of a segment in the shadow memory should be increased to allow for storage of such values.

[0062] According to an embodiment of the invention, the size of the first part of any shadow segment is fixed and equals to the size of the first part of the meta segment. The first part of the meta-segment is filled with a base value. This is to keep the same structure for all segments in the shadow memory space.

[0063] According to an embodiment of the invention, the size of the first part of any segment, including the meta-segment, is equal to the byte-width Aw of an address. Generally, the size of the first part of any segment is not less than the byte-width Aw.

[0064] According to an embodiment of the invention, in a third step 203 of the method, a second part S1B, S2B, S3B, ..., SNB of the segments S1SM, S2SM, S3SM, ..., SNSM of the shadow memory block is used to capture per-byte initialization of the corresponding segment in the application memory block. The first parts S1A, S2A, S3A, ..., SNA and the second parts S1B, S2B, S3B, ..., SNB are contiguous in each segment. In other words, the second parts of segments S1B, S2B, S3B, ..., SNB of the shadow memory block SM store information INIT1, INIT2, INIT3, ..., INITN, indicative of the initialization of each byte of the corresponding application memory segments. Initialization can be performed by a computer program after allocation of a memory space by writing values to application memory.

[0065] According to a particular embodiment, the second parts S1B, S2B, S3B, ..., SNB of the segments S1SM, S2SM, S3SM, ..., SNSM are of the size szseg bits, with szseg being the size of a segment in bytes. The first szseg bits in the second part of each shadow segment track per-byte initialization of bytes of the corresponding segment in the application memory. This is such that the first bit in the second part of the shadow segment tracks initialization of the first byte of the corresponding application segment, the second bit tracks the second byte and so on. In a preferred embodiment of the invention a bit-value of one is indicative of an initialized byte in the application memory and zero denotes an uninitialized byte. In an alternative embodiment zero denotes an initialized byte and one is reserved for uninitialized memory.

[0066] The remaining space left in a segment that is not part of the first part or the second part is left unused. It could be used to store any information which can be encoded in the remaining bits.

[0067] According to another embodiment of the invention, the first and the second parts of each segment of the shadow memory can be discontinuous.

[0068] According to yet another embodiment of the invention, when a program de-allocates an application memory block AM, the corresponding shadow memory block SM is updated by initializing all its content with base values.

[0069] Figures 3 and 4 show a method for determining properties of a memory address by using shadow memory, according to another embodiment of the invention.

[0070] Let addr be an address belonging to an application memory block AM having a corresponding shadow memory block SM encoded as described above. Figure 3 shows the steps of a method for determining properties of address addr including the length of the memory block AM that address addr belongs to, the base address of that memory block AM and the offset of address addr within the memory block AM. All these properties relate to the boundaries of the memory block addr belongs to and the position of address addr within this block.

[0071] Figure 4 represents a particular example where address addr is in segment 3 of memory block AM.

[0072] The method described in Figure 3 begins with step 301 in which the offset of address addr relative to the base address of the segment it belongs to, is computed via the following operation:

where szseg is the length of a segment expressed in bytes and mod denotes a modulo operation. In a step 302, the base address of the segment addr belongs to is then computed:

In the particular example of Figure 4, segaddr is the base address of segment 3.

[0073] In a step 303, the corresponding address in the shadow memory block SM of the base address segaddr is computed:

where Shadow(a) is a mapping function translating an application memory address a into a corresponding address in the shadow memory.

[0074] In a step 304, the offset of the segment where the address segsh lies, relative to the base address of the shadow memory block SM, is computed. If the base value is equal or greater than zero, the offset is computed as follows:

where ReadNum(a) is a function retrieving a number stored in a part of a segment starting with address a and bv denotes the base value. In the example depicted in Figure 4, the above operation returns baseoffsh = 33-1 = 32. Alternatively, if the base value used to initialize shadow memory is strictly negative, the operation computed at step 304 is:



[0075] In a step 305, the base address of the shadow memory block segsh belongs to is computed:



[0076] In a step 306, the length of the application memory block addr belongs to is then computed by reading the number stored in the second part of the meta-segment preceding the base address of the shadow memory block. This can be achieved with the following operation.

where Mw denotes the byte-length of the first part of a segment in the shadow memory.

[0077] In a step 307, the base address of the application memory block AM that addr belongs to is computed:

where Uspace(s) is a mapping function translating a shadow memory address s into a corresponding application-space address.

[0078] Finally, in a step 308, the byte offset of addr within its memory block AM can be computed:



[0079] The method depicted in Figure 3 can be used to determine properties of an address addr including the length of the memory block that address addr belongs to, the base address of that memory block and the offset of address addr within the memory block.

[0080] These properties can then be used to detect memory safety problems including illegal or improper access through address addr to a memory location.

[0081] An example of illegal memory access is a pointer trying to access a memory location that was not properly allocated. An example of improper memory access is an access to a properly allocated memory location through a pointer which does not directly point to a memory block containing that location. Knowing the boundaries of the memory block the pointer references and the byte offset of the pointer within this block allows to detect these particular problems.

[0082] Figure 5 shows a flowchart of an example of a method for detecting illegal or improper access of memory by a program. In this example, a program tries to access a memory location at address addr.

[0083] In a first step 501, properties of address addr are computed according to the method depicted in Figure 3. The step 304 of the method is completed with a test of the value read at address location segsh of the shadow memory block. If this value is equal to a base value (for example zero as depicted in Figure 5), the method is terminated and step 501 concludes that address addr corresponds to an unallocated memory location. If the read value is not equal to a base value, then it means that address addr is in a memory block that was properly allocated.

[0084] The method then turns to step 502 in which the offset of address addr within the memory block is compared to the length of the memory block. If the offset baseoffaddr is less than the length of the memory block, then the method concludes that address addr belongs to a memory block that was allocated. If the offset baseoffaddr is equal or larger than the length of the memory block, then the method concludes that the program is trying to access an unallocated memory block.

[0085] According to an alternative embodiment of the method of Figure 5, if the program accesses an address of the form addr+off, then step 502 can be modified to compare the length of the memory block plus baseoffaddr with an offset to determine memory violation problems related to improper memory access. In this case, if baseoffaddr+off is greater or equal to the length of the memory block, the method can conclude that an illegal access to memory location addr+off is being performed.

[0086] If step 502 concludes with no memory safety problem, then in an optional step 503, the method performs initialization check of address location addr by executing the operation ReadBit(segsh + Aw, segoffaddr) and comparing the result with the value used to store initialization information in the shadow memory segments. For example, a value of 1 may mean that the corresponding byte in the segment of the application memory was properly initialized. An initialization check of address addr can be performed in case of a read access to this address. A write access to this location is authorized while a read access is not. When writing in an uninitialized location addr, checking the safety of the write access should be successful, but next an additional step of the method should be performed to modify the shadow memory to store that addr is now initialized.

[0087] The function ReadBit (a,N) returns the value stored in the Nth bit past a memory address a. Therefore, the operation ReadBit(segsh + Aw, segoffaddr) returns the value stored in bit at position segoffaddr in the second part S3B of segment 3 that is used for initialization purpose.

[0088] Figure 6 shows an application of the method depicted in Figure 5 to a first example showing detection of a write access past the bounds of an allocated buffer.

[0089] The first example refers to a particular example program written in the C programming language depicted in Listing 1.
Listing 1
1 #include <stdlib.h> 2 3 int main(int argc, char **argv) { 4 short *s = malloc(sizeof(short)); 5 int *i= (int*)s; 6 *i=2147483647; 7 free(s); 8 }


[0090] The first example shows how the proposed shadow state encoding method can facilitate detection of illegal memory modification - a memory safety problem where a program writes to a memory location not allocated on its program's heap. One of the aims of this example is to show that the proposed shadow state encoding is capable of addressing problems in memory safety typically handled using byte-level shadowing. In particular this example shows that, given a memory address, the shadow state encoding method according to the invention, can identify whether it belongs to a program's allocation.

[0091] The example given in Listing 1 is a program written in the C programming language. The program first allocates a 2-byte heap memory block at Line 4 and aliases it using pointer s. At Line 5 the program declares a 4-byte integer pointer i and makes an alias to the allocated 2-byte heap memory block. Finally, the program writes integer 2147483647 to the memory block whose base address is i and de-allocates the allocated memory via a call to free at Line 7. The program shown in Listing 1 is unsafe as the constant number 2147483647 is represented by 4 bytes, while the memory block pointed to by i at Line 6 is only 2 bytes in length. Consequently the assignment at Line 6 writes 2 bytes past the bounds of the memory block allocated on the heap.

[0092] An example shadow state encoding of the memory block allocated at Line 4 (Listing 1) is shown in Figure 6. The encoding describes the state of the program after executing the statement at Line 5, but before the statement at Line 6 that leads to a memory violation.

[0093] Figure 6 represents an application memory block AM having a length L equal to 2 bytes and corresponding to allocation of a short integer on line 4 of Listing 1. In this particular example, a 32-bit architecture is considered with 8-byte segments and a scale factor of 1. The base value used is 0 and zeros are used to indicate uninitialized bytes. The base address of the memory block AM is pointed to by i (Line 5 of Listing 1). Figure 6 also shows a shadow memory block SM tracking AM. The size of a segment in this example is equal to 8 bytes. Therefore, the application memory block AM comprises a meta-segment MSAM and a base segment S1AM. Similarly, the shadow memory block SM comprises a meta-segment MSSM and a base segment S1SM.

[0094] The shadow meta segment MSSM has a base address equal to Shadow(i - 8) and stores the length L of the allocated block (2 bytes) in its four higher bytes. The base segment S1SM in the shadow memory block SM has a base address equal to Shadow(i) and stores an offset relative to the base address of the block captured by i. Here the offset is incremented by one to avoid confusion with non-allocated areas which store base values equal to zero. The base segment S1SM in the shadow memory block SM also stores per-bit initialization INIT1 of the allocated memory using 8 bits starting at address Shadow(i) + 4. Since the memory has been allocated but not initialized by writing to it, all eight initialization bits are zeroes. Since the shadow segment size is 8 bytes, where the first 4 bytes are used to store the offset and the 5th byte (8 bits) is used for initialization, the three highest bytes of the base shadow segment S1SM are unused.

[0095] An illegal memory access in Listing 1 can be detected using the method shown in Figures 3 and 5.

[0096] At Line 6 the program requests to write four bytes carrying bit-representation of the integer 2147483647 starting at address i. Therefore locations i, i+1, i+2 and i+3 will be written via the code executed at line 6. Using the computations of the method shown in Figure 3 one can identify i as the base address of the memory block and determine that its block length is two bytes. Addresses i+2 and i+3 therefore lie outside of a program's heap allocation, thus writing to these addresses will lead to a memory violation.

[0097] The following shows an application of the method shown in Figure 3 to determine block-level properties of address i+3 and detect that it belongs to the unallocated memory space.

[0098] First, offset of i+3 relative to the base address of the segment S1AM it belongs to is computed (step 301):

Note, that since i captures the address returned by the allocation function malloc, it is aligned at the boundary of 8 and the above expression thus evaluates to 3.
Then, the base address of the segment i+3 belongs to is computed (step 302):

Then, the address shadowing segaddr is computed (step 303):

Then, the offset in the shadow memory block SM relative to the base address of the shadow memory block SM is computed (step 304):

Then, the base address of the shadow block segsh belongs to is computed (step 305):

Then, the length of the memory block i+3 belongs to is computed (step 306):

Then, the base address of the memory block i+3 belongs to is computed (step 307):

Finally the byte offset of address i+3 is computed (step 308):

Finally, applying the method described in Figure 5, the operation ReadNum(segsh) returns 1 and baseoffaddr is greater than the length of the memory block so address i+3 does not belong to the allocated space. Consequently, executing assignment *i=2147483647 at line 6 of Listing 1 leads to a memory violation involving modification of a memory location that has not been allocated by the program.

[0099] In a variant of application of the invention, instead of applying the method shown in Figure 3 to address i+3, the method can be applied to address i to determine that the length of the memory block i belongs to is 2 bytes and its offset within this block is 0 bytes. Then, a variant of the method in Figure 5 can be applied by comparing offset 3 (from address i+3) to the length of the memory block plus the offset of address i previously determined and arriving to the same conclusion of a memory violation.

[0100] Figure 7 shows an application of the method depicted in Figure 5 to a second example involving detection of an improper use of allocated memory.

[0101] The second example is a program written in the C programming language given in Listing 2.
Listing 2
1 #include <stdint.h> 2 #include <stdlib.h> 3 4 int main() { 5 char *p = malloc(3); 6 char *q = malloc(5); 7 int i = (intptr_t)q - (intptr_t)p; 8 *(p+i) = 'θ'; 9 }


[0102] The example program in Listing 2 shows a scenario involving improper use of allocated heap memory, where an allocated memory location is modified through a pointer that references a memory block which does not contain that location. Such an improper use of allocated memory cannot be detected with shadow memory encoding techniques of the prior art.

[0103] In this particular example, a 32-bit architecture is considered with 8-byte segments and a scale factor of 1. The base value used is 0 and zeros are used to indicate uninitialized bytes.

[0104] The program in Listing 2 first allocates two heap memory blocks of 3 and 5 bytes at lines 5 and 6 respectively. Further, an operation at Line 7 computes the difference between the base addresses of the memory blocks pointed to by p and q and saves this difference to integer i. Finally, the statement at Line 8 accesses the memory location belonging to a memory block pointed to by q through p and assigns '0' to it. Therefore, p is used to modify a location beyond the memory block it points to. Since (p+i) is also the address of q (which was allocated on the heap), this error cannot be detected via byte-level shadowing techniques of the prior art. This is because tracking memory at a byte-level can only identify whether a memory address belongs to a program's allocation but cannot identify the bounds of the memory block it points to.

[0105] Figure 7 shows a first application memory block AM1 of 3 bytes pointed to by p and a second application memory block AM2 of 5 bytes pointed to by q.

[0106] Figure 7 also shows the corresponding shadow memory blocks SM1 and SM2 each having one meta segment and one base segment of length equal to 8 bytes.

[0107] Applying the method of Figure 3 to pointer p, it can be determined that p belongs to a memory block of length LAM1 equal to 3 bytes and its offset is 0 within this block.

[0108] The validity of the heap memory modification at address p+i can be determined as follows. The offset of p+i within the memory block AM1 is i. Because heap memory blocks are disjoint, aligned at a boundary of 8 and padded with 8 bytes of unusable memory (meta segments MSAM1 and MSAM2), the value of i is either greater than 7 (if the base address of the memory block AM1 pointed to by p is less than the base address of the memory block AM2 pointed to by q) or less than -7 otherwise. Then, since the length of memory block AM1 is 3 bytes, the offset of p within this block is 0 byte and i has a value that is either greater than 7 or less than -7, the location p+i lies outside the memory block AM1 of p. In other words, the value of i is either bigger than 3+0 or negative which leads, when executing the method shown in Figure 5 (with modified step 502), to the conclusion of a buffer overflow via the assignment at Line 8, Listing 2.

[0109] Although the various embodiments of the invention have been described in relation to two particular examples of memory safety violations occurring in the C programing language, it should be noted that the invention can be applied to various memory safety issues including heap overflow errors, double free violations, null pointer dereferences. Also, all the embodiments of the invention are not limited to the C programming language but also apply to other programming languages such as C++. The invention can be implemented using source-level instrumentation or binary instrumentation. The invention provides a shadow memory encoding scheme that allows determining properties related to boundaries of allocated memory blocks. These properties can then be used to detect memory safety problems. In some embodiments of the invention, detection of a memory safety problem can trigger a message to the developer at runtime. As such, the invention can be included in a debugging tool for use by programmers.

[0110] Additional advantages and modifications will readily appear to those skilled in the art. The invention in its broader aspects is therefore not limited to the specific details, representative methods, and illustrative examples shown and described.

[0111] Figure 8 shows a generic computing system suitable for implementing embodiments of the invention comprising a computer 801 or any equivalent computing system. The system 801 comprises a processor 802 and a memory 803. The processor 802 can be a single central processing unit (CPU), or alternatively include multiple processors or cores. The processor can be a 32-bit or 64-bit processor or any equivalent. Computer 801 can be a personal computer, mainframe computer, server or any other computing device. The processor 802 can be any type of device capable of manipulating or processing information. The processor 802 can be, for example, a quantum processor or a general purpose processor or a special purpose processor or an application-specific integrated circuit, programmable logic arrays, programmable logic controller, microcode, firmware, micro-controller, microprocessor, digital signal processor, or any combination of the foregoing, this list being given for a purely illustrative purpose and is not a limitation to the scope of the invention.

[0112] Memory 803 can be random access memory (RAM) or any other suitable type of storage device. Generally processor 802 receives program instructions and data from the memory 803 which can be used by processor 802 to perform the embodiments of the invention. Memory 803 can be arranged through a virtual memory space and include heap memory but also stack memory. Memory 803 can be in the same unit as processor 802 as shown or can be located in a separate unit that is coupled to processor 802. Processor 802 can access specific locations in memory by placing the location's address onto an address bus 804. The contents in the specified location of memory 803 are then accessed by processor 802 on a data bus 805. Memory 803 is virtualized so that application programs running on processor 802 can address a virtual memory space as opposed to physical locations within memory 803. The operating system of computer 801 manages this virtual memory space.

[0113] Figure 9 is a block diagram of a system including a compiler 903 that accepts source code 902 as input and generates executable code 904 as output. Executable code 904 includes instrumentation code 941 used in performing embodiments taught herein, such as methods depicted in Figures 3 and 5. Source code 902 can be generated by a human programmer using a text editor or programming tool. Code for creating instrumentation code 941 is contained in a library 901 that is accessible by compiler 903. Library 901 is also called run-time library herein. Executable code 904 generated by compiler 903 includes compiled application code 940, also called the application program, into which instrumentation code 941 is inserted. Out-of-bounds accesses to heap memory objects, initialization issues or improper access to allocated memory can be detected using embodiments described herein.

[0114] The system depicted in Figure 9 can be executed by the processor 802 of the computing system 801. In another embodiment, the system of Figure 9 can be implemented through instrumentation added before the source code is passed to a compiler. In yet another embodiment, the instrumentation can be performed at a binary level, i.e., after compilation.

[0115] Generally, all embodiments of the invention can be implemented as a computer program product accessible from a computer-usable or computer-readable medium providing program code for use by or in connection with a computer or any instruction execution system. For the purposes of this description, a computer-usable or computer readable medium can be any apparatus that can contain, store, communicate, propagate, or transport the program for use by or in connection with the instruction execution system, apparatus, or device.

[0116] The term "program" may be used to describe an aspect of computing system implemented to perform a particular function. In some cases, a program may be instantiated via logic device executing machine-readable instructions held by storage device. It will be understood that different modules may be instantiated from the same application, service, code block, object, library, routine, API, function, etc. Likewise, the same program may be instantiated by different applications, services, code blocks, objects, routines, APIs, functions, etc. The term "program" may encompass individual or groups of executable files, data files, libraries, drivers, scripts, database records, etc.

References



[0117] 
  1. [1] R. Hastings and B. Joyce. Purify: Fast detection of memory leaks and access errors. In Proceedings of the Winter USENIX Conference, pages 125-136, January 1992.
  2. [2] J. Seward and N. Nethercote. Using valgrind to detect undefined value errors with bit-precision. In Proceedings of the USENIX Annual Technical Conference, pages 17-30. USENIX, 2005.
  3. [3] W. Cheng, Q. Zhao, B. Yu, and S. Hiroshige. Tainttrace: Efficient flow tracing with dynamic binary rewriting. In Proceedings of the IEEE Symposium on Computers and Communications, pages 749-754. IEEE Computer Society, June 2006.
  4. [4] D. Bruening and Q. Zhao. Practical memory checking with Dr. Memory. In Proceedings of the Annual IEEE / ACM International Symposium on Code Generation and Optimization, CGO '11, pages 213-223, Washington, DC, USA, 2011. IEEE Computer Society.
  5. [5] K. Serebryany, D. Bruening, A. Potapenko, and D. Vyukov. AddressSanitizer: A fast address sanity checker. In Proceedings of the USENIX Annual Technical Conference, pages 309-319. USENIX Association, June 2012,
  6. [6] Q. Zhao, D. Bruening, and S. P. Amarasinghe. Umbra: Efficient and scalable memory shadowing. In Proceedings of the International Symposium on Code Generation and Optimization, pages 22-31. ACM, April 2010.



Claims

1. A computer-implemented method for encoding an application memory that a program, executed on a computer, has access to, using a shadow memory corresponding to the application memory, the method comprising:

- creating and initializing a shadow memory divided into a plurality of segments, each segment in the application memory being mapped to a corresponding segment in the shadow memory,

- for each memory block (AM) in the application memory that the program allocates, encoding a corresponding shadow memory block (SM), in the shadow memory, by:

• defining (201) a meta segment (MSAM) preceding the first segment (S1AM) of the memory block (AM) in the application memory, and a corresponding shadow meta segment (MSSM) in the shadow memory block (SM),

characterised by writing (201) in the shadow meta segment (MSSM) a first value indicative of the size (L) of the memory block (AM),

• writing (202), in each subsequent segment (S1SM, S2SM, S3SM,... SNSM) of the shadow memory block (SM), a second value indicative of the offset (OFF1,OFF2,OFF3,...OFFN) between the segment (S1SM, S2SM, S3SM,... SNSM) and the first segment (S1SM) of the shadow memory block (SM).


 
2. The computer-implemented method for encoding an application memory of claim 1 wherein the second value (OFF1, OFF2, OFF3, ..., OFFN) is indicative of the offset from the base address of the shadow memory block (SM) to the segment's base address.
 
3. The computer-implemented method for encoding an application memory of any of the preceding claims wherein a meta segment (MSAM) in the application memory is reserved as unallocated memory.
 
4. The computer-implemented method for encoding an application memory of any of the preceding claims wherein the shadow memory is initialized with base values being positive or zero.
 
5. The computer-implemented method for encoding an application memory of claim 4 comprising writing a base value in a first part (MSA) of the shadow meta segment (MSAM) and the first value indicative of the size (L) of the memory block (AM) in a second part (MSB) of the shadow meta segment (MSAM).
 
6. The computer-implemented method for encoding an application memory of any of claim 4 or 5 wherein the base value is zero and the second value (OFF1, OFF2, OFF3, ..., OFFN) is equal to the offset from the base address of the shadow memory block (SM) to the segment's base address incremented by one.
 
7. The computer-implemented method for encoding an application memory of any of the preceding claims wherein the second value (OFF1, OFF2, OFF3, ..., OFFN) is written in a first part (S1A, S2A, S3A, ..., SNA) of a shadow segment having the same size as the first part (MSA) of a meta segment.
 
8. The computer-implemented method for encoding an application memory of claim 7 comprising writing (203), in a second part (S1B, S2B, S3B, ..., SNB) of each shadow segment (S1SM, S2SM, S3SM, ..., SNSM), a third value (INIT1, INIT2, INIT3,... INITN) indicative of the initialization of all bytes of the corresponding segment (S1AM, S2AM, S3AM, ..., SNAM) in the application memory (AM).
 
9. The computer-implemented method for encoding an application memory of any of the preceding claims wherein the application memory comprises heap memory.
 
10. The computer-implemented method for encoding an application memory of any of the preceding claims comprising writing base values to the first part of each segment in a shadow memory block (SM) when a corresponding memory block (AM) in the application memory is de-allocated by the program.
 
11. A computer-implemented method for detecting illegal memory access by a program executed on a computer having a processor and an application memory, the method comprising:

- executing the method for encoding an application memory according to any of claims 1 to 10 and,

- when the program accesses to an address in an application memory block (AM), analyzing the shadow memory block (SM) to determine if the access is illegal.


 
12. The computer-implemented method for detecting illegal memory access of claim 11 wherein analyzing the shadow memory block (SM) to determine if the access is illegal comprises determining (501) the length (L) of the memory block (AM) and the offset of the address within the memory block (AM).
 
13. The computer-implemented method for detecting illegal memory access of claim 12 wherein determining if the access is illegal comprises comparing (502) the offset of the address within the memory block and the length (L) of the memory block.
 
14. The computer-implemented method for detecting illegal memory access of claim 12 wherein the address is equal to a base address plus an offset value and determining if the access is illegal comprises comparing (502) the offset of the base address within the memory block plus the length (L) of the memory block with the offset value.
 
15. The computer-implemented method for detecting illegal memory access of any of claims 12 to 14 wherein determining if the access is illegal comprises reading the value of the segment offset in the shadow segment to which the address belongs and comparing said value with a base value.
 
16. The computer-implemented method for detecting illegal memory access of any of claims 12 to 15 wherein determining the length of the memory block comprises:

- Determining (301) the offset of the address relative to the base address of the segment it belongs to,

- Determining (302) the base address of the segment to which the address belongs,

- Determining (303) the base address of the corresponding shadow segment,

- Determining (304) the segment offset by reading a value at the base address of the shadow segment,

- Determining (305) the base address of the shadow memory block,

- Determining (306) the length of the memory block by reading the shadow meta segment of the shadow memory block.


 
17. The computer-implemented method for detecting illegal memory access of any of claims 12 to 16 wherein determining the offset of the address within the memory block comprises:

- Determining (301) the offset of the address relative to the base address of the segment it belongs to,

- Determining (302) the base address of the segment to which the address belongs,

- Determining (303) the base address of the corresponding shadow segment,

- Determining (304) the segment offset by reading a value at the base address of the shadow segment,

- Determining (305) the base address of the shadow memory block,

- Determining (307) the base address of the corresponding memory block,

- Determining (308) the offset of the address within the memory block.


 
18. The computer-implemented method for detecting illegal memory access according to any of claims 9 to 17 comprising determining (503) if the address is initialized by evaluating the third value in the second part of the shadow segment corresponding to the segment to which the address belongs.
 
19. A system comprising an application memory and a processor configured to execute the steps of any of the computer-implemented methods of any of claims 1 to 18.
 
20. A computer program product, comprising computer-executable instructions which, when said computer program is executed by a processor, cause the processor to carry out the computer-implemented method of any of claims 1 to 18.
 


Ansprüche

1. Computerimplementiertes Verfahren zum Codieren eines Anwendungsspeichers, auf den ein auf einem Computer ausgeführtes Programm Zugriff hat, unter Verwendung eines Schattenspeichers entsprechend dem Anwendungsspeicher, wobei das Verfahren Folgendes umfasst:

- Erzeugen und Initialisieren eines Schattenspeichers, der in eine Mehrzahl von Segmenten unterteilt ist, wobei jedes Segment in dem Anwendungsspeicher auf ein entsprechendes Segment im Schattenspeicher abgebildet wird,

- Codieren, für jeden Speicherblock (AM) im Anwendungsspeicher, den das Programm zuweist, eines entsprechenden Schattenspeicherblocks (SM) im Schattenspeicher durch:

• Definieren (201) eines Metasegments (MSAM), das dem ersten Segment (S1AM) des Speicherblocks (AM) im Anwendungsspeicher vorausgeht, und eines entsprechenden Schatten-Metasegments (MSSM) in dem Schattenspeicherblock (SM),

gekennzeichnet durch Schreiben (201), in das Schatten-Metasegment (MSSM), eines ersten Wertes, der die Größe (L) des Speicherblocks (AM) angibt,

• Schreiben (202), in jedes nachfolgende Segment (S1SM, S2SM, S3SM, ... SNSM) des Schattenspeicherblocks (SM), eines zweiten Wertes, der den Versatz (OFF1, OFF2, OFF3, ... OFFN) zwischen dem Segment (S1SM, S2SM, S3SM, ... SNSM) und dem ersten Segment (S1SM) des Schattenspeicherblocks (SM) angibt.


 
2. Computerimplementiertes Verfahren zum Codieren eines Anwendungsspeichers nach Anspruch 1, wobei der zweite Wert (OFF1, OFF2, OFF3, ..., OFFN) den Versatz zwischen der Basisadresse des Schattenspeicherblocks (SM) und der Basisadresse des Segments angibt.
 
3. Computerimplementiertes Verfahren zum Codieren eines Anwendungsspeichers nach einem der vorherigen Ansprüche, wobei ein Metasegment (MSAM) im Anwendungsspeicher als unzugewiesener Speicher reserviert wird.
 
4. Computerimplementiertes Verfahren zum Codieren eines Anwendungsspeichers nach einem der vorherigen Ansprüche, wobei der Schattenspeicher mit positiven oder Null-Basiswerten initialisiert wird.
 
5. Computerimplementiertes Verfahren zum Codieren eines Anwendungsspeichers nach Anspruch 4, das das Schreiben eines Basiswertes in einen ersten Teil (MSA) des Schatten-Metasegments (MSAM) und des ersten Wertes, der die Größe (L) des Speicherblocks (AM) angibt, in einen zweiten Teil (MSB) des Schatten-Metasegments (MSAM) umfasst.
 
6. Computerimplementiertes Verfahren zum Codieren eines Anwendungsspeichers nach Anspruch 4 oder 5, wobei der Basiswert Null ist und der zweite Wert (OFF1, OFF2, OFF3, ..., OFFN) gleich dem Versatz zwischen der Basisadresse des Schattenspeicherblocks (SM) und der Basisadresse des Segments inkrementiert um eins ist.
 
7. Computerimplementiertes Verfahren zum Codieren eines Anwendungsspeichers nach einem der vorherigen Ansprüche, wobei der zweite Wert (OFF1, OFF2, OFF3, ..., OFFN) in einen ersten Teil (S1A, S2A, S3A, ..., SNA) eines Schattensegments mit der gleichen Größe wie der erste Teil (MSA) eines Metasegments geschrieben wird.
 
8. Computerimplementiertes Verfahren zum Codieren eines Anwendungsspeichers nach Anspruch 7, das das Schreiben (203) eines dritten Wertes (INIT1, INIT2, INIT3, ... INITN), der die Initialisierung aller Bytes des entsprechenden Segments (S1AM, S2AM, S3AM, ..., SNAM) im Anwendungsspeicher (AM) anzeigt, in einen zweiten Teil (S1B, S2B, S3B, ..., SNB) jedes Schattensegments (S1SM, S2SM, S3SM, ..., SNSM) umfasst.
 
9. Computerimplementiertes Verfahren zum Codieren eines Anwendungsspeichers nach einem der vorherigen Ansprüche, wobei der Anwendungsspeicher Heap-Speicher umfasst.
 
10. Computerimplementiertes Verfahren zum Codieren eines Anwendungsspeichers nach einem der vorherigen Ansprüche, das das Schreiben von Basiswerten zum ersten Teil jedes Segments in einem Schattenspeicherblock (SM) umfasst, wenn die Zuweisung eines entsprechenden Speicherblocks (AM) im Anwendungsspeicher durch das Programm aufgehoben wird.
 
11. Computerimplementiertes Verfahren zum Erkennen eines illegalen Speicherzugriffs durch ein Programm, das auf einem Computer mit einem Prozessor und einem Anwendungsspeicher ausgeführt wird, wobei das Verfahren Folgendes beinhaltet:

- Ausführen des Verfahrens zum Codieren eines Anwendungsspeichers nach einem der Ansprüche 1 bis 10 und,

- Analysieren, wenn das Programm auf eine Adresse in einem Anwendungsspeicherblock (AM) zugreift, des Schattenspeicherblocks (SM), um festzustellen, ob der Zugriff illegal ist.


 
12. Computerimplementiertes Verfahren zum Erkennen eines illegalen Speicherzugriffs nach Anspruch 11, wobei das Analysieren des Schattenspeicherblocks (SM), um festzustellen, ob der Zugriff illegal ist, das Bestimmen (501) der Länge (L) des Speicherblocks (AM) und des Versatzes der Adresse in dem Speicherblock (AM) umfasst.
 
13. Computerimplementiertes Verfahren zum Erkennen eines illegalen Speicherzugriffs nach Anspruch 12, wobei das Feststellen, ob der Zugriff illegal ist, das Vergleichen (502) des Versatzes der Adresse in dem Speicherblock und der Länge (L) des Speicherblocks umfasst.
 
14. Computerimplementiertes Verfahren zum Erkennen eines illegalen Speicherzugriffs nach Anspruch 12, wobei die Adresse gleich einer Basisadresse plus einem Versatzwert ist, und das Feststellen, ob der Zugriff illegal ist, das Vergleichen (502) des Versatzes der Basisadresse in dem Speicherblock plus der Länge (L) des Speicherblocks mit dem Versatzwert umfasst.
 
15. Computerimplementiertes Verfahren zum Erkennen eines illegalen Speicherzugriffs nach einem der Ansprüche 12 bis 14, wobei das Feststellen, ob der Zugriff illegal ist, das Lesen des Wertes des Segmentversatzes in dem Schattensegment, zu dem die Adresse gehört, und das Vergleichen dieses Wertes mit einem Basiswert beinhaltet.
 
16. Computerimplementiertes Verfahren zum Erkennen eines illegalen Speicherzugriffs nach einem der Ansprüche 12 bis 15, wobei das Bestimmen der Länge des Speicherblocks Folgendes umfasst:

- Bestimmen (301) des Versatzes der Adresse relativ zur Basisadresse des Segments, zu dem sie gehört,

- Bestimmen (302) der Basisadresse des Segments, zu dem die Adresse gehört,

- Bestimmen (303) der Basisadresse des entsprechenden Schattensegments,

- Bestimmen (304) des Segmentversatzes durch Lesen eines Wertes an der Basisadresse des Schattensegments,

- Bestimmen (305) der Basisadresse des Schattenspeicherblocks,

- Bestimmen (306) der Länge des Speicherblocks durch Lesen des Schatten-Metasegments des Schattenspeicherblocks.


 
17. Computerimplementiertes Verfahren zum Erkennen eines illegalen Speicherzugriffs nach einem der Ansprüche 12 bis 16, wobei das Bestimmen des Versatzes der Adresse in dem Speicherblock Folgendes umfasst:

- Bestimmen (301) des Versatzes der Adresse relativ zur Basisadresse des Segments, zu dem sie gehört,

- Bestimmen (302) der Basisadresse des Segments, zu dem die Adresse gehört,

- Bestimmen (303) der Basisadresse des entsprechenden Schattensegments,

- Bestimmen (304) des Segmentversatzes durch Lesen eines Wertes an der Basisadresse des Schattensegments,

- Bestimmen (305) der Basisadresse des Schattenspeicherblocks,

- Bestimmen (307) der Basisadresse des entsprechenden Speicherblocks,

- Bestimmen (308) des Versatzes der Adresse innerhalb des Speicherblocks.


 
18. Computerimplementiertes Verfahren zum Erkennen eines illegalen Speicherzugriffs nach einem der Ansprüche 9 bis 17, das das Feststellen (503) umfasst, ob die Adresse initialisiert ist, durch Beurteilen des dritten Wertes im zweiten Teil des Schattensegments, das dem Segment entspricht, zu dem die Adresse gehört.
 
19. System umfassend einen Anwendungsspeicher und einen Prozessor, konfiguriert zum Ausführen der Schritte eines beliebigen der computerimplementierten Verfahren nach einem der Ansprüche 1 bis 18.
 
20. Computerprogrammprodukt umfassend computerausführbare Befehle, die bei Ausführung des Computerprogramms durch einen Prozessor bewirken, dass der Prozessor das computerimplementierte Verfahren nach einem der Ansprüche 1 bis 18 ausführt.
 


Revendications

1. Procédé mis en œuvre par ordinateur pour l'encodage d'une mémoire d'application auquel un programme, exécuté sur un ordinateur, a accès, en utilisant une mémoire fantôme correspondant à la mémoire d'application, le procédé comprenant:

- la création et l'initialisation d'une mémoire fantôme divisée en une pluralité de segments, chaque segment dans la mémoire d'application étant mappé à un segment correspondant dans la mémoire fantôme,

- pour chaque bloc de mémoire (AM) dans la mémoire d'application que le programme alloue, l'encodage d'un bloc de mémoire fantôme (SM) correspondant, dans la mémoire fantôme, en:

• définissant (201) un métasegment (MSAM) précédant le premier segment (S1AM) du bloc de mémoire (AM) dans la mémoire d'application, et un métasegment fantôme (MSSM) correspondant dans le bloc de mémoire fantôme (SM),

caractérisé par l'écriture (201) dans le métasegment fantôme (MSSM) d'une première valeur indiquant la taille (L) du bloc de mémoire (AM),

• l'écriture (202), dans chaque segment (S1SM, S2SM, S3SM, ..., SNSM) suivant du bloc de mémoire fantôme (SM), une seconde valeur indiquant le décalage (OFF1, OFF2, OFF3, ..., OFFN) entre le segment (S1SM, S2SM, S3SM, ..., SNSM) et le premier segment (S1SM) du bloc de mémoire fantôme (SM).


 
2. Procédé mis en œuvre par ordinateur pour l'encodage d'une mémoire d'application selon la revendication 1, la seconde valeur (OFF1, OFF2, OFF3, ..., OFFN) indiquant le décalage entre l'adresse de base du bloc de mémoire fantôme (SM) et l'adresse de base du segment.
 
3. Procédé mis en œuvre par ordinateur pour l'encodage d'une mémoire d'application selon l'une quelconque des revendications précédentes, un métasegment (MSAM) dans la mémoire d'application étant réservé en tant que mémoire non allouée.
 
4. Procédé mis en œuvre par ordinateur pour l'encodage d'une mémoire d'application selon l'une quelconque des revendications précédentes, la mémoire fantôme étant initialisée avec des valeurs de base positives ou nulles.
 
5. Procédé mis en œuvre par ordinateur pour l'encodage d'une mémoire d'application selon la revendication 4, comprenant l'écriture d'une valeur de base dans une première partie (MSA) du métasegment fantôme (MSAM) et de la première valeur indiquant la taille (L) du bloc de mémoire (AM) dans une seconde partie (MSB) du métasegment fantôme (MSAM).
 
6. Procédé mis en œuvre par ordinateur pour l'encodage d'une mémoire d'application selon l'une quelconque des revendications 4 ou 5, la valeur de base étant nulle et la seconde valeur (OFF1, OFF2, OFF3, ..., OFFN) étant égale au décalage entre l'adresse de base du bloc de mémoire fantôme (SM) et l'adresse de base du segment incrémenté de un.
 
7. Procédé mis en œuvre par ordinateur pour l'encodage d'une mémoire d'application selon l'une quelconque des revendications précédentes, la seconde valeur (OFF1, OFF2, OFF3, ..., OFFN) étant écrite dans une première partie (S1A, S2A, S3A, ..., SNA) d'un segment fantôme ayant la même taille que la première partie (MSA) d'un métasegment.
 
8. Procédé mis en œuvre par ordinateur pour l'encodage d'une mémoire d'application selon la revendication 7, comprenant l'écriture (203), dans une seconde partie (S1B, S2B, S3B, ..., SNB) de chaque segment fantôme (S1SM, S2SM, S3SM, ..., SNSM), d'une troisième valeur (INIT1, INIT2, INIT3, ..., INITN) indiquant l'initialisation de tous les bytes du segment correspondant (S1AM, S2AM, S3AM, ..., SNAM) dans la mémoire d'application (AM).
 
9. Procédé mis en œuvre par ordinateur pour l'encodage d'une mémoire d'application selon l'une quelconque des revendications précédentes, la mémoire d'application comprenant une mémoire en tas.
 
10. Procédé mis en œuvre par ordinateur pour l'encodage d'une mémoire d'application selon l'une quelconque des revendications précédentes, comprenant l'écriture des valeurs de base à la première partie de chaque segment dans un bloc de mémoire fantôme (SM) lorsqu'un bloc de mémoire (AM) correspondant dans la mémoire d'application est désalloué par le programme.
 
11. Procédé mis en œuvre par ordinateur pour la détection d'accès de mémoire illégal par un programme exécuté sur un ordinateur ayant un processeur et une mémoire d'application, le procédé comprenant:

- l'exécution du procédé pour l'encodage d'une mémoire d'application selon l'une quelconque des revendications 1 à 10 et,

- lorsque le programme accède à une adresse dans un bloc de mémoire d'application (AM), l'analyse du bloc de mémoire fantôme (SM) pour déterminer si l'accès est illégal.


 
12. Procédé mis en œuvre par ordinateur pour la détection d'accès de mémoire illégal selon la revendication 11, l'analyse du bloc de mémoire fantôme (SM) pour déterminer si l'accès est illégal comprenant la détermination (501) de la longueur (L) du bloc de mémoire (AM) et le décalage de l'adresse au sein du bloc de mémoire (AM).
 
13. Procédé mis en œuvre par ordinateur pour la détection d'accès de mémoire illégal selon la revendication 12, la détermination de si l'accès est ou n'est pas illégal comprenant la comparaison (502) du décalage de l'adresse au sein du bloc de mémoire et la longueur (L) du bloc de mémoire.
 
14. Procédé mis en œuvre par ordinateur pour la détection d'accès de mémoire illégal selon la revendication 12, l'adresse étant égale à une adresse de base plus une valeur de décalage et la détermination du fait que l'accès est ou n'est pas illégal comprenant la comparaison (502) du décalage de l'adresse de base au sein du bloc de mémoire plus la longueur (L) du bloc de mémoire à la valeur de décalage.
 
15. Procédé mis en œuvre par ordinateur pour la détection d'accès de mémoire illégal selon l'une quelconque des revendications 12 à 14, la détermination du fait que l'accès est ou n'est pas illégal comprenant la lecture de la valeur du décalage de segment dans le segment fantôme auquel l'adresse appartient et la comparaison de ladite valeur à la valeur de base.
 
16. Procédé mis en œuvre par ordinateur pour la détection d'accès de mémoire illégal selon l'une quelconque des revendications 12 à 15, la détermination de la longueur du bloc de mémoire comprenant:

- la détermination (301) du décalage de l'adresse par rapport à l'adresse de base du segment auquel elle appartient,

- la détermination (302) de l'adresse de base du segment auquel l'adresse appartient,

- la détermination (303) de l'adresse de base du segment fantôme correspondant,

- la détermination (304) du décalage de segment en lisant une valeur à l'adresse de base du segment fantôme,

- la détermination (305) de l'adresse de base du bloc de mémoire fantôme,

- la détermination (306) de la longueur du bloc de mémoire en lisant le métasegment fantôme du bloc de mémoire fantôme.


 
17. Procédé mis en œuvre par ordinateur pour la détection d'accès de mémoire illégal selon l'une quelconque des revendications 12 à 16, la détermination du décalage de l'adresse au sein du bloc de mémoire comprenant:

- la détermination (301) du décalage de l'adresse par rapport à l'adresse de base du segment auquel elle appartient,

- la détermination (302) de l'adresse de base du segment auquel l'adresse appartient,

- la détermination (303) de l'adresse de base du segment fantôme correspondant,

- la détermination (304) du décalage de segment en lisant une valeur à l'adresse de base du segment fantôme,

- la détermination (305) de l'adresse de base du bloc de mémoire fantôme,

- la détermination (307) de l'adresse de base du bloc de mémoire correspondant,

- la détermination (308) du décalage de l'adresse au sein du bloc de mémoire.


 
18. Procédé mis en œuvre par ordinateur pour la détection d'accès de mémoire illégal selon l'une quelconque des revendications 9 à 17, comprenant la détermination (503) du fait que l'adresse est ou n'est pas initialisée en évaluant la troisième valeur dans la seconde partie du segment fantôme correspondant au segment auquel l'adresse appartient.
 
19. Système comprenant une mémoire d'application et un processeur configuré pour exécuter les étapes selon l'un quelconque des procédés mis en œuvre par ordinateur selon l'une quelconque des revendications 1 à 18.
 
20. Programme informatique, comprenant des instructions exécutables par ordinateur qui, lorsque ledit programme informatique est exécuté par un processeur, forcent le processeur à réaliser le procédé mis en œuvre par ordinateur selon l'une quelconque des revendications 1 à 18.
 




Drawing
































Cited references

REFERENCES CITED IN THE DESCRIPTION



This list of references cited by the applicant is for the reader's convenience only. It does not form part of the European patent document. Even though great care has been taken in compiling the references, errors or omissions cannot be excluded and the EPO disclaims all liability in this regard.

Patent documents cited in the description




Non-patent literature cited in the description