<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>Graph models of memory access traces</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Dušan Bernát</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Matúš Hluch</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>FMFI UK</institution>
          ,
          <addr-line>Bratislava</addr-line>
          ,
          <country country="SK">Slovakia</country>
        </aff>
      </contrib-group>
      <pub-date>
        <year>2024</year>
      </pub-date>
      <abstract>
        <p>This paper describes proposal of a method to analyse memory access traces of a process. It is based on record of all addresses which a process generates by memory access during its run time. The process address trace is subsequently represented by a graph structure suitable for further analysis by a variety of available graph and network tools. Preliminary results proved such approach to be useful when detecting whether dynamical linking was used by a process.</p>
      </abstract>
      <kwd-group>
        <kwd>eol&gt;memory address trace</kwd>
        <kwd>graph representation</kwd>
        <kwd>graph invariant</kwd>
        <kwd>strongly connected component</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>1. Introduction</title>
      <p>
        While executing a program, processor makes at least one
memory access to fetch each instruction and additional
access to load or store a data is possible. It is a well known
that a sequence of all addresses accessed by a process
does not have a uniform distribution. Rather it exhibits
various patterns, which were recognised and studied in
1970s by Denning [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ].
1.1. Locality principles
process. In our work we use Intel’s binary PIN tool [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ],
which by means of code instrumentation and various
plug-in modules allows to record information about each
memory access that a process makes. Particularly,
modules pinatrace and itrace executes call-back function
which might record the address of instruction, load or
store access type, and the address of memory operand
if any. Further modification of the modules allows to
store to a separate output files also the binary code of the
instruction or the mappings of memory regions used by
the process.
      </p>
      <p>
        The basic patterns are known as principles of locality
[
        <xref ref-type="bibr" rid="ref2">2</xref>
        ], namely sequential, spatial and time locality. On the 2.1. Graph representation
one hand, these principles are natural consequences of The main output file contains sequence of all addresses
how processors execute instructions, how processes use accessed by a process in the text hexadecimal form, one
a stack for passing arguments and storing local variables, per line. Thus in a raw form the file might get too large
or how algorithms process a data in general. On the other and hard to manipulate. We conjecture, that essential
hand, locality in address sequences allows to construct information is contained in the graph structure, which
highly eficient memory systems, which is very eficient can be constructed by assigning a vertex to each unique
while the fastest memory, registers, are expensive and address and connecting two vertices by a directed edge,
scarce and high volume memory storage is relatively whenever the two addresses lies on consecutive lines.
slow. This is because an average process, a typical useful Vertices of such graph can be labelled by the address,
algorithm, does not need all its data at once. Exploita- edges can be labeled by the number of occurrences of
tion of patterns in memory access led to development of a corresponding address pair. As a typical program is
demand paging [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ], [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ], utilisation of data prefetching or also comprised of loops, the labeled graph representation
LRU (Least recently used) data replacement algorithm on can be (at least in principle) smaller than the complete
various hierarchy levels, e.g. cache lines, memory pages, address trace. Although the original addresses might be
disk blocks. useful when analysing execution of particular process,
the graph structure itself can represent some more
gen2. Address trace recording eral properties of the program. Moreover, the addresses
can change in each run of the same program due to
security measures imposed by operating systems, for example
ASLR (Address space layout randomisation).
      </p>
      <p>Emulation and virtualisation provide several
possibilities of recording partial or complete address trace of a</p>
      <sec id="sec-1-1">
        <title>2.2. Graph properties</title>
        <p>
          Without lost of information, further reduction of the
graph can be achieved by squeezing a sequence of
equidistant addresses to a block designated by only the first and
the last address of the sequence. These blocks are called All programs tested in [
          <xref ref-type="bibr" rid="ref7">7</xref>
          ] contained several
singlebasic blocks Sequence is, of course, the very basic pro- ton strongly connected components and one component
gramming construct present in any program. However, containing rest of the vertices in the trace graphs for
a sequence of instructions need not to generate accesses data memory access. For the instruction addresses, the
to consecutive memory addresses. Moreover, this prop- structure was similar, but apart from one big
compoerty depends on the processor architecture. Processors nent there were always components composed of 37,
of CISC types may have variable instruction size, so they 31, and 10 vertices. Using the additional stored
inforcan yield subsequent instruction addresses distances from mation about memory region mappings (it is found in
one to fifteen bytes (e.g. for Pentium based platforms). /proc/self/maps during run-time), as mentioned in
RISC processors usually have fixed instruction code size, section 2, it was possible to identify the addresses with
which creates a regular pattern of instruction sequences, the code of dynamical linker. Particularly, on an x86_64
as program counter register increments with each instruc- Linux system, the addresses belong to range mapped to
tion except of branches. With RISCs, there are usually ifle ld-linux-x86-64.so.2. The experiment was
reonly two instructions for data memory transfers (load- peated on an arm based Raspberry Pi system. The graph
/store). All ALU operations are performed on registers structure looked very similar, it showed three strongly
so data memory access might occur rarely. On the other connected components with orders 35, 28, 7. Addresses
hand, a CISC type processor allows many instructions to forming these components belong to the range mapped
operate on memory, thus addresses of instructions can to the file ld-2.28.so. All tested statically linked
probe overlapped by data addresses more frequently. grams lack such structure. Thus it is possible to conclude
        </p>
        <p>Processors from CISC family, notably there is only one that presence of the three strongly connected
compomajor representative, the Intel compatible ones, allow for nents of this precise size determined by the platform,
repeated execution of one single instruction, particularly means that the running process uses the dynamic linker.
the string instructions, by means of so called instruc- Usually, using a dynamic linker for system utilities is a
tion prefix ( rep repeating until CX register reaches zero, standard. Conversely, fake malicious programs
pretendor alternatively, conditional variants REPZ/REPNZ check ing to be a legitimate utilities are often statically linked to
also for other flags). This generates a special pattern all necessary libraries in order to minimise dependency
of repeated single instruction address several times, so on target system. Thus missing the proper three
concorresponding graph will comprise a loop edge on the nected components from the memory access graph can
vertex with given instruction address. imply an attempt to exchange original program file with</p>
        <p>All of these observations can be used to characterise a malware. Anyway, this can be considered a suspicious
the architecture based on the graph properties only. condition and can serve as one of the inputs to a more
complex security system (e.g. an IDS).</p>
      </sec>
    </sec>
    <sec id="sec-2">
      <title>3. Trace analysis as security measure</title>
      <p>
        Using memory traces for detection of program failures,
like bufer overflows or other corruptions, or detection
of malicious activity like directing control flow to area
iflled with user provided data, is well established field of
research, e.g. see [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ]. In his bachelor thesis, M. Hluch [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ]
revealed that some property of the graph created from
memory trace, particularly strongly connected
components, always coincided with the way of linking which
the program uses.
      </p>
    </sec>
    <sec id="sec-3">
      <title>4. Conclusion</title>
      <p>We described the procedure of creating directed graphs
from complete memory address trace of a process. We
conjecture that properties of this abstract structure – the
graph, can indicate possible security risk. The main result
is that presence of three strongly connected components
of prescribed size is related to usage of a dynamic linker
by the examined program. Absence of these strongly
connected components thus may have implications for
the security of the system.</p>
      <sec id="sec-3-1">
        <title>3.1. Strongly connected components</title>
      </sec>
    </sec>
    <sec id="sec-4">
      <title>Acknowledgments</title>
      <p>As we mentioned above, the control flow of process in- This publication is the result of support under the
duces an orientation on edges of the memory trace graph. Operational Program Integrated Infrastructure for the
The graph  is called strongly connected if there exists a project: Advancing University Capacity and
Compepath between each pair of vertices, regarding the direc- tence in Research, Development a Innovation (ACCORD,
tion of edges. A strongly connected component of graph ITMS2014+:313021X329), co-financed by the European
is a maximal subgraph of  which is strongly connected. Regional Development Fund.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <surname>Peter</surname>
            <given-names>J. Denning.</given-names>
          </string-name>
          <article-title>The locality principle</article-title>
          .
          <source>Commun. ACM</source>
          ,
          <volume>48</volume>
          (
          <issue>7</issue>
          ):
          <fpage>19</fpage>
          -
          <lpage>24</lpage>
          ,
          <year>July 2005</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <surname>Jefrey</surname>
            <given-names>R.</given-names>
          </string-name>
          <string-name>
            <surname>Spirn</surname>
          </string-name>
          and
          <string-name>
            <surname>Peter J. Denning</surname>
          </string-name>
          .
          <article-title>Experiments with program locality</article-title>
          .
          <source>In Proceedings of the December 5-7</source>
          ,
          <year>1972</year>
          , Fall Joint Computer Conference,
          <string-name>
            <surname>Part</surname>
            <given-names>I</given-names>
          </string-name>
          , AFIPS '
          <volume>72</volume>
          (Fall,
          <string-name>
            <surname>part I</surname>
          </string-name>
          ), page
          <fpage>611</fpage>
          -
          <lpage>621</lpage>
          , New York, NY, USA,
          <year>1972</year>
          .
          <article-title>Association for Computing Machinery</article-title>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <surname>Peter</surname>
            <given-names>J. Denning.</given-names>
          </string-name>
          <article-title>The working set model for program behavior</article-title>
          .
          <source>Communications of the ACM</source>
          ,
          <volume>11</volume>
          (
          <issue>5</issue>
          ):
          <fpage>323</fpage>
          -
          <lpage>333</lpage>
          ,
          <year>1968</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4]
          <string-name>
            <surname>Andrew</surname>
            <given-names>S.</given-names>
          </string-name>
          <string-name>
            <surname>Tanenbaum</surname>
          </string-name>
          . Operating Systems: Design and
          <string-name>
            <surname>Implementation (Second Edition)</surname>
          </string-name>
          . New Jersey: Prentice-Hall
          <year>1997</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          <article-title>[5] Intel's web pages. Pin - A Dynamic Binary Instrumentation Tool</article-title>
          , URL: https://www.intel. com/content/www/us/en/developer/articles/tool/ pin
          <article-title>-a-dynamic-binary-instrumentation-tool</article-title>
          .html, accessed on 2024-
          <volume>07</volume>
          -11.
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          [6]
          <string-name>
            <given-names>Zhixing</given-names>
            <surname>Xu</surname>
          </string-name>
          ,
          <string-name>
            <given-names>Aarti</given-names>
            <surname>Gupta</surname>
          </string-name>
          , and
          <string-name>
            <given-names>Sharad</given-names>
            <surname>Malik</surname>
          </string-name>
          .
          <article-title>Tracebased analysis of memory corruption malware attacks</article-title>
          .
          <source>In Ofer Strichman and Rachel</source>
          Tzoref-Brill, editors,
          <source>Hardware and Software: Verification and Testing</source>
          , pages
          <fpage>67</fpage>
          -
          <lpage>82</lpage>
          , Cham,
          <year>2017</year>
          . Sprin- ger International Publishing.
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          [7]
          <string-name>
            <given-names>Matúš</given-names>
            <surname>Hluch</surname>
          </string-name>
          .
          <article-title>Detekcia vzorov správania procesu v postupnosti adries. (Bachelor thesis supervised by D. Bernát</article-title>
          .) Department of Computer Science.
          <source>Faculty of Mathematics, Physics and Informatics</source>
          . Comenius University, Bratislava, Slovakia.
          <year>2022</year>
          .
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>