<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<title>elias::posts</title>
	<subtitle>My contribution to the delay of the dead internet</subtitle>
	<link rel="self" type="application/atom+xml" href="https://elias.amsterdam/posts/feed.xml"/>
  <link rel="alternate" type="text/html" href="https://elias.amsterdam/posts/"/>
  
	<updated>2026-01-21T00:00:00+00:00</updated>
	
	<id>https://elias.amsterdam/posts/feed.xml</id>
	<entry xml:lang="en">
		<title>Managing Information Leaks in the Spectre Era</title>
		<published>2026-01-21T00:00:00+00:00</published>
		<updated>2026-01-21T00:00:00+00:00</updated>
		<link rel="alternate" type="text/html" href="https://elias.amsterdam/posts/odi/"/>
		<id>https://elias.amsterdam/posts/odi/</id>
    
		<content type="html" xml:base="https://elias.amsterdam/posts/odi/">&lt;p&gt;&lt;strong&gt;As the final semester is about to kick off, I too have to face finishing up my Master&#x27;s degree with a thesis. Fortunately for me, many topics in the field of security engineering align closely to my professional work and personal interests, so that I can write about them here. This post marks the start of a series of posts that cover the process of researching and prototyping &lt;em&gt;object-based data isolation&lt;&#x2F;em&gt;.&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;p&gt;In the world of systems security, temporal and spatial memory errors have long been the leading cause of actively exploited software vulnerabilities, and there seems no reason to assume &lt;a rel=&quot;nofollow noreferrer&quot; href=&quot;https:&#x2F;&#x2F;cwe.mitre.org&#x2F;top25&#x2F;archive&#x2F;2024&#x2F;2024_kev_insights.html&quot;&gt;that this will change any time soon&lt;&#x2F;a&gt;. These errors mostly stem from the fact that many systems rely on memory that is managed manually by the programmer, and the programmer can make mistakes. The desire for manual memory management is in turn based on the idea that systems should be fast and memory-efficient, and that only by manually managing memory, one can optimally allocate the available resources to meet the ever-increasing performance requirements.&lt;&#x2F;p&gt;
&lt;p&gt;Despite increasing adoption trends in languages that discourage manual memory management (such as garbage collection in Go and C#), and languages that try to verify that memory management is performed safely (such as Rust&#x27;s borrow-checker), many systems that are in production today still rely on codebases that consist largely of &lt;em&gt;unsafe&lt;&#x2F;em&gt; C and C++ code. One option is to migrate (crucial) systems to &lt;em&gt;safer&lt;&#x2F;em&gt; languages - this is part of my professional work - but unfortunately, this is hard to scale and cannot be done in one night, one year or even one decade (&lt;a rel=&quot;nofollow noreferrer&quot; href=&quot;https:&#x2F;&#x2F;www.linkedin.com&#x2F;feed&#x2F;update&#x2F;urn:li:activity:7407863239289729024&#x2F;&quot;&gt;despite what some Microsoft engineers seem to think&lt;&#x2F;a&gt;). As such, much research is dedicated to finding new solutions for existing systems and codebases, to detect (and possibly mitigate) memory errors &lt;em&gt;at the scale of thousands to millions of lines of code&lt;&#x2F;em&gt;.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;architectural-information-leaks&quot;&gt;Architectural Information Leaks&lt;a class=&quot;zola-anchor&quot; href=&quot;#architectural-information-leaks&quot; aria-label=&quot;Anchor link for: architectural-information-leaks&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;&#x2F;a&gt;
&lt;&#x2F;h1&gt;
&lt;p&gt;Software vulnerabilities are heterogeneous in both their forms and effects, but in general the exploitation goal is to &quot;bypass a security policy&quot;. This is often referred to as violating the &lt;em&gt;CIA&lt;&#x2F;em&gt; triangle: breaking &lt;em&gt;confidentiality&lt;&#x2F;em&gt;, &lt;em&gt;integrity&lt;&#x2F;em&gt;, &lt;em&gt;availability&lt;&#x2F;em&gt; or a combination thereof. In this work, I am particularly interested in mitigating &lt;em&gt;information leaks&lt;&#x2F;em&gt; that breach confidentiality.&lt;&#x2F;p&gt;
&lt;p&gt;Such information leaks are often associated with the aforementioned memory errors. Common cases include buffer overreads and use-after-free vulnerabilities.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;c&quot; class=&quot;language-c z-code&quot;&gt;&lt;code class=&quot;language-c&quot; data-lang=&quot;c&quot;&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-storage z-type z-c&quot;&gt;void&lt;&#x2F;span&gt; &lt;span class=&quot;z-meta z-function z-c&quot;&gt;&lt;span class=&quot;z-entity z-name z-function z-c&quot;&gt;buffer_overread&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function z-parameters z-c&quot;&gt;&lt;span class=&quot;z-meta z-group z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-section z-group z-begin z-c&quot;&gt;(&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function z-parameters z-c&quot;&gt;&lt;span class=&quot;z-meta z-group z-c&quot;&gt;&lt;span class=&quot;z-storage z-type z-c&quot;&gt;char&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator z-c&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;z-variable z-parameter z-c&quot;&gt;dest&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-c&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;z-storage z-type z-c&quot;&gt;int&lt;&#x2F;span&gt; &lt;span class=&quot;z-variable z-parameter z-c&quot;&gt;len&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-section z-group z-end z-c&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function z-c&quot;&gt; &lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-section z-block z-begin z-c&quot;&gt;{&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;
&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-meta z-function z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;    &lt;span class=&quot;z-storage z-type z-c&quot;&gt;char&lt;&#x2F;span&gt; public_data&lt;span class=&quot;z-meta z-brackets z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-section z-brackets z-begin z-c&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric z-integer z-decimal z-c&quot;&gt;16&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-section z-brackets z-end z-c&quot;&gt;]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-terminator z-c&quot;&gt;;&lt;&#x2F;span&gt;
&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-meta z-function z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;
&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-meta z-function z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;    &lt;span class=&quot;z-comment z-line z-double-slash z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-c&quot;&gt;&#x2F;&#x2F;&lt;&#x2F;span&gt; No bounds check, so might copy more than 16 bytes
&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-meta z-function z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;    &lt;span class=&quot;z-comment z-line z-double-slash z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-c&quot;&gt;&#x2F;&#x2F;&lt;&#x2F;span&gt; information leak!
&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-meta z-function z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;    &lt;span class=&quot;z-meta z-function-call z-c&quot;&gt;&lt;span class=&quot;z-support z-function z-C99 z-c&quot;&gt;memcpy&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-group z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-section z-group z-begin z-c&quot;&gt;(&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-c&quot;&gt;&lt;span class=&quot;z-meta z-group z-c&quot;&gt;dest&lt;span class=&quot;z-punctuation z-separator z-c&quot;&gt;,&lt;&#x2F;span&gt; public_data&lt;span class=&quot;z-punctuation z-separator z-c&quot;&gt;,&lt;&#x2F;span&gt; len&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-c&quot;&gt;&lt;span class=&quot;z-meta z-group z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-section z-group z-end z-c&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-terminator z-c&quot;&gt;;&lt;&#x2F;span&gt;
&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-meta z-function z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-section z-block z-end z-c&quot;&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;pre data-lang=&quot;c&quot; class=&quot;language-c z-code&quot;&gt;&lt;code class=&quot;language-c&quot; data-lang=&quot;c&quot;&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-storage z-type z-c&quot;&gt;int&lt;&#x2F;span&gt;&lt;span class=&quot;z-keyword z-operator z-c&quot;&gt;*&lt;&#x2F;span&gt; &lt;span class=&quot;z-meta z-function z-c&quot;&gt;&lt;span class=&quot;z-entity z-name z-function z-c&quot;&gt;uaf&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function z-parameters z-c&quot;&gt;&lt;span class=&quot;z-meta z-group z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-section z-group z-begin z-c&quot;&gt;(&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function z-parameters z-c&quot;&gt;&lt;span class=&quot;z-meta z-group z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-section z-group z-end z-c&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function z-c&quot;&gt; &lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-section z-block z-begin z-c&quot;&gt;{&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;
&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-meta z-function z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;    &lt;span class=&quot;z-storage z-type z-c&quot;&gt;int&lt;&#x2F;span&gt; &lt;span class=&quot;z-keyword z-operator z-c&quot;&gt;*&lt;&#x2F;span&gt;secret_storage &lt;span class=&quot;z-keyword z-operator z-assignment z-c&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;z-meta z-function-call z-c&quot;&gt;&lt;span class=&quot;z-support z-function z-C99 z-c&quot;&gt;malloc&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-group z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-section z-group z-begin z-c&quot;&gt;(&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-c&quot;&gt;&lt;span class=&quot;z-meta z-group z-c&quot;&gt;&lt;span class=&quot;z-keyword z-operator z-word z-c&quot;&gt;sizeof&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-group z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-section z-group z-begin z-c&quot;&gt;(&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-group z-c&quot;&gt;&lt;span class=&quot;z-storage z-type z-c&quot;&gt;int&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-group z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-section z-group z-end z-c&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-c&quot;&gt;&lt;span class=&quot;z-meta z-group z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-section z-group z-end z-c&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-terminator z-c&quot;&gt;;&lt;&#x2F;span&gt;
&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-meta z-function z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;    &lt;span class=&quot;z-keyword z-operator z-c&quot;&gt;*&lt;&#x2F;span&gt;secret_storage &lt;span class=&quot;z-keyword z-operator z-assignment z-c&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;z-constant z-numeric z-integer z-hexadecimal z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-numeric z-base z-c&quot;&gt;0x&lt;&#x2F;span&gt;babe&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-terminator z-c&quot;&gt;;&lt;&#x2F;span&gt; &lt;span class=&quot;z-comment z-line z-double-slash z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-c&quot;&gt;&#x2F;&#x2F;&lt;&#x2F;span&gt; some secret value
&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-meta z-function z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;    &lt;span class=&quot;z-meta z-function-call z-c&quot;&gt;&lt;span class=&quot;z-support z-function z-C99 z-c&quot;&gt;free&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-group z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-section z-group z-begin z-c&quot;&gt;(&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-c&quot;&gt;&lt;span class=&quot;z-meta z-group z-c&quot;&gt;secret_storage&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-c&quot;&gt;&lt;span class=&quot;z-meta z-group z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-section z-group z-end z-c&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-terminator z-c&quot;&gt;;&lt;&#x2F;span&gt;
&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-meta z-function z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;     
&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-meta z-function z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;    &lt;span class=&quot;z-comment z-line z-double-slash z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-c&quot;&gt;&#x2F;&#x2F;&lt;&#x2F;span&gt; Returns a pointer to memory that was freed
&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-meta z-function z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;    &lt;span class=&quot;z-comment z-line z-double-slash z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-c&quot;&gt;&#x2F;&#x2F;&lt;&#x2F;span&gt; users of this pointer may be able to recover the secret value
&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-meta z-function z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;    &lt;span class=&quot;z-comment z-line z-double-slash z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-c&quot;&gt;&#x2F;&#x2F;&lt;&#x2F;span&gt; information leak!
&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-meta z-function z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;    &lt;span class=&quot;z-keyword z-control z-flow z-return z-c&quot;&gt;return&lt;&#x2F;span&gt; secret_storage&lt;span class=&quot;z-punctuation z-terminator z-c&quot;&gt;;&lt;&#x2F;span&gt;
&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-meta z-function z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-section z-block z-end z-c&quot;&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;These types of vulnerabilities are well-known and well-understood, and arguably easy to spot in the trivial examples above. Yet, most production systems are highly complex, and memory allocations and accesses are often spaced far apart in both time and space. As such, it is hard and often infeasible to exhaustively identify memory errors from manual inspection or static analysis alone. This was confirmed once more by the recently published &lt;a rel=&quot;nofollow noreferrer&quot; href=&quot;https:&#x2F;&#x2F;nvd.nist.gov&#x2F;vuln&#x2F;detail&#x2F;CVE-2025-11979&quot;&gt;MongoDB buffer overread vulnerability&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;To identify information leaks at scale, research has hence been put towards building &lt;em&gt;memory sanitizers&lt;&#x2F;em&gt; that can detect memory errors at runtime. Implementations vary, but the common theme is to introduce additional metadata for allocations, frees and pointers that are then used in runtime validity checks. For example:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Introduce poisoned &lt;em&gt;redzones&lt;&#x2F;em&gt; around allocated memory. A buffer overread would then read a poison value, which would be detected&lt;&#x2F;li&gt;
&lt;li&gt;Mark pointers after being freed. When a pointer is reused, its mark is detected&lt;&#x2F;li&gt;
&lt;li&gt;Quarantine and poison freed memory so that it is not allocated again (immediately). A use-after-free would then read a poison value, which would then be detected&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;To allow for this, the program is instrumented at compile-time, and then runs with a modified memory allocator. When talked about memory sanitizers, Address Sanitizer (&lt;em&gt;ASan&lt;&#x2F;em&gt;) is often meant. It was introduced by Google in 2011, and became part of LLVM and GCC shortly after. From their &lt;a rel=&quot;nofollow noreferrer&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;google&#x2F;sanitizers&#x2F;wiki&#x2F;AddressSanitizerAlgorithm&quot;&gt;wiki&lt;&#x2F;a&gt;:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;The run-time library replaces the malloc and free functions. The memory around malloc-ed regions (red zones) is poisoned. The free-ed memory is placed in quarantine and also poisoned. Every memory access in the program is transformed by the compiler in the following way:&lt;&#x2F;p&gt;
&lt;p&gt;Before:&lt;&#x2F;p&gt;
&lt;pre class=&quot;z-code&quot;&gt;&lt;code&gt;&lt;span class=&quot;z-text z-plain&quot;&gt;*address = ...;  &#x2F;&#x2F; or: ... = *address;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;After:&lt;&#x2F;p&gt;
&lt;pre class=&quot;z-code&quot;&gt;&lt;code&gt;&lt;span class=&quot;z-text z-plain&quot;&gt;if (IsPoisoned(address)) {
&lt;&#x2F;span&gt;&lt;span class=&quot;z-text z-plain&quot;&gt;  ReportError(address, kAccessSize, kIsWrite);
&lt;&#x2F;span&gt;&lt;span class=&quot;z-text z-plain&quot;&gt;}
&lt;&#x2F;span&gt;&lt;span class=&quot;z-text z-plain&quot;&gt;*address = ...;  &#x2F;&#x2F; or: ... = *address;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;This instrumentation adds significant overhead in terms of memory (due to the additional metadata) and runtime (due to the additional checks). So significant even, that instrumented systems are rarely deployed in production, but rather only used when debugging and testing.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;sanitizing-at-scale&quot;&gt;Sanitizing At Scale&lt;a class=&quot;zola-anchor&quot; href=&quot;#sanitizing-at-scale&quot; aria-label=&quot;Anchor link for: sanitizing-at-scale&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;&#x2F;a&gt;
&lt;&#x2F;h2&gt;
&lt;p&gt;Even with a sanitizer that can accurately find memory errors for a given input, the input space is often enormous. To draw meaningful conclusion about memory safety, it is thus important to cover as much of this input space as possible. For this, industry has turned to conducting &lt;em&gt;fuzzing campaigns&lt;&#x2F;em&gt;. A &lt;em&gt;fuzzer&lt;&#x2F;em&gt; repeatedly feeds different inputs to a system and then relies on the sanitizer to decide if that particular input reveals memory errors. Sometimes fuzzers are described as &quot;random input generators&quot; but nowadays that rarely holds true. Similar to evolution in biology, modern fuzzers often rely on fitness (or rather, interestingness) to decide the inputs that they generate: interesting inputs are further mutated, while uninteresting inputs are discarded earlier on. To decide what is interesting, fuzzers can rely on white-box heuristics such as line or branch coverage, or utilize system-specific heuristics in a more black-box setting.&lt;&#x2F;p&gt;
&lt;p&gt;Two common methods exist to improve a fuzzer: (1) have it cover more inputs and (2) have it cover more &lt;em&gt;relevant&lt;&#x2F;em&gt; inputs. The latter can be done by improving a fuzzer&#x27;s input evolution algorithms or the heuristics they rely on. The first can be done by increasing a fuzzer&#x27;s throughput. Since fuzzers depend on memory sanitizers and memory sanitizers decrease throughput due to the overhead they introduce, much effort has been put into making memory sanitizers more efficient by improving on the &lt;a rel=&quot;nofollow noreferrer&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;HexHive&#x2F;FuZZan&quot;&gt;metadata that they store&lt;&#x2F;a&gt; or &lt;a rel=&quot;nofollow noreferrer&quot; href=&quot;https:&#x2F;&#x2F;5hadowblad3.github.io&#x2F;files&#x2F;asplos24-GiantSan.pdf&quot;&gt;optimizing their checks&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Recent work has improved on this by exploiting under-utilized exiisting hardware components (&lt;a rel=&quot;nofollow noreferrer&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;vusec&#x2F;floatzone&quot;&gt;FloatZone&lt;&#x2F;a&gt;), as well as utilizing new hardware primitives for very efficient bookkeeping and validity checking (&lt;a rel=&quot;nofollow noreferrer&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;vusec&#x2F;rangesanitizer&quot;&gt;RangeSanitizer&lt;&#x2F;a&gt;).&lt;&#x2F;p&gt;
&lt;figure&gt;
    &lt;img
        src=&quot;&amp;#x2F;img&amp;#x2F;posts&amp;#x2F;rsan-comparison.png&quot;
         alt=&quot;From RSan: comparison of runtime overhead on SPEC benchmarking suites&quot;
        
        
    &gt;
    
    &lt;figcaption&gt;&lt;p&gt;From &lt;a rel=&quot;nofollow noreferrer&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;vusec&#x2F;rangesanitizer&quot;&gt;RangeSanitizer&lt;&#x2F;a&gt;: Runtime overhead comparison of RSan and the state of the art sanitizers on SPEC CPU2006 and CPU2017.&lt;&#x2F;p&gt;
&lt;&#x2F;figcaption&gt;
    
&lt;&#x2F;figure&gt;
&lt;h1 id=&quot;but-then-there-was-the-micro-architecture&quot;&gt;But Then There Was the Micro-Architecture&lt;a class=&quot;zola-anchor&quot; href=&quot;#but-then-there-was-the-micro-architecture&quot; aria-label=&quot;Anchor link for: but-then-there-was-the-micro-architecture&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;&#x2F;a&gt;
&lt;&#x2F;h1&gt;
&lt;p&gt;As unfortunate as it is, even if memory sanitizers would be perfect and fuzzers could cover the entire input space somehow, we could not stop worrying about information leaks. The disclosure of &lt;a rel=&quot;nofollow noreferrer&quot; href=&quot;https:&#x2F;&#x2F;spectreattack.com&#x2F;&quot;&gt;&lt;em&gt;spectre&lt;&#x2F;em&gt;&lt;&#x2F;a&gt;, has revealed an entirely new attack surface that stems from micro-architectural &lt;em&gt;speculative execution&lt;&#x2F;em&gt; optimizations. The vulnerabilities are less well-known than the traditional memory errors, and their omni-presence in today&#x27;s systems justifies a brief revisit of their cause and effect.&lt;&#x2F;p&gt;
&lt;p&gt;In the complexity of modern day computing, there are many aspects at many different layers that can be optimized to make systems &lt;em&gt;fast&lt;&#x2F;em&gt; - or perhaps more importantly, &lt;em&gt;faster&lt;&#x2F;em&gt;. Assembly is often referred to as the lowest layer in this regard (ignoring machine code for simplicty). Its instructions are the primitive, yet most complete truth we have to understand what the processor will execute for us. These instructions are considered to be at the &lt;em&gt;architectural&lt;&#x2F;em&gt; level, since they are generated by a compiler based on the Instruction Set Architecture (&lt;em&gt;ISA&lt;&#x2F;em&gt;) for this specific CPU. This is where the aforementioned &quot;classic&quot; memory errors (buffer overreads and use-after-frees) happen.&lt;&#x2F;p&gt;
&lt;p&gt;Though to run these architectural instructions faster, CPU vendors have not just concerned themselves with increasing the transistor counts to keep up with Moore&#x27;s law. They have also been focussed on better utilizing the transistors that are already present by parallelizing many operations. Large performance gains were achieved by &lt;em&gt;pipelining&lt;&#x2F;em&gt; a CPU&#x27;s execution unit, allowing a CPU, for instance, to already start decoding the next instruction, while it is busy executing the current instruction, parallelizing the available execution steps.&lt;&#x2F;p&gt;
&lt;p&gt;Another major performance improvement was achieved by exploiting the fact that instructions that do not depend on each other, can be executed out of order. A &quot;slow&quot; instruction that is waiting for its data to become available (i.e. by reading from memory) can be overtaken by another instruction if there is a processing unit available.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;asm&quot; class=&quot;language-asm z-code&quot;&gt;&lt;code class=&quot;language-asm&quot; data-lang=&quot;asm&quot;&gt;&lt;span class=&quot;z-source z-assembly&quot;&gt;&lt;span class=&quot;z-comment z-assembly&quot;&gt;; Example of a simple addition program that computes&lt;&#x2F;span&gt;
&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-assembly&quot;&gt;&lt;span class=&quot;z-comment z-assembly&quot;&gt;; int res = (10 + 12) + (5 + 8)&lt;&#x2F;span&gt;
&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-assembly&quot;&gt;
&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-assembly&quot;&gt;&lt;span class=&quot;z-comment z-assembly&quot;&gt;; Load the operands&lt;&#x2F;span&gt;
&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-assembly&quot;&gt;&lt;span class=&quot;z-comment z-assembly&quot;&gt;; These mov instructions may be executed in any order&lt;&#x2F;span&gt;
&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-assembly&quot;&gt;&lt;span class=&quot;z-comment z-assembly&quot;&gt;; without changing the architectural behavior&lt;&#x2F;span&gt;
&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-assembly&quot;&gt;&lt;span class=&quot;z-keyword z-control z-assembly&quot;&gt;mov&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt; &lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt; &lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt; &lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt; &lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt; &lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt;r&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-assembly&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt; &lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt;#&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-character z-decimal z-assembly&quot;&gt;10&lt;&#x2F;span&gt;
&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-assembly&quot;&gt;&lt;span class=&quot;z-keyword z-control z-assembly&quot;&gt;mov&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt; &lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt; &lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt; &lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt; &lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt; &lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt;r&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-assembly&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt; &lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt;#&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-character z-decimal z-assembly&quot;&gt;12&lt;&#x2F;span&gt;
&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-assembly&quot;&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt;l&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt;d&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt;r&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt; &lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt; &lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt; &lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt; &lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt; &lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter z-register z-assembly&quot;&gt;r12&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt; &lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-assembly&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter z-register z-assembly&quot;&gt;sp&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-assembly&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt; &lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt;#&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-character z-decimal z-assembly&quot;&gt;12&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-assembly&quot;&gt;]&lt;&#x2F;span&gt;&lt;span class=&quot;z-comment z-assembly&quot;&gt; ; load from memory, slow!&lt;&#x2F;span&gt;
&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-assembly&quot;&gt;&lt;span class=&quot;z-keyword z-control z-assembly&quot;&gt;mov&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt; &lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt; &lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt; &lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt; &lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt; &lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt;r&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt;3&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-assembly&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt; &lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt;#&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-character z-decimal z-assembly&quot;&gt;8&lt;&#x2F;span&gt;
&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-assembly&quot;&gt;
&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-assembly&quot;&gt;&lt;span class=&quot;z-comment z-assembly&quot;&gt;; Sum the operands&lt;&#x2F;span&gt;
&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-assembly&quot;&gt;&lt;span class=&quot;z-comment z-assembly&quot;&gt;; These additions may be executed in any order&lt;&#x2F;span&gt;
&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-assembly&quot;&gt;&lt;span class=&quot;z-comment z-assembly&quot;&gt;; without changing the architectural behavior&lt;&#x2F;span&gt;
&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-assembly&quot;&gt;&lt;span class=&quot;z-keyword z-control z-assembly&quot;&gt;add&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt; &lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt; &lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt; &lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt; &lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt; &lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt;r&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-assembly&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt; &lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt;r&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-assembly&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt; &lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt;r&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;z-comment z-assembly&quot;&gt;     ; r0 = 10 + 12&lt;&#x2F;span&gt;
&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-assembly&quot;&gt;&lt;span class=&quot;z-keyword z-control z-assembly&quot;&gt;add&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt; &lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt; &lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt; &lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt; &lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt; &lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt;r&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt;2&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-assembly&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt; &lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt;r&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt;2&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-assembly&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt; &lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt;r&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt;3&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-comment z-assembly&quot;&gt;    ; r2 = 5 + 8&lt;&#x2F;span&gt;
&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-assembly&quot;&gt;
&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-assembly&quot;&gt;&lt;span class=&quot;z-comment z-assembly&quot;&gt;; The final add cannot be reordered, because it depends on r0 and r2&lt;&#x2F;span&gt;
&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-assembly&quot;&gt;&lt;span class=&quot;z-keyword z-control z-assembly&quot;&gt;add&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt; &lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt; &lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt; &lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt; &lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt; &lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt;r&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-assembly&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt; &lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt;r&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-assembly&quot;&gt;,&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt; &lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt;r&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-function z-assembly&quot;&gt;2&lt;&#x2F;span&gt;&lt;span class=&quot;z-comment z-assembly&quot;&gt;     ; r0 = r0 + r2&lt;&#x2F;span&gt;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Finally, the last major category of optimizations falls under &lt;em&gt;speculative execution&lt;&#x2F;em&gt;. In its simplest form, this allows a CPU to start executing multiple branches in parallel when encountering a conditional jump. After determining the condition, only the computation result of the correct branch will be preserved. Execution results of the other, wrongfully executed branches are discarded, never to be used again.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;c&quot; class=&quot;language-c z-code&quot;&gt;&lt;code class=&quot;language-c&quot; data-lang=&quot;c&quot;&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-comment z-line z-double-slash z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-c&quot;&gt;&#x2F;&#x2F;&lt;&#x2F;span&gt; This condition will take a few cycles to compute
&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-storage z-type z-c&quot;&gt;bool&lt;&#x2F;span&gt; condition &lt;span class=&quot;z-keyword z-operator z-assignment z-c&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;z-keyword z-operator z-variadic z-c&quot;&gt;...&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-accessor z-c&quot;&gt;.&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-terminator z-c&quot;&gt;;&lt;&#x2F;span&gt;
&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;
&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-storage z-type z-c&quot;&gt;int&lt;&#x2F;span&gt; i &lt;span class=&quot;z-keyword z-operator z-assignment z-c&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;z-constant z-numeric z-integer z-decimal z-c&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-terminator z-c&quot;&gt;;&lt;&#x2F;span&gt;
&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-keyword z-control z-c&quot;&gt;if&lt;&#x2F;span&gt; &lt;span class=&quot;z-meta z-group z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-section z-group z-begin z-c&quot;&gt;(&lt;&#x2F;span&gt;condition&lt;span class=&quot;z-punctuation z-section z-group z-end z-c&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt; &lt;span class=&quot;z-meta z-block z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-section z-block z-begin z-c&quot;&gt;{&lt;&#x2F;span&gt;
&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;    &lt;span class=&quot;z-comment z-line z-double-slash z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-c&quot;&gt;&#x2F;&#x2F;&lt;&#x2F;span&gt; Already start executing this branch, 
&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;    &lt;span class=&quot;z-comment z-line z-double-slash z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-c&quot;&gt;&#x2F;&#x2F;&lt;&#x2F;span&gt; before the condition is evaluated!
&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;    &lt;span class=&quot;z-storage z-type z-c&quot;&gt;int&lt;&#x2F;span&gt; &lt;span class=&quot;z-keyword z-operator z-assignment z-c&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;z-constant z-numeric z-integer z-decimal z-c&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-terminator z-c&quot;&gt;;&lt;&#x2F;span&gt; 
&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-section z-block z-end z-c&quot;&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt; &lt;span class=&quot;z-keyword z-control z-c&quot;&gt;else&lt;&#x2F;span&gt; &lt;span class=&quot;z-meta z-block z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-section z-block z-begin z-c&quot;&gt;{&lt;&#x2F;span&gt;
&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;    &lt;span class=&quot;z-comment z-line z-double-slash z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-c&quot;&gt;&#x2F;&#x2F;&lt;&#x2F;span&gt; Already start executing this branch, 
&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;    &lt;span class=&quot;z-comment z-line z-double-slash z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-c&quot;&gt;&#x2F;&#x2F;&lt;&#x2F;span&gt; before the condition is evaluated!
&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;    &lt;span class=&quot;z-storage z-type z-c&quot;&gt;int&lt;&#x2F;span&gt; &lt;span class=&quot;z-keyword z-operator z-assignment z-c&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;z-constant z-numeric z-integer z-decimal z-c&quot;&gt;2&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-terminator z-c&quot;&gt;;&lt;&#x2F;span&gt;
&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-section z-block z-end z-c&quot;&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;
&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-comment z-line z-double-slash z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-c&quot;&gt;&#x2F;&#x2F;&lt;&#x2F;span&gt; The results of the wrong branch are discarded
&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-comment z-line z-double-slash z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-c&quot;&gt;&#x2F;&#x2F;&lt;&#x2F;span&gt; and the correct number is printed
&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-meta z-function-call z-c&quot;&gt;&lt;span class=&quot;z-variable z-function z-c&quot;&gt;printf&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-group z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-section z-group z-begin z-c&quot;&gt;(&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-c&quot;&gt;&lt;span class=&quot;z-meta z-group z-c&quot;&gt;&lt;span class=&quot;z-string z-quoted z-double z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-begin z-c&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;I took branch &lt;span class=&quot;z-constant z-other z-placeholder z-c&quot;&gt;%d&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-character z-escape z-c&quot;&gt;\n&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-end z-c&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-c&quot;&gt;,&lt;&#x2F;span&gt; i&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-group z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-section z-group z-end z-c&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-terminator z-c&quot;&gt;;&lt;&#x2F;span&gt;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;A CPU has the freedom to rearrange instructions and speculatively execute them, as long as it adheres to its part of the contract: operating on the ISA as expected. It should, in other words, not violate any architectural constraints.&lt;&#x2F;p&gt;
&lt;p&gt;In the case of speculative execution, since both branches have been already speculatively executed, the processor can just continue with the correct one which enables significant speedups compared to waiting for the condition to be fully evaluated and only then starting execution from the right branch. At the same time, since the wrong result is discarded, the program still behaves correctly and will never know about the wrongfully executed and then discarded state, in theory. How instructions are executed - and thus how speculative execution is implemented - is dictated by a CPU&#x27;s &lt;em&gt;micro-architecture&lt;&#x2F;em&gt;, implemented in both its hardware and microcode.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;traces-everywhere&quot;&gt;Traces Everywhere&lt;a class=&quot;zola-anchor&quot; href=&quot;#traces-everywhere&quot; aria-label=&quot;Anchor link for: traces-everywhere&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;&#x2F;a&gt;
&lt;&#x2F;h2&gt;
&lt;p&gt;It that turns out that, even though speculative execution adheres to the architectural rules, the (micro-architectural) speculative paths that are taken leave traces that can be observed at the architectural level. A popular example of an observable trace is cache presence.&lt;&#x2F;p&gt;
&lt;p&gt;Memory lookups are orders of magnitudes slower than cache lookups, so depending on a program&#x27;s memory access patterns, caching data from memory improves performance considerably. However, by timing memory accesses, one can now determine if a value was cached or not. A popular way to do so is by performing a FLUSH+RELOAD attack (although many other methods exist). An example is shown below.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;c&quot; class=&quot;language-c z-code&quot;&gt;&lt;code class=&quot;language-c&quot; data-lang=&quot;c&quot;&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-storage z-type z-c&quot;&gt;int&lt;&#x2F;span&gt; data&lt;span class=&quot;z-meta z-brackets z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-section z-brackets z-begin z-c&quot;&gt;[&lt;&#x2F;span&gt;DATA_LEN&lt;span class=&quot;z-punctuation z-section z-brackets z-end z-c&quot;&gt;]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-terminator z-c&quot;&gt;;&lt;&#x2F;span&gt;
&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;
&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-comment z-line z-double-slash z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-c&quot;&gt;&#x2F;&#x2F;&lt;&#x2F;span&gt; FLUSH: make sure that no item in this array is cached
&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-keyword z-control z-c&quot;&gt;for&lt;&#x2F;span&gt; &lt;span class=&quot;z-meta z-group z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-section z-group z-begin z-c&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-storage z-type z-c&quot;&gt;int&lt;&#x2F;span&gt; i &lt;span class=&quot;z-keyword z-operator z-assignment z-c&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;z-constant z-numeric z-integer z-decimal z-c&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-terminator z-c&quot;&gt;;&lt;&#x2F;span&gt; i &lt;span class=&quot;z-keyword z-operator z-comparison z-c&quot;&gt;&amp;lt;&lt;&#x2F;span&gt; DATA_LEN&lt;span class=&quot;z-punctuation z-terminator z-c&quot;&gt;;&lt;&#x2F;span&gt; i&lt;span class=&quot;z-keyword z-operator z-arithmetic z-c&quot;&gt;++&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-section z-group z-end z-c&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt; &lt;span class=&quot;z-meta z-block z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-section z-block z-begin z-c&quot;&gt;{&lt;&#x2F;span&gt;
&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;    &lt;span class=&quot;z-meta z-function-call z-c&quot;&gt;&lt;span class=&quot;z-variable z-function z-c&quot;&gt;clflush&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-group z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-section z-group z-begin z-c&quot;&gt;(&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-c&quot;&gt;&lt;span class=&quot;z-meta z-group z-c&quot;&gt;data&lt;span class=&quot;z-meta z-brackets z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-section z-brackets z-begin z-c&quot;&gt;[&lt;&#x2F;span&gt;i&lt;span class=&quot;z-punctuation z-section z-brackets z-end z-c&quot;&gt;]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-c&quot;&gt;&lt;span class=&quot;z-meta z-group z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-section z-group z-end z-c&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-terminator z-c&quot;&gt;;&lt;&#x2F;span&gt; &lt;span class=&quot;z-comment z-line z-double-slash z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-c&quot;&gt;&#x2F;&#x2F;&lt;&#x2F;span&gt; removes i from the cache
&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-section z-block z-end z-c&quot;&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;
&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-comment z-line z-double-slash z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-c&quot;&gt;&#x2F;&#x2F;&lt;&#x2F;span&gt; ... 
&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-comment z-line z-double-slash z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-c&quot;&gt;&#x2F;&#x2F;&lt;&#x2F;span&gt; some actions are performed on the data
&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-comment z-line z-double-slash z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-c&quot;&gt;&#x2F;&#x2F;&lt;&#x2F;span&gt; ...
&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;
&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;
&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-comment z-line z-double-slash z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-c&quot;&gt;&#x2F;&#x2F;&lt;&#x2F;span&gt; RELOAD: access all values and see how long this takes per value
&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-keyword z-control z-c&quot;&gt;for&lt;&#x2F;span&gt; &lt;span class=&quot;z-meta z-group z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-section z-group z-begin z-c&quot;&gt;(&lt;&#x2F;span&gt;&lt;span class=&quot;z-storage z-type z-c&quot;&gt;int&lt;&#x2F;span&gt; i &lt;span class=&quot;z-keyword z-operator z-assignment z-c&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;z-constant z-numeric z-integer z-decimal z-c&quot;&gt;0&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-terminator z-c&quot;&gt;;&lt;&#x2F;span&gt; i &lt;span class=&quot;z-keyword z-operator z-comparison z-c&quot;&gt;&amp;lt;&lt;&#x2F;span&gt; DATA_LEN&lt;span class=&quot;z-punctuation z-terminator z-c&quot;&gt;;&lt;&#x2F;span&gt; i&lt;span class=&quot;z-keyword z-operator z-arithmetic z-c&quot;&gt;++&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-section z-group z-end z-c&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt; &lt;span class=&quot;z-meta z-block z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-section z-block z-begin z-c&quot;&gt;{&lt;&#x2F;span&gt;
&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;    &lt;span class=&quot;z-storage z-type z-c&quot;&gt;int&lt;&#x2F;span&gt; start &lt;span class=&quot;z-keyword z-operator z-assignment z-c&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;z-meta z-function-call z-c&quot;&gt;&lt;span class=&quot;z-support z-function z-C99 z-c&quot;&gt;time&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-group z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-section z-group z-begin z-c&quot;&gt;(&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-c&quot;&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-c&quot;&gt;&lt;span class=&quot;z-meta z-group z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-section z-group z-end z-c&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-terminator z-c&quot;&gt;;&lt;&#x2F;span&gt;
&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;    &lt;span class=&quot;z-storage z-type z-c&quot;&gt;int&lt;&#x2F;span&gt; val &lt;span class=&quot;z-keyword z-operator z-assignment z-c&quot;&gt;=&lt;&#x2F;span&gt; data&lt;span class=&quot;z-meta z-brackets z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-section z-brackets z-begin z-c&quot;&gt;[&lt;&#x2F;span&gt;i&lt;span class=&quot;z-punctuation z-section z-brackets z-end z-c&quot;&gt;]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-terminator z-c&quot;&gt;;&lt;&#x2F;span&gt; &lt;span class=&quot;z-comment z-line z-double-slash z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-c&quot;&gt;&#x2F;&#x2F;&lt;&#x2F;span&gt; load the value at i
&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;    &lt;span class=&quot;z-storage z-type z-c&quot;&gt;int&lt;&#x2F;span&gt; end &lt;span class=&quot;z-keyword z-operator z-assignment z-c&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;z-meta z-function-call z-c&quot;&gt;&lt;span class=&quot;z-support z-function z-C99 z-c&quot;&gt;time&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-group z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-section z-group z-begin z-c&quot;&gt;(&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-c&quot;&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function-call z-c&quot;&gt;&lt;span class=&quot;z-meta z-group z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-section z-group z-end z-c&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-terminator z-c&quot;&gt;;&lt;&#x2F;span&gt;
&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;    
&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;    &lt;span class=&quot;z-storage z-type z-c&quot;&gt;int&lt;&#x2F;span&gt; duration &lt;span class=&quot;z-keyword z-operator z-assignment z-c&quot;&gt;=&lt;&#x2F;span&gt; end &lt;span class=&quot;z-keyword z-operator z-arithmetic z-c&quot;&gt;-&lt;&#x2F;span&gt; start&lt;span class=&quot;z-punctuation z-terminator z-c&quot;&gt;;&lt;&#x2F;span&gt;
&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;    &lt;span class=&quot;z-keyword z-control z-c&quot;&gt;if&lt;&#x2F;span&gt; &lt;span class=&quot;z-meta z-group z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-section z-group z-begin z-c&quot;&gt;(&lt;&#x2F;span&gt;duration &lt;span class=&quot;z-keyword z-operator z-comparison z-c&quot;&gt;&amp;gt;&lt;&#x2F;span&gt; &lt;span class=&quot;z-constant z-numeric z-integer z-decimal z-c&quot;&gt;1000&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-section z-group z-end z-c&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt; &lt;span class=&quot;z-meta z-block z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-section z-block z-begin z-c&quot;&gt;{&lt;&#x2F;span&gt;
&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;        &lt;span class=&quot;z-comment z-line z-double-slash z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-c&quot;&gt;&#x2F;&#x2F;&lt;&#x2F;span&gt; It took a while to access this value, so it was loaded
&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;        &lt;span class=&quot;z-comment z-line z-double-slash z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-c&quot;&gt;&#x2F;&#x2F;&lt;&#x2F;span&gt; from memory. Not cached! So not used before
&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;    &lt;span class=&quot;z-punctuation z-section z-block z-end z-c&quot;&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt; &lt;span class=&quot;z-keyword z-control z-c&quot;&gt;else&lt;&#x2F;span&gt; &lt;span class=&quot;z-meta z-block z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-section z-block z-begin z-c&quot;&gt;{&lt;&#x2F;span&gt;
&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;        &lt;span class=&quot;z-comment z-line z-double-slash z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-c&quot;&gt;&#x2F;&#x2F;&lt;&#x2F;span&gt; Loading this value was quick, so cached!
&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;        &lt;span class=&quot;z-comment z-line z-double-slash z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-c&quot;&gt;&#x2F;&#x2F;&lt;&#x2F;span&gt; This data was used before
&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;    &lt;span class=&quot;z-punctuation z-section z-block z-end z-c&quot;&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-section z-block z-end z-c&quot;&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;A FLUSH+RELOAD attack is already quite powerful, as it allows attackers to leak information (such as crypto keys) across &lt;a rel=&quot;nofollow noreferrer&quot; href=&quot;https:&#x2F;&#x2F;www.usenix.org&#x2F;conference&#x2F;usenixsecurity14&#x2F;technical-sessions&#x2F;presentation&#x2F;yarom&quot;&gt;shared pages&lt;&#x2F;a&gt; on multi-tenant systems like cloud servers. This attack surface is widened when speculative execution is added to the mix:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;c&quot; class=&quot;language-c z-code&quot;&gt;&lt;code class=&quot;language-c&quot; data-lang=&quot;c&quot;&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-storage z-type z-c&quot;&gt;int&lt;&#x2F;span&gt; &lt;span class=&quot;z-meta z-function z-c&quot;&gt;&lt;span class=&quot;z-entity z-name z-function z-c&quot;&gt;double_lookup&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function z-parameters z-c&quot;&gt;&lt;span class=&quot;z-meta z-group z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-section z-group z-begin z-c&quot;&gt;(&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function z-parameters z-c&quot;&gt;&lt;span class=&quot;z-meta z-group z-c&quot;&gt;&lt;span class=&quot;z-storage z-type z-c&quot;&gt;int&lt;&#x2F;span&gt; &lt;span class=&quot;z-variable z-parameter z-c&quot;&gt;password&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-separator z-c&quot;&gt;,&lt;&#x2F;span&gt; &lt;span class=&quot;z-storage z-type z-c&quot;&gt;int&lt;&#x2F;span&gt; &lt;span class=&quot;z-keyword z-operator z-c&quot;&gt;*&lt;&#x2F;span&gt;&lt;span class=&quot;z-variable z-parameter z-c&quot;&gt;dest&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-section z-group z-end z-c&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function z-c&quot;&gt; &lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-section z-block z-begin z-c&quot;&gt;{&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;
&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-meta z-function z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;    &lt;span class=&quot;z-storage z-type z-c&quot;&gt;int&lt;&#x2F;span&gt; secret &lt;span class=&quot;z-keyword z-operator z-assignment z-c&quot;&gt;=&lt;&#x2F;span&gt; SECRET&lt;span class=&quot;z-punctuation z-terminator z-c&quot;&gt;;&lt;&#x2F;span&gt; &lt;span class=&quot;z-comment z-line z-double-slash z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-c&quot;&gt;&#x2F;&#x2F;&lt;&#x2F;span&gt; the secret to leak
&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-meta z-function z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;    &lt;span class=&quot;z-keyword z-control z-c&quot;&gt;if&lt;&#x2F;span&gt; &lt;span class=&quot;z-meta z-group z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-section z-group z-begin z-c&quot;&gt;(&lt;&#x2F;span&gt;password &lt;span class=&quot;z-keyword z-operator z-comparison z-c&quot;&gt;==&lt;&#x2F;span&gt; CORRECT_PASSWORD&lt;span class=&quot;z-punctuation z-section z-group z-end z-c&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt; &lt;span class=&quot;z-meta z-block z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-section z-block z-begin z-c&quot;&gt;{&lt;&#x2F;span&gt;
&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;mark&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-meta z-function z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;        dest&lt;span class=&quot;z-meta z-brackets z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-section z-brackets z-begin z-c&quot;&gt;[&lt;&#x2F;span&gt;secret&lt;span class=&quot;z-punctuation z-section z-brackets z-end z-c&quot;&gt;]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt; &lt;span class=&quot;z-keyword z-operator z-assignment z-c&quot;&gt;=&lt;&#x2F;span&gt; &lt;span class=&quot;z-constant z-numeric z-integer z-decimal z-c&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-terminator z-c&quot;&gt;;&lt;&#x2F;span&gt; &lt;span class=&quot;z-comment z-line z-double-slash z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-definition z-comment z-c&quot;&gt;&#x2F;&#x2F;&lt;&#x2F;span&gt; this places dest[secret] in cache
&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;mark&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-meta z-function z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;        &lt;span class=&quot;z-keyword z-control z-flow z-return z-c&quot;&gt;return&lt;&#x2F;span&gt; secret&lt;span class=&quot;z-punctuation z-terminator z-c&quot;&gt;;&lt;&#x2F;span&gt;
&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-meta z-function z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;    &lt;span class=&quot;z-punctuation z-section z-block z-end z-c&quot;&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt; &lt;span class=&quot;z-keyword z-control z-c&quot;&gt;else&lt;&#x2F;span&gt; &lt;span class=&quot;z-meta z-block z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-section z-block z-begin z-c&quot;&gt;{&lt;&#x2F;span&gt;
&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-meta z-function z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;        &lt;span class=&quot;z-keyword z-control z-flow z-return z-c&quot;&gt;return&lt;&#x2F;span&gt; &lt;span class=&quot;z-keyword z-operator z-arithmetic z-c&quot;&gt;-&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric z-integer z-decimal z-c&quot;&gt;1&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-terminator z-c&quot;&gt;;&lt;&#x2F;span&gt;
&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-meta z-function z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;    &lt;span class=&quot;z-punctuation z-section z-block z-end z-c&quot;&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source z-c&quot;&gt;&lt;span class=&quot;z-meta z-function z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-meta z-function z-c&quot;&gt;&lt;span class=&quot;z-meta z-block z-c&quot;&gt;&lt;span class=&quot;z-punctuation z-section z-block z-end z-c&quot;&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The example above is &quot;safe&quot; at the architectural level: if the password is incorrect, the function will return -1 and will not leak any information. Yet, at the micro-architectural level both branches have been speculatively executed! Even though the result (i.e. setting the value of &lt;code&gt;dest[secret]&lt;&#x2F;code&gt; to 1) has been rolled back, &lt;code&gt;dest[secret]&lt;&#x2F;code&gt; is now in the cache, and an attacker could perform FLUSH+RELOAD to now reveal this cache state, and thus the value of &lt;code&gt;secret&lt;&#x2F;code&gt;. The cache operates as a side-channel for the micro-architectural state.&lt;&#x2F;p&gt;
&lt;p&gt;The code snippet is an example of Spectre-V1, also known as &lt;em&gt;bounds check bypass&lt;&#x2F;em&gt;. This particular snippet is contrived, but real-world &quot;spectre gadgets&quot; continue to be found, even in high-level languages &lt;a rel=&quot;nofollow noreferrer&quot; href=&quot;https:&#x2F;&#x2F;v8.dev&#x2F;blog&#x2F;spectre&quot;&gt;like JavaScript&lt;&#x2F;a&gt;. Patching spectre is nearly impossible, as removing speculative execution from a CPU would incur an unacceptably large a performance penalty. Besides, speculative execution is implemented mostly in hardware, which is infeasible to update for all existing systems. Detecting exploitation of spectre gadgets is hard, and many more side-channels exist than just the cache, such as power usage and variable instruction timing differences.&lt;&#x2F;p&gt;
&lt;p&gt;As if leaking cache states was not concerning enough, speculative execution gadgets have also proven to be useful for breaking modern hardware memory protections. Apple M1 memory protections have been shown vulnerable, due to the exploitation of speculatively executed code as a memory integrity &lt;a rel=&quot;nofollow noreferrer&quot; href=&quot;https:&#x2F;&#x2F;pacmanattack.com&#x2F;&quot;&gt;&quot;&lt;em&gt;oracle&lt;&#x2F;em&gt;&quot;&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Unfortunately, there is no rest for security engineers. Even if programs are considered safe at the architectural level, information might still be leaked through the micro-architecture.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;acceptable-mitigations&quot;&gt;Acceptable Mitigations&lt;a class=&quot;zola-anchor&quot; href=&quot;#acceptable-mitigations&quot; aria-label=&quot;Anchor link for: acceptable-mitigations&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;&#x2F;a&gt;
&lt;&#x2F;h1&gt;
&lt;p&gt;Since its publication, it has been clear that spectre is &lt;em&gt;here to stay&lt;&#x2F;em&gt;, and that effective yet acceptable mitigations must be found in software. The most straight-forward fix is to disable speculative execution altogether by having the compiler add &lt;a rel=&quot;nofollow noreferrer&quot; href=&quot;https:&#x2F;&#x2F;www.felixcloutier.com&#x2F;x86&#x2F;lfence&quot;&gt;&lt;code&gt;lfence&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; instructions to branches and jump targets. As already mentioned, this would cause too drastic of a performance decrease to be applied everywhere, but it can be selectively be applied to manually identified spectre gadgets or code that is considered so vital to security, that the decreased performance is justified. This however, relies mostly on manual inspection, which does not particularly scale well.&lt;&#x2F;p&gt;
&lt;p&gt;Hence, other mitigation options have been, and continue to be actively researched. As usual, the goal is to find mitigations that have their performance penalty legitimized by strong enough security improvements, while minimizing the compatibility issues that arise from applying them at scale. LLVM has introduced &lt;a rel=&quot;nofollow noreferrer&quot; href=&quot;https:&#x2F;&#x2F;llvm.org&#x2F;docs&#x2F;SpeculativeLoadHardening.html&quot;&gt;&lt;em&gt;speculative load hardening&lt;&#x2F;em&gt;&lt;&#x2F;a&gt; which is considered to be the state-of-the-art spectre-v1 mitigation at the time of writing.
SLH is based on the principle of detecting wrongful speculative execution at runtime. When detected, the loaded data values are scrambled, which &quot;poisons&quot; the cache, so that nothing useful can be deduced from it anymore, even when its state is leaked. In 2023, &lt;a rel=&quot;nofollow noreferrer&quot; href=&quot;https:&#x2F;&#x2F;www.usenix.org&#x2F;conference&#x2F;usenixsecurity23&#x2F;presentation&#x2F;zhang-zhiyuan-slh&quot;&gt;&lt;em&gt;ultimate SLH&lt;&#x2F;em&gt;&lt;&#x2F;a&gt; was published to improve on existing SLH solutions by also poisoning values for arithmetic operations with variable load times (dependent on their operands) and the results of some obscure x86 &lt;code&gt;repeat&lt;&#x2F;code&gt; instructions.&lt;&#x2F;p&gt;
&lt;figure&gt;
    &lt;img
        src=&quot;&amp;#x2F;img&amp;#x2F;posts&amp;#x2F;uslh-comparison.png&quot;
         alt=&quot;From USLH: comparison of runtime overhead on SPEC benchmarking suites&quot;
        
        
    &gt;
    
    &lt;figcaption&gt;&lt;p&gt;From &lt;a rel=&quot;nofollow noreferrer&quot; href=&quot;https:&#x2F;&#x2F;www.usenix.org&#x2F;system&#x2F;files&#x2F;sec23fall-prepub-278-zhang-zhiyuan.pdf&quot;&gt;USLH&lt;&#x2F;a&gt;: Runtime overhead comparison of modern spectre mitigations on SPEC CPU2017.&lt;&#x2F;p&gt;
&lt;&#x2F;figcaption&gt;
    
&lt;&#x2F;figure&gt;
&lt;p&gt;Though SLH incurs (much) less overhead than &lt;code&gt;lfence&lt;&#x2F;code&gt;-ing, its security benefits do still not come cheaply. Hence, SLH too, must be selectively applied and is not enabled at scale.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;embracing-spectre&quot;&gt;Embracing Spectre&lt;a class=&quot;zola-anchor&quot; href=&quot;#embracing-spectre&quot; aria-label=&quot;Anchor link for: embracing-spectre&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;&#x2F;a&gt;
&lt;&#x2F;h2&gt;
&lt;p&gt;Instead of costly measures that prevent spectre from leaking any information at all (such as &lt;code&gt;lfence&lt;&#x2F;code&gt; and SLH), recent work has focussed on constraining the information that can be leaked to &quot;acceptable&quot; levels. At VUSec - the research group at the VU that organizes my Master&#x27;s degree - the idea of &lt;a rel=&quot;nofollow noreferrer&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;vusec&#x2F;typeisolation&quot;&gt;&lt;em&gt;Type-Based Data Isolation&lt;&#x2F;em&gt;&lt;&#x2F;a&gt; has been explored to this end.&lt;&#x2F;p&gt;
&lt;p&gt;As the name suggests, information (data) is isolated based on its type. Each type has its own allocation arena, and using both compile-time and runtime instrumentation data accesses are constrained to their own arena at the &lt;em&gt;architectural&lt;&#x2F;em&gt; and &lt;em&gt;micro-architectural&lt;&#x2F;em&gt; level. This implies that, even if one manages to leak information, the leak is restricted to that type only. The granularity of types can vary from very coarse (e.g. &quot;safe&quot; and &quot;unsafe&quot; data) to more fine forms (such as one type per primitive). The idea is quite powerful and has a much lower performance overhead, as also underpinned by Apple&#x27;s &lt;a rel=&quot;nofollow noreferrer&quot; href=&quot;https:&#x2F;&#x2F;security.apple.com&#x2F;blog&#x2F;memory-integrity-enforcement&#x2F;&quot;&gt;recent adoption&lt;&#x2F;a&gt; in the iPhone 17.&lt;&#x2F;p&gt;
&lt;figure&gt;
    &lt;img
        src=&quot;&amp;#x2F;img&amp;#x2F;posts&amp;#x2F;tdi-comparison.png&quot;
         alt=&quot;From TDI: comparison of runtime overhead on SPEC benchmarking suites&quot;
        
        
    &gt;
    
    &lt;figcaption&gt;&lt;p&gt;From &lt;a rel=&quot;nofollow noreferrer&quot; href=&quot;https:&#x2F;&#x2F;download.vusec.net&#x2F;papers&#x2F;tdi_sp22.pdf&quot;&gt;Type-Based Data Isolation&lt;&#x2F;a&gt;: Runtime overhead comparison of Type-Based Data Isolation (blue) and Speculative Load Hardening (red) on SPEC CPU2017.&lt;&#x2F;p&gt;
&lt;&#x2F;figcaption&gt;
    
&lt;&#x2F;figure&gt;
&lt;p&gt;Yet, the effectiveness of type-based data isolation still largely depends on its implementation details. The hardest challenge is to decide on the types to use: can they be determined accurately, also for existing (and old) codebases? If type information is not present, or very coarse-grained, the guarantees that TDI provide are weakened (i.e. there are few, very large arenas that allow for a lot of information to be leaked intra-arena).&lt;&#x2F;p&gt;
&lt;p&gt;And even if types were fine-grained, compatible and accurate, TDI would still allow for &lt;em&gt;inter-arena&lt;&#x2F;em&gt; information leaks by being able to, for instance, exploit an &lt;em&gt;intra-domain&lt;&#x2F;em&gt; buffer overflow. The guarantees hence depend on the specific target program that is instrumented, and its (architectural) security mitigations.&lt;&#x2F;p&gt;
&lt;figure&gt;
    &lt;img
        src=&quot;&amp;#x2F;img&amp;#x2F;posts&amp;#x2F;inter-arena-leak.png&quot;
         alt=&quot;From RSan: comparison of runtime overhead on SPEC benchmarking suites&quot;
        
        
    &gt;
    
    &lt;figcaption&gt;&lt;p&gt;An intra-arena buffer-overflow of &lt;code&gt;char arr[8]&lt;&#x2F;code&gt; into &lt;code&gt;void *ptr&lt;&#x2F;code&gt; might still overwrite a pointer that allows inter-arena information leaking.&lt;&#x2F;p&gt;
&lt;&#x2F;figcaption&gt;
    
&lt;&#x2F;figure&gt;
&lt;p&gt;Again, mitigations that are applied at scale are normally weighed on their security improvements versus their performance costs and compatibility issues. TDI scores great on all three: for single-digit overhead, systems can enjoy serious security improvements with relatively little compatibility concerns. Though, what happens if we turn the knobs?&lt;&#x2F;p&gt;
&lt;h1 id=&quot;expanding-the-tradeoff-space&quot;&gt;Expanding the Tradeoff Space&lt;a class=&quot;zola-anchor&quot; href=&quot;#expanding-the-tradeoff-space&quot; aria-label=&quot;Anchor link for: expanding-the-tradeoff-space&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;&#x2F;a&gt;
&lt;&#x2F;h1&gt;
&lt;p&gt;With that introduction out of the way, the foundation for a research topic has been laid. In the coming months, I will explore the tradeoff space further to find solutions that have stronger security guarantees than TDI, and less overhead than SLH. To do so, I will base my prototype on novel structures in the state-of-the-art memory sanitizing developments, combined with data isolation methods that have already proven themselves worthy in production systems. More to follow.&lt;&#x2F;p&gt;
</content>
	</entry>
</feed>
