Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(210)

Side by Side Diff: native_client_sdk/doc_generated/reference/sandbox_internals/arm-32-bit-sandbox.html

Issue 438403003: [NaCl SDK Docs] Only generate one top-level <section> element. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 {{+bindTo:partials.standard_nacl_article}} 1 {{+bindTo:partials.standard_nacl_article}}
2 2
3 <section id="arm-32-bit-sandbox"> 3 <section id="arm-32-bit-sandbox">
4 <span id="id1"></span><h1 id="arm-32-bit-sandbox"><span id="id1"></span>ARM 32-b it Sandbox</h1> 4 <span id="id1"></span><h1 id="arm-32-bit-sandbox"><span id="id1"></span>ARM 32-b it Sandbox</h1>
5 <p>Native Client for ARM is a sandboxing technology for running 5 <p>Native Client for ARM is a sandboxing technology for running
6 programs&#8212;even malicious ones&#8212;safely, on computers that use 32-bit 6 programs&#8212;even malicious ones&#8212;safely, on computers that use 32-bit
7 ARM processors. The ARM sandbox is an extension of earlier work on 7 ARM processors. The ARM sandbox is an extension of earlier work on
8 Native Client for x86 processors. Security is provided with a low 8 Native Client for x86 processors. Security is provided with a low
9 performance overhead of about 10% over regular ARM code, and as you&#8217;ll 9 performance overhead of about 10% over regular ARM code, and as you&#8217;ll
10 see in this document the sandbox model is beautifully simple, meaning 10 see in this document the sandbox model is beautifully simple, meaning
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 <ul class="small-gap"> 49 <ul class="small-gap">
50 <li><a class="reference internal" href="#forbidden-instructions" id="id16">Forbi dden Instructions</a></li> 50 <li><a class="reference internal" href="#forbidden-instructions" id="id16">Forbi dden Instructions</a></li>
51 <li><a class="reference internal" href="#coprocessors" id="id17">Coprocessors</a ></li> 51 <li><a class="reference internal" href="#coprocessors" id="id17">Coprocessors</a ></li>
52 <li><a class="reference internal" href="#validator-code" id="id18">Validator Cod e</a></li> 52 <li><a class="reference internal" href="#validator-code" id="id18">Validator Cod e</a></li>
53 </ul> 53 </ul>
54 </li> 54 </li>
55 </ul> 55 </ul>
56 </li> 56 </li>
57 </ul> 57 </ul>
58 58
59 </div><section id="an-introduction-to-the-arm-architecture"> 59 </div><h2 id="an-introduction-to-the-arm-architecture">An Introduction to the AR M Architecture</h2>
60 <h2 id="an-introduction-to-the-arm-architecture">An Introduction to the ARM Arch itecture</h2>
61 <p>In this section, we summarize the relevant parts of the ARM processor 60 <p>In this section, we summarize the relevant parts of the ARM processor
62 architecture.</p> 61 architecture.</p>
63 <section id="about-arm-and-armv7-a">
64 <h3 id="about-arm-and-armv7-a">About ARM and ARMv7-A</h3> 62 <h3 id="about-arm-and-armv7-a">About ARM and ARMv7-A</h3>
65 <p>ARM is one of the older commercial &#8220;RISC&#8221; processor designs, dati ng back 63 <p>ARM is one of the older commercial &#8220;RISC&#8221; processor designs, dati ng back
66 to the early 1980s. Today, it is used primarily in embedded systems: 64 to the early 1980s. Today, it is used primarily in embedded systems:
67 everything from toys, to home automation, to automobiles. However, its 65 everything from toys, to home automation, to automobiles. However, its
68 most visible use is in cellular phones, tablets and some 66 most visible use is in cellular phones, tablets and some
69 laptops.</p> 67 laptops.</p>
70 <p>Through the years, there have been many revisions of the ARM 68 <p>Through the years, there have been many revisions of the ARM
71 architecture, written as ARMv<em>X</em> for some version <em>X</em>. Native Clie nt 69 architecture, written as ARMv<em>X</em> for some version <em>X</em>. Native Clie nt
72 specifically targets the ARMv7-A architecture commonly used in high-end 70 specifically targets the ARMv7-A architecture commonly used in high-end
73 phones and smartbooks. This revision, defined in the mid-2000s, adds a 71 phones and smartbooks. This revision, defined in the mid-2000s, adds a
74 number of useful instructions, and specifies some portions of the system 72 number of useful instructions, and specifies some portions of the system
75 that used to be left to individual chip manufacturers. Critically, 73 that used to be left to individual chip manufacturers. Critically,
76 ARMv7-A specifies the &#8220;eXecute Never&#8221; bit, or <em>XN</em>. This page table 74 ARMv7-A specifies the &#8220;eXecute Never&#8221; bit, or <em>XN</em>. This page table
77 attribute lets us mark memory as non-executable. Our security relies on 75 attribute lets us mark memory as non-executable. Our security relies on
78 the presence of this feature.</p> 76 the presence of this feature.</p>
79 <p>ARMv8 adds a new 64-bit instruction set architecture called A64, while 77 <p>ARMv8 adds a new 64-bit instruction set architecture called A64, while
80 also enhancing the 32-bit A32 ISA. For Native Client&#8217;s purposes the A32 78 also enhancing the 32-bit A32 ISA. For Native Client&#8217;s purposes the A32
81 ISA is equivalent to the ARMv7 ARM ISA, albeit with a few new 79 ISA is equivalent to the ARMv7 ARM ISA, albeit with a few new
82 instructions. This document only discussed the 32-bit A32 instruction 80 instructions. This document only discussed the 32-bit A32 instruction
83 set: A64 would require a different sandboxing model.</p> 81 set: A64 would require a different sandboxing model.</p>
84 </section><section id="arm-programmer-s-model">
85 <h3 id="arm-programmer-s-model">ARM Programmer&#8217;s Model</h3> 82 <h3 id="arm-programmer-s-model">ARM Programmer&#8217;s Model</h3>
86 <p>While modern ARM chips support several instruction encodings, 32-bit 83 <p>While modern ARM chips support several instruction encodings, 32-bit
87 Native Client on ARM focuses on a single one: a fixed-width encoding 84 Native Client on ARM focuses on a single one: a fixed-width encoding
88 where every instruction is 32-bits wide called A32 (previously, and 85 where every instruction is 32-bits wide called A32 (previously, and
89 confusingly, called simply ARM). Thumb, Thumb2 (now confusingly called 86 confusingly, called simply ARM). Thumb, Thumb2 (now confusingly called
90 T32), Jazelle, ThumbEE and such aren&#8217;t supported by Native Client. This 87 T32), Jazelle, ThumbEE and such aren&#8217;t supported by Native Client. This
91 dramatically simplifies some of our analyses, as we&#8217;ll see later. Nearly 88 dramatically simplifies some of our analyses, as we&#8217;ll see later. Nearly
92 every instruction can be conditionally executed based on the contents of 89 every instruction can be conditionally executed based on the contents of
93 a dedicated condition code register.</p> 90 a dedicated condition code register.</p>
94 <p>ARM processors have 16 general-purpose registers used for integer and 91 <p>ARM processors have 16 general-purpose registers used for integer and
(...skipping 27 matching lines...) Expand all
122 <li>The <code>movw</code> and <code>movt</code> instructions can be used to set the top and 119 <li>The <code>movw</code> and <code>movt</code> instructions can be used to set the top and
123 bottom 16-bits of a register, and can therefore encode any 32-bit 120 bottom 16-bits of a register, and can therefore encode any 32-bit
124 immediate.</li> 121 immediate.</li>
125 <li>For values that can&#8217;t be represented as modified immediates, ARM 122 <li>For values that can&#8217;t be represented as modified immediates, ARM
126 programs use <code>pc</code>-relative loads to load data from inside the 123 programs use <code>pc</code>-relative loads to load data from inside the
127 code&#8212;hidden in a place where it won&#8217;t be executed such as &#8220;con stant 124 code&#8212;hidden in a place where it won&#8217;t be executed such as &#8220;con stant
128 pools&#8221;, just past the final return of a function.</li> 125 pools&#8221;, just past the final return of a function.</li>
129 </ol> 126 </ol>
130 <p>We&#8217;ll introduce more details of the ARM instruction set later, as we 127 <p>We&#8217;ll introduce more details of the ARM instruction set later, as we
131 walk through the system.</p> 128 walk through the system.</p>
132 </section></section><section id="the-native-client-approach">
133 <h2 id="the-native-client-approach">The Native Client Approach</h2> 129 <h2 id="the-native-client-approach">The Native Client Approach</h2>
134 <p>Native Client runs an untrusted program, potentially from an unknown or 130 <p>Native Client runs an untrusted program, potentially from an unknown or
135 malicious source, inside a sandbox created by a trusted runtime. The 131 malicious source, inside a sandbox created by a trusted runtime. The
136 trusted runtime allows the untrusted program to &#8220;call-out&#8221; and perfo rm 132 trusted runtime allows the untrusted program to &#8220;call-out&#8221; and perfo rm
137 certain actions, such as drawing graphics, but prevents it from 133 certain actions, such as drawing graphics, but prevents it from
138 accessing the operating system directly. This &#8220;call-out&#8221; facility, 134 accessing the operating system directly. This &#8220;call-out&#8221; facility,
139 called a trampoline, looks like a standard function call to the 135 called a trampoline, looks like a standard function call to the
140 untrusted program, but it allows control to escape from the sandbox in a 136 untrusted program, but it allows control to escape from the sandbox in a
141 controlled way.</p> 137 controlled way.</p>
142 <p>The untrusted program and trusted runtime inhabit the same process, or 138 <p>The untrusted program and trusted runtime inhabit the same process, or
(...skipping 25 matching lines...) Expand all
168 compilers either. Instead, we apply a load-time validator that 164 compilers either. Instead, we apply a load-time validator that
169 disassembles the program. The validator either proves that the program 165 disassembles the program. The validator either proves that the program
170 complies with our rules, or rejects it as unsafe. By keeping the rules 166 complies with our rules, or rejects it as unsafe. By keeping the rules
171 simple, we keep the validator simple, small, and fast. We like to put 167 simple, we keep the validator simple, small, and fast. We like to put
172 our trust in small, simple things, and the validator is key to the 168 our trust in small, simple things, and the validator is key to the
173 system&#8217;s security.</p> 169 system&#8217;s security.</p>
174 <aside class="note"> 170 <aside class="note">
175 For the computationally-inclined, all our validators scale linearly in 171 For the computationally-inclined, all our validators scale linearly in
176 the size of the program. 172 the size of the program.
177 </aside> 173 </aside>
178 <section id="nacl-arm-pure-software-fault-isolation">
179 <h3 id="nacl-arm-pure-software-fault-isolation">NaCl/ARM: Pure Software Fault Is olation</h3> 174 <h3 id="nacl-arm-pure-software-fault-isolation">NaCl/ARM: Pure Software Fault Is olation</h3>
180 <p>In the original Native Client system for the x86, we used unusual 175 <p>In the original Native Client system for the x86, we used unusual
181 hardware features of that processor (the segment registers) to isolate 176 hardware features of that processor (the segment registers) to isolate
182 untrusted programs. This was simple and fast, but won&#8217;t work on ARM, 177 untrusted programs. This was simple and fast, but won&#8217;t work on ARM,
183 which has nothing equivalent. Instead, we use pure software fault 178 which has nothing equivalent. Instead, we use pure software fault
184 isolation.</p> 179 isolation.</p>
185 <p>We use a fixed address space layout: the untrusted program gets the 180 <p>We use a fixed address space layout: the untrusted program gets the
186 lowest gigabyte, addresses <code>0</code> through <code>0x3FFFFFFF</code>. The r est of the 181 lowest gigabyte, addresses <code>0</code> through <code>0x3FFFFFFF</code>. The r est of the
187 address space holds the trusted runtime and the operating system. We 182 address space holds the trusted runtime and the operating system. We
188 isolate the program by requiring every <em>load</em>, <em>store</em>, and <em>in direct 183 isolate the program by requiring every <em>load</em>, <em>store</em>, and <em>in direct
189 branch</em> (to an address in a register) to use a pseudo-instruction. The 184 branch</em> (to an address in a register) to use a pseudo-instruction. The
190 pseudo-instructions ensure that the address stays within the 185 pseudo-instructions ensure that the address stays within the
191 sandbox. The <em>indirect branch</em> pseudo-instruction, in turn, ensures that 186 sandbox. The <em>indirect branch</em> pseudo-instruction, in turn, ensures that
192 such branches won&#8217;t split up other pseudo-instructions.</p> 187 such branches won&#8217;t split up other pseudo-instructions.</p>
193 <p>At either side of the sandbox, we place small (8KiB) guard 188 <p>At either side of the sandbox, we place small (8KiB) guard
194 regions. These are simply areas in the process&#8217;s address space that are 189 regions. These are simply areas in the process&#8217;s address space that are
195 mapped without read, write, or execute permissions, so any attempt to 190 mapped without read, write, or execute permissions, so any attempt to
196 access them for any reason&#8212;<em>load</em>, <em>store</em>, or <em>jump</em> &#8212;will cause a 191 access them for any reason&#8212;<em>load</em>, <em>store</em>, or <em>jump</em> &#8212;will cause a
197 fault.</p> 192 fault.</p>
198 <p>Finally, we ban the use of certain instructions, notably direct system 193 <p>Finally, we ban the use of certain instructions, notably direct system
199 calls. This is to ensure that the untrusted program can be run on any 194 calls. This is to ensure that the untrusted program can be run on any
200 operating system supported by Native Client, and to prevent access to 195 operating system supported by Native Client, and to prevent access to
201 certain system features that might be used to subvert the sandbox. As a 196 certain system features that might be used to subvert the sandbox. As a
202 side effect, it helps to prevent programs from exploiting buggy 197 side effect, it helps to prevent programs from exploiting buggy
203 operating system APIs.</p> 198 operating system APIs.</p>
204 <p>Let&#8217;s walk through the details, starting with the simplest part: <em>lo ad</em> 199 <p>Let&#8217;s walk through the details, starting with the simplest part: <em>lo ad</em>
205 and <em>store</em>.</p> 200 and <em>store</em>.</p>
206 <section id="load-and-store">
207 <h4 id="load-and-store"><em>Load</em> and <em>Store</em></h4> 201 <h4 id="load-and-store"><em>Load</em> and <em>Store</em></h4>
208 <p>All access to memory must be through <em>load</em> and <em>store</em> 202 <p>All access to memory must be through <em>load</em> and <em>store</em>
209 pseudo-instructions. These are simply a native <em>load</em> or <em>store</em> 203 pseudo-instructions. These are simply a native <em>load</em> or <em>store</em>
210 instruction, preceded by a guard instruction.</p> 204 instruction, preceded by a guard instruction.</p>
211 <p>Each <em>load</em> or <em>store</em> pseudo-instruction is similar to the <em >load</em> shown 205 <p>Each <em>load</em> or <em>store</em> pseudo-instruction is similar to the <em >load</em> shown
212 below. We use abstract &#8220;placeholder&#8221; registers instead of specific 206 below. We use abstract &#8220;placeholder&#8221; registers instead of specific
213 numbered registers for the sake of discussion. <code>rA</code> is the register 207 numbered registers for the sake of discussion. <code>rA</code> is the register
214 holding the address to load from. <code>rD</code> is the destination for the 208 holding the address to load from. <code>rD</code> is the destination for the
215 loaded data.</p> 209 loaded data.</p>
216 <pre> 210 <pre>
(...skipping 11 matching lines...) Expand all
228 <p>This illustrates a common property of all Native Client systems: we aim 222 <p>This illustrates a common property of all Native Client systems: we aim
229 for safety, not correctness. A program using an invalid address in 223 for safety, not correctness. A program using an invalid address in
230 <code>rA</code> here is simply broken, so we are free to do whatever we want to 224 <code>rA</code> here is simply broken, so we are free to do whatever we want to
231 preserve safety. In this case the program might load an invalid (but 225 preserve safety. In this case the program might load an invalid (but
232 safe) value, or cause a segmentation fault limited to the untrusted 226 safe) value, or cause a segmentation fault limited to the untrusted
233 code.</p> 227 code.</p>
234 <p>Now, if we allowed arbitrary branches within the program, a malicious 228 <p>Now, if we allowed arbitrary branches within the program, a malicious
235 program could set up carefully-crafted values in <code>rA</code>, and then jump 229 program could set up carefully-crafted values in <code>rA</code>, and then jump
236 straight to the <code>ldr</code>. This is why we validate that programs never 230 straight to the <code>ldr</code>. This is why we validate that programs never
237 split pseudo-instructions.</p> 231 split pseudo-instructions.</p>
238 <section id="alternative-sandboxing">
239 <h5 id="alternative-sandboxing">Alternative Sandboxing</h5> 232 <h5 id="alternative-sandboxing">Alternative Sandboxing</h5>
240 <pre> 233 <pre>
241 tst rA, #0xC0000000 234 tst rA, #0xC0000000
242 ldreq rD, [rA] 235 ldreq rD, [rA]
243 </pre> 236 </pre>
244 <p>The first instruction, <code>tst</code>, performs a bitwise-<code>AND</code> of <code>rA</code> 237 <p>The first instruction, <code>tst</code>, performs a bitwise-<code>AND</code> of <code>rA</code>
245 and the modified immediate literal, <code>0xC0000000</code>. It sets the 238 and the modified immediate literal, <code>0xC0000000</code>. It sets the
246 condition flags based on the result, but does not write the result to a 239 condition flags based on the result, but does not write the result to a
247 register. In particular, it sets the <code>Z</code> condition flag if the result 240 register. In particular, it sets the <code>Z</code> condition flag if the result
248 was zero&#8212;if the two values had no set bits in common. In this case, 241 was zero&#8212;if the two values had no set bits in common. In this case,
(...skipping 13 matching lines...) Expand all
262 <aside class="note"> 255 <aside class="note">
263 The <code>tst</code>-based sequence is faster than the <code>bic</code>-based se quence 256 The <code>tst</code>-based sequence is faster than the <code>bic</code>-based se quence
264 on modern ARM chips. It avoids a data dependency in the address 257 on modern ARM chips. It avoids a data dependency in the address
265 register. This is why we keep both around. The <code>tst</code>-based sequence 258 register. This is why we keep both around. The <code>tst</code>-based sequence
266 unfortunately leaks information on some processors, and is therefore 259 unfortunately leaks information on some processors, and is therefore
267 forbidden on certain processors. This effectively means that it cannot 260 forbidden on certain processors. This effectively means that it cannot
268 be used for regular Native Client <strong>nexe</strong> files, but can be used w ith 261 be used for regular Native Client <strong>nexe</strong> files, but can be used w ith
269 Portable Native Client because the target processor is known at 262 Portable Native Client because the target processor is known at
270 translation time from <strong>pexe</strong> to <strong>nexe</strong>. 263 translation time from <strong>pexe</strong> to <strong>nexe</strong>.
271 </aside> 264 </aside>
272 </section><section id="addressing-modes">
273 <h5 id="addressing-modes">Addressing Modes</h5> 265 <h5 id="addressing-modes">Addressing Modes</h5>
274 <p>ARM has an unusually rich set of addressing modes. We allow all but one: 266 <p>ARM has an unusually rich set of addressing modes. We allow all but one:
275 register-indexed, where two registers are added to determine the 267 register-indexed, where two registers are added to determine the
276 address.</p> 268 address.</p>
277 <p>We permit simple <em>load</em> and <em>store</em>, as shown above. We also pe rmit 269 <p>We permit simple <em>load</em> and <em>store</em>, as shown above. We also pe rmit
278 displacement, pre-index, and post-index memory operations:</p> 270 displacement, pre-index, and post-index memory operations:</p>
279 <pre> 271 <pre>
280 bic rA, #0xC0000000 272 bic rA, #0xC0000000
281 ldr rD, [rA, #1234] ; This is fine. 273 ldr rD, [rA, #1234] ; This is fine.
282 bic rA, #0xC0000000 274 bic rA, #0xC0000000
283 ldr rD, [rA, #1234]! ; Also fine. 275 ldr rD, [rA, #1234]! ; Also fine.
284 bic rA, #0xC0000000 276 bic rA, #0xC0000000
285 ldr rD, [rA], #1234 ; Looking good. 277 ldr rD, [rA], #1234 ; Looking good.
286 </pre> 278 </pre>
287 <p>In each case, we know <code>rA</code> points into the sandbox when the <code> ldr</code> 279 <p>In each case, we know <code>rA</code> points into the sandbox when the <code> ldr</code>
288 executes. We allow adding an immediate displacement to <code>rA</code> to 280 executes. We allow adding an immediate displacement to <code>rA</code> to
289 determine the final address (as in the first two examples here) because 281 determine the final address (as in the first two examples here) because
290 the largest immediate displacement is ±4095 bytes, while our guard pages 282 the largest immediate displacement is ±4095 bytes, while our guard pages
291 are 8192 bytes wide.</p> 283 are 8192 bytes wide.</p>
292 <p>We also allow ARM&#8217;s more unusual <em>load</em> and <em>store</em> instr uctions, such 284 <p>We also allow ARM&#8217;s more unusual <em>load</em> and <em>store</em> instr uctions, such
293 as <em>load-multiple</em> and <em>store-multiple</em>, etc.</p> 285 as <em>load-multiple</em> and <em>store-multiple</em>, etc.</p>
294 </section><section id="conditional-load-and-store">
295 <h5 id="conditional-load-and-store">Conditional <em>Load</em> and <em>Store</em> </h5> 286 <h5 id="conditional-load-and-store">Conditional <em>Load</em> and <em>Store</em> </h5>
296 <p>There&#8217;s one problem with the pseudo-instructions shown above: they are 287 <p>There&#8217;s one problem with the pseudo-instructions shown above: they are
297 unconditional (assuming <code>rA</code> is valid). ARM compilers regularly use 288 unconditional (assuming <code>rA</code> is valid). ARM compilers regularly use
298 conditional <em>load</em> and <em>store</em>, so we should support this in Nativ e 289 conditional <em>load</em> and <em>store</em>, so we should support this in Nativ e
299 Client. We do so by defining alternate, predictable 290 Client. We do so by defining alternate, predictable
300 pseudo-instructions. Here is a conditional <em>store</em> 291 pseudo-instructions. Here is a conditional <em>store</em>
301 (<em>store-if-greater-than</em>) using this pseudo-instruction sequence:</p> 292 (<em>store-if-greater-than</em>) using this pseudo-instruction sequence:</p>
302 <pre> 293 <pre>
303 bicgt rA, #0xC0000000 294 bicgt rA, #0xC0000000
304 strgt rX, [rA, #123] 295 strgt rX, [rA, #123]
305 </pre> 296 </pre>
306 </section></section><section id="the-stack-pointer-thread-pointer-and-program-co unter">
307 <h4 id="the-stack-pointer-thread-pointer-and-program-counter">The Stack Pointer, Thread Pointer, and Program Counter</h4> 297 <h4 id="the-stack-pointer-thread-pointer-and-program-counter">The Stack Pointer, Thread Pointer, and Program Counter</h4>
308 <section id="stack-pointer">
309 <h5 id="stack-pointer">Stack Pointer</h5> 298 <h5 id="stack-pointer">Stack Pointer</h5>
310 <p>In C-like languages, the stack is used to store return addresses during 299 <p>In C-like languages, the stack is used to store return addresses during
311 function calls, as well as any local variables that won&#8217;t fit in 300 function calls, as well as any local variables that won&#8217;t fit in
312 registers. This makes stack operations very common.</p> 301 registers. This makes stack operations very common.</p>
313 <p>Native Client does not require guard instructions on any <em>load</em> or 302 <p>Native Client does not require guard instructions on any <em>load</em> or
314 <em>store</em> involving the stack pointer, <code>sp</code>. This improves perfo rmance 303 <em>store</em> involving the stack pointer, <code>sp</code>. This improves perfo rmance
315 and reduces code size. However, ARM&#8217;s stack pointer isn&#8217;t special: i t&#8217;s 304 and reduces code size. However, ARM&#8217;s stack pointer isn&#8217;t special: i t&#8217;s
316 just another register, called <code>sp</code> only by convention. To make it saf e 305 just another register, called <code>sp</code> only by convention. To make it saf e
317 to use this register as a <em>load</em> or <em>store</em> address without guards , we 306 to use this register as a <em>load</em> or <em>store</em> address without guards , we
318 add a rule: <code>sp</code> must always contain a valid address.</p> 307 add a rule: <code>sp</code> must always contain a valid address.</p>
(...skipping 18 matching lines...) Expand all
337 <p>The <code>bic</code> is similar to the one we used for conditional <em>load</ em> and 326 <p>The <code>bic</code> is similar to the one we used for conditional <em>load</ em> and
338 <em>store</em>, and serves exactly the same purpose: after it completes, <code>s p</code> 327 <em>store</em>, and serves exactly the same purpose: after it completes, <code>s p</code>
339 is a valid address.</p> 328 is a valid address.</p>
340 <aside class="note"> 329 <aside class="note">
341 Clever assembly programmers and compilers may want to use this 330 Clever assembly programmers and compilers may want to use this
342 &#8220;trusted&#8221; property of <code>sp</code> to emit more efficient code: i n a hot 331 &#8220;trusted&#8221; property of <code>sp</code> to emit more efficient code: i n a hot
343 loop instead of using <code>sp</code> as a stack pointer it can be temporarily 332 loop instead of using <code>sp</code> as a stack pointer it can be temporarily
344 used as an index pointer (e.g. to traverse an array). This avoids the 333 used as an index pointer (e.g. to traverse an array). This avoids the
345 extra <code>bic</code> whenever the pointer is updated in the loop. 334 extra <code>bic</code> whenever the pointer is updated in the loop.
346 </aside> 335 </aside>
347 </section><section id="thread-pointer-loads">
348 <h5 id="thread-pointer-loads">Thread Pointer Loads</h5> 336 <h5 id="thread-pointer-loads">Thread Pointer Loads</h5>
349 <p>The thread pointer and IRT thread pointer are stored in the trusted 337 <p>The thread pointer and IRT thread pointer are stored in the trusted
350 address space. All uses and definitions of <code>r9</code> from untrusted code 338 address space. All uses and definitions of <code>r9</code> from untrusted code
351 are forbidden except as follows:</p> 339 are forbidden except as follows:</p>
352 <pre> 340 <pre>
353 ldr Rn, [r9] ; Load user thread pointer. 341 ldr Rn, [r9] ; Load user thread pointer.
354 ldr Rn, [r9, #4] ; Load IRT thread pointer. 342 ldr Rn, [r9, #4] ; Load IRT thread pointer.
355 </pre> 343 </pre>
356 </section><section id="pc-relative-loads">
357 <h5 id="pc-relative-loads"><code>pc</code>-relative Loads</h5> 344 <h5 id="pc-relative-loads"><code>pc</code>-relative Loads</h5>
358 <p>By extension, we also allow <em>load</em> through the <code>pc</code> without a 345 <p>By extension, we also allow <em>load</em> through the <code>pc</code> without a
359 mask. The explanation is quite similar:</p> 346 mask. The explanation is quite similar:</p>
360 <ul class="small-gap"> 347 <ul class="small-gap">
361 <li>Our control-flow isolation rules mean that the <code>pc</code> will always 348 <li>Our control-flow isolation rules mean that the <code>pc</code> will always
362 point into the sandbox.</li> 349 point into the sandbox.</li>
363 <li>The maximum immediate displacement that can be used in a 350 <li>The maximum immediate displacement that can be used in a
364 <code>pc</code>-relative <em>load</em> is smaller than the width of the guard pa ges.</li> 351 <code>pc</code>-relative <em>load</em> is smaller than the width of the guard pa ges.</li>
365 </ul> 352 </ul>
366 <p>We do not allow <code>pc</code>-relative stores, because they look suspicious ly 353 <p>We do not allow <code>pc</code>-relative stores, because they look suspicious ly
367 like self-modifying code, or any addressing mode that would alter the 354 like self-modifying code, or any addressing mode that would alter the
368 <code>pc</code> as a side effect of the <em>load</em>.</p> 355 <code>pc</code> as a side effect of the <em>load</em>.</p>
369 </section></section><section id="indirect-branch">
370 <h4 id="indirect-branch"><em>Indirect Branch</em></h4> 356 <h4 id="indirect-branch"><em>Indirect Branch</em></h4>
371 <p>There are two types of control flow on ARM: direct and indirect. Direct 357 <p>There are two types of control flow on ARM: direct and indirect. Direct
372 control flow instructions have an embedded target address or 358 control flow instructions have an embedded target address or
373 offset. Indirect control flow instructions take their destination 359 offset. Indirect control flow instructions take their destination
374 address from a register. The <code>b</code> (branch) and <code>bl</code> 360 address from a register. The <code>b</code> (branch) and <code>bl</code>
375 (<em>branch-with-link</em>) instructions are <em>direct branch</em> and <em>call </em>, 361 (<em>branch-with-link</em>) instructions are <em>direct branch</em> and <em>call </em>,
376 respectively. The <code>bx</code> (<em>branch-exchange</em>) and <code>blx</code > 362 respectively. The <code>bx</code> (<em>branch-exchange</em>) and <code>blx</code >
377 (<em>branch-with-link-exchange</em>) are the indirect equivalents.</p> 363 (<em>branch-with-link-exchange</em>) are the indirect equivalents.</p>
378 <p>Because the program counter <code>pc</code> is simply another register, ARM a lso 364 <p>Because the program counter <code>pc</code> is simply another register, ARM a lso
379 has many implicit indirect control flow instructions. Programs can 365 has many implicit indirect control flow instructions. Programs can
380 operate on the <code>pc</code> using <em>add</em> or <em>load</em>, or even outl andish (and 366 operate on the <code>pc</code> using <em>add</em> or <em>load</em>, or even outl andish (and
381 often specified as having unpredictable-behavior) things like multiply! 367 often specified as having unpredictable-behavior) things like multiply!
382 In Native Client we ban all such instructions. Indirect control flow is 368 In Native Client we ban all such instructions. Indirect control flow is
383 exclusively through <code>bx</code> and <code>blx</code>. Because all of ARM&#82 17;s control 369 exclusively through <code>bx</code> and <code>blx</code>. Because all of ARM&#82 17;s control
384 flow instructions are called <em>branch</em> instructions, we&#8217;ll use the t erm 370 flow instructions are called <em>branch</em> instructions, we&#8217;ll use the t erm
385 <em>indirect branch</em> from here on, even though this includes things like 371 <em>indirect branch</em> from here on, even though this includes things like
386 <em>virtual call</em>, <em>return</em>, and the like.</p> 372 <em>virtual call</em>, <em>return</em>, and the like.</p>
387 <section id="the-trouble-with-indirection">
388 <h5 id="the-trouble-with-indirection">The Trouble with Indirection</h5> 373 <h5 id="the-trouble-with-indirection">The Trouble with Indirection</h5>
389 <p><em>Indirect branch</em> present two problems for Native Client:</p> 374 <p><em>Indirect branch</em> present two problems for Native Client:</p>
390 <ul class="small-gap"> 375 <ul class="small-gap">
391 <li>We must ensure that they don&#8217;t send execution outside the sandbox.</li > 376 <li>We must ensure that they don&#8217;t send execution outside the sandbox.</li >
392 <li>We must ensure that they don&#8217;t break up the instructions inside a 377 <li>We must ensure that they don&#8217;t break up the instructions inside a
393 pseudo-instruction, by landing on the second one.</li> 378 pseudo-instruction, by landing on the second one.</li>
394 </ul> 379 </ul>
395 <aside class="note"> 380 <aside class="note">
396 On the x86 architectures we must also ensure that it doesn&#8217;t land 381 On the x86 architectures we must also ensure that it doesn&#8217;t land
397 inside an instruction. This is unnecessary on ARM, where all 382 inside an instruction. This is unnecessary on ARM, where all
398 instructions are 32-bit wide. 383 instructions are 32-bit wide.
399 </aside> 384 </aside>
400 <p>Checking both of these for <em>direct branch</em> is easy: the validator just 385 <p>Checking both of these for <em>direct branch</em> is easy: the validator just
401 pulls the (fixed) target address out of the instruction and checks what 386 pulls the (fixed) target address out of the instruction and checks what
402 it points to.</p> 387 it points to.</p>
403 </section><section id="the-native-client-solution-bundles">
404 <h5 id="the-native-client-solution-bundles">The Native Client Solution: &#8220;B undles&#8221;</h5> 388 <h5 id="the-native-client-solution-bundles">The Native Client Solution: &#8220;B undles&#8221;</h5>
405 <p>For <em>indirect branch</em>, we can address the first problem by simply 389 <p>For <em>indirect branch</em>, we can address the first problem by simply
406 masking some high-order bits off the address, like we did for <em>load</em> and 390 masking some high-order bits off the address, like we did for <em>load</em> and
407 <em>store</em>. The second problem is more subtle. Detecting every possible 391 <em>store</em>. The second problem is more subtle. Detecting every possible
408 route that every <em>indirect branch</em> might take is difficult. Instead, we 392 route that every <em>indirect branch</em> might take is difficult. Instead, we
409 take the approach pioneered by the original Native Client: we restrict 393 take the approach pioneered by the original Native Client: we restrict
410 the possible places that any <em>indirect branch</em> can land. On Native 394 the possible places that any <em>indirect branch</em> can land. On Native
411 Client for ARM, <em>indirect branch</em> can target any address that has its 395 Client for ARM, <em>indirect branch</em> can target any address that has its
412 bottom four bits clear&#8212;any address that&#8217;s <code>0 mod 16</code>. We call these 396 bottom four bits clear&#8212;any address that&#8217;s <code>0 mod 16</code>. We call these
413 16-byte chunks of code &#8220;bundles&#8221;. The validator makes sure that no 397 16-byte chunks of code &#8220;bundles&#8221;. The validator makes sure that no
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 A32 code that&#8217;s actually very naughty T32 code, somewhat like forming 449 A32 code that&#8217;s actually very naughty T32 code, somewhat like forming
466 a sentence that happens to be valid in English and French but with 450 a sentence that happens to be valid in English and French but with
467 completely different meanings, complimenting the reader in one 451 completely different meanings, complimenting the reader in one
468 language and insulting them in the other.</p> 452 language and insulting them in the other.</p>
469 <p>You&#8217;ve figured out by now that the bundle alignment restrictions of 453 <p>You&#8217;ve figured out by now that the bundle alignment restrictions of
470 the Native Client sandbox already take care of making this travesty 454 the Native Client sandbox already take care of making this travesty
471 impossible: by masking off the bottom 4 bits of the destination the 455 impossible: by masking off the bottom 4 bits of the destination the
472 interworking nature of ARM&#8217;s <em>indirect branch</em> is completely avoide d.</p> 456 interworking nature of ARM&#8217;s <em>indirect branch</em> is completely avoide d.</p>
473 457
474 </aside> 458 </aside>
475 </section><section id="call-and-return">
476 <h5 id="call-and-return"><em>Call</em> and <em>Return</em></h5> 459 <h5 id="call-and-return"><em>Call</em> and <em>Return</em></h5>
477 <p>On ARM, there is no <em>call</em> or <em>return</em> instruction. A <em>call< /em> is simply a 460 <p>On ARM, there is no <em>call</em> or <em>return</em> instruction. A <em>call< /em> is simply a
478 <em>branch</em> that just happen to load a return address into <code>lr</code>, the link 461 <em>branch</em> that just happen to load a return address into <code>lr</code>, the link
479 register. If the called function is a leaf (that is, if it calls no 462 register. If the called function is a leaf (that is, if it calls no
480 other functions before returning), it simply branches to the address 463 other functions before returning), it simply branches to the address
481 stored in <code>lr</code> to <em>return</em> to its caller:</p> 464 stored in <code>lr</code> to <em>return</em> to its caller:</p>
482 <pre> 465 <pre>
483 bic lr, #0xC000000F 466 bic lr, #0xC000000F
484 bx lr 467 bx lr
485 </pre> 468 </pre>
(...skipping 24 matching lines...) Expand all
510 Client doesn&#8217;t try to prevent infinite loops, but the validator actually 493 Client doesn&#8217;t try to prevent infinite loops, but the validator actually
511 does check the alignment of calls. This is because, when we were writing 494 does check the alignment of calls. This is because, when we were writing
512 the compiler, it was annoying to find out our calls were in the wrong 495 the compiler, it was annoying to find out our calls were in the wrong
513 place by having the program run forever!)</p> 496 place by having the program run forever!)</p>
514 <aside class="note"> 497 <aside class="note">
515 Properly balancing the CPU&#8217;s <em>call</em>/<em>return</em> actually allows it to 498 Properly balancing the CPU&#8217;s <em>call</em>/<em>return</em> actually allows it to
516 perform much better by allowing it to speculatively execute the return 499 perform much better by allowing it to speculatively execute the return
517 address&#8217; code. For more information on ARM&#8217;s <em>call</em>/<em>retur n</em> stack see 500 address&#8217; code. For more information on ARM&#8217;s <em>call</em>/<em>retur n</em> stack see
518 ARM&#8217;s technical reference manual. 501 ARM&#8217;s technical reference manual.
519 </aside> 502 </aside>
520 </section></section><section id="literal-pools-and-data-bundles">
521 <h4 id="literal-pools-and-data-bundles">Literal Pools and Data Bundles</h4> 503 <h4 id="literal-pools-and-data-bundles">Literal Pools and Data Bundles</h4>
522 <p>In the section where we described the ARM architecture, we mentioned 504 <p>In the section where we described the ARM architecture, we mentioned
523 ARM&#8217;s unusual immediate forms. To restate:</p> 505 ARM&#8217;s unusual immediate forms. To restate:</p>
524 <ul class="small-gap"> 506 <ul class="small-gap">
525 <li>ARM instructions are fixed-length, 32-bits, so we can&#8217;t have an 507 <li>ARM instructions are fixed-length, 32-bits, so we can&#8217;t have an
526 instruction that includes an arbitrary 32-bit constant.</li> 508 instruction that includes an arbitrary 32-bit constant.</li>
527 <li>Many ARM instructions can include a modified immediate constant, which 509 <li>Many ARM instructions can include a modified immediate constant, which
528 is flexible, but limited.</li> 510 is flexible, but limited.</li>
529 <li>For any other value (particularly addresses), ARM programs explicitly 511 <li>For any other value (particularly addresses), ARM programs explicitly
530 load constants from inside the code itself.</li> 512 load constants from inside the code itself.</li>
(...skipping 30 matching lines...) Expand all
561 in Native Client... but there&#8217;s a potential flaw. If we let programs 543 in Native Client... but there&#8217;s a potential flaw. If we let programs
562 contain arbitrary data, mingled in with the code, couldn&#8217;t they hide 544 contain arbitrary data, mingled in with the code, couldn&#8217;t they hide
563 malicious instructions this way?</p> 545 malicious instructions this way?</p>
564 <p>The answer is no, because the validator disassembles the entire 546 <p>The answer is no, because the validator disassembles the entire
565 executable region of the program, without regard to whether the 547 executable region of the program, without regard to whether the
566 programmer said a certain chunk was code or data. But this brings the 548 programmer said a certain chunk was code or data. But this brings the
567 opposite problem: what if the program needs to contain a certain 549 opposite problem: what if the program needs to contain a certain
568 constant that just happens to encode a malicious instruction? We want 550 constant that just happens to encode a malicious instruction? We want
569 to allow this, but we have to be certain it will never be executed as 551 to allow this, but we have to be certain it will never be executed as
570 code!</p> 552 code!</p>
571 <section id="data-bundles-to-the-rescue">
572 <h5 id="data-bundles-to-the-rescue">Data Bundles to the Rescue</h5> 553 <h5 id="data-bundles-to-the-rescue">Data Bundles to the Rescue</h5>
573 <p>As we discussed in the last section, ARM code in Native Client is 554 <p>As we discussed in the last section, ARM code in Native Client is
574 structured in 16-byte bundles. We allow literal pools by putting them in 555 structured in 16-byte bundles. We allow literal pools by putting them in
575 special bundles, called data bundles. Each data bundle can contain 12 556 special bundles, called data bundles. Each data bundle can contain 12
576 bytes of arbitrary data, and the program can have as many data bundles 557 bytes of arbitrary data, and the program can have as many data bundles
577 as it likes.</p> 558 as it likes.</p>
578 <p>Each data bundle starts with a breakpoint instruction, <code>bkpt</code>. Thi s 559 <p>Each data bundle starts with a breakpoint instruction, <code>bkpt</code>. Thi s
579 way, if an <em>indirect branch</em> tries to enter the data bundle, the process 560 way, if an <em>indirect branch</em> tries to enter the data bundle, the process
580 will take a fault and the trusted runtime will intervene (by terminating 561 will take a fault and the trusted runtime will intervene (by terminating
581 the program). For example:</p> 562 the program). For example:</p>
(...skipping 19 matching lines...) Expand all
601 awfully specific when you just need a special &#8220;roadblock&#8221; instructio n! 582 awfully specific when you just need a special &#8220;roadblock&#8221; instructio n!
602 Quite true, young Padawan! It happens that this odd <code>bkpt</code> 583 Quite true, young Padawan! It happens that this odd <code>bkpt</code>
603 instruction is encoded as <code>0xE125BE70</code> in A32, and in T32 the 584 instruction is encoded as <code>0xE125BE70</code> in A32, and in T32 the
604 <code>bkpt</code> instruction is encoded as <code>0xBExx</code> (where <code>xx< /code> could be 585 <code>bkpt</code> instruction is encoded as <code>0xBExx</code> (where <code>xx< /code> could be
605 any 8-bit immediate, say <code>0x70</code>) and <code>0xE125</code> encodes the <em>branch</em> 586 any 8-bit immediate, say <code>0x70</code>) and <code>0xE125</code> encodes the <em>branch</em>
606 instruction <code>b.n #0x250</code>. The special roadblock instruction 587 instruction <code>b.n #0x250</code>. The special roadblock instruction
607 therefore doubles as a roadblock in T32, if anything were to go so 588 therefore doubles as a roadblock in T32, if anything were to go so
608 awry that we tried to execute it as a T32 instruction! Much defense, 589 awry that we tried to execute it as a T32 instruction! Much defense,
609 such depth, wow! 590 such depth, wow!
610 </aside> 591 </aside>
611 </section></section></section><section id="trampolines-and-memory-layout">
612 <h3 id="trampolines-and-memory-layout">Trampolines and Memory Layout</h3> 592 <h3 id="trampolines-and-memory-layout">Trampolines and Memory Layout</h3>
613 <p>So far, the rules we&#8217;ve described make for boring programs: they can&#8 217;t 593 <p>So far, the rules we&#8217;ve described make for boring programs: they can&#8 217;t
614 communicate with the outside world!</p> 594 communicate with the outside world!</p>
615 <ul class="small-gap"> 595 <ul class="small-gap">
616 <li>The program can&#8217;t call an external library, or the operating system, 596 <li>The program can&#8217;t call an external library, or the operating system,
617 even to do something simple like draw some pixels on the screen.</li> 597 even to do something simple like draw some pixels on the screen.</li>
618 <li>It also can&#8217;t read or write memory outside of its dedicated sandbox, 598 <li>It also can&#8217;t read or write memory outside of its dedicated sandbox,
619 so communicating that way is right out.</li> 599 so communicating that way is right out.</li>
620 </ul> 600 </ul>
621 <p>We fix this by allowing the untrusted program to call into the trusted 601 <p>We fix this by allowing the untrusted program to call into the trusted
622 runtime using a trampoline. A trampoline is simply a short stretch of 602 runtime using a trampoline. A trampoline is simply a short stretch of
623 code, placed by the trusted runtime at a known location within the 603 code, placed by the trusted runtime at a known location within the
624 sandbox, that is permitted to do things the untrusted program can&#8217;t.</p> 604 sandbox, that is permitted to do things the untrusted program can&#8217;t.</p>
625 <p>Even though trampolines are inside the sandbox, the untrusted program 605 <p>Even though trampolines are inside the sandbox, the untrusted program
626 can&#8217;t modify them: the trusted runtime marks them read-only. It also 606 can&#8217;t modify them: the trusted runtime marks them read-only. It also
627 can&#8217;t do anything clever with the special instructions inside the 607 can&#8217;t do anything clever with the special instructions inside the
628 trampoline&#8212;for example, call it at a slightly offset address to bypass 608 trampoline&#8212;for example, call it at a slightly offset address to bypass
629 some checks&#8212;because the validator only allows trampolines to be 609 some checks&#8212;because the validator only allows trampolines to be
630 reached by <em>indirect branch</em> (or <em>branch-with-link</em>). We structure the 610 reached by <em>indirect branch</em> (or <em>branch-with-link</em>). We structure the
631 trampolines carefully so that they&#8217;re safe to enter at any <code>0 mod 16< /code> 611 trampolines carefully so that they&#8217;re safe to enter at any <code>0 mod 16< /code>
632 address.</p> 612 address.</p>
633 <p>The validator can detect attempts to use the trampolines because they&#8217;r e 613 <p>The validator can detect attempts to use the trampolines because they&#8217;r e
634 loaded at a fixed location in memory. Let&#8217;s look at the memory map of 614 loaded at a fixed location in memory. Let&#8217;s look at the memory map of
635 the Native Client sandbox.</p> 615 the Native Client sandbox.</p>
636 <section id="memory-map">
637 <h4 id="memory-map">Memory Map</h4> 616 <h4 id="memory-map">Memory Map</h4>
638 <p>The ARM sandbox is always at virtual address <code>0</code>, and is exactly 1 GiB 617 <p>The ARM sandbox is always at virtual address <code>0</code>, and is exactly 1 GiB
639 in size. This includes the untrusted program&#8217;s code and data, the 618 in size. This includes the untrusted program&#8217;s code and data, the
640 trampolines, and a small guard region to detect null pointer 619 trampolines, and a small guard region to detect null pointer
641 dereferences. In practice, the untrusted program takes up a bit more 620 dereferences. In practice, the untrusted program takes up a bit more
642 room than this, because of the need for additional guard regions at 621 room than this, because of the need for additional guard regions at
643 either end of the sandbox.</p> 622 either end of the sandbox.</p>
644 <table border="1" class="docutils"> 623 <table border="1" class="docutils">
645 <colgroup> 624 <colgroup>
646 </colgroup> 625 </colgroup>
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 that&#8217;s <code>0 mod 16</code>. However, only even slots are used, so useful 662 that&#8217;s <code>0 mod 16</code>. However, only even slots are used, so useful
684 trampolines are always <code>0 mod 32</code>. If the program calls an odd slot, 663 trampolines are always <code>0 mod 32</code>. If the program calls an odd slot,
685 it will fault, and the trusted runtime will shut it down.</p> 664 it will fault, and the trusted runtime will shut it down.</p>
686 <aside class="note"> 665 <aside class="note">
687 This is a bit of speculative flexibility. While the current bundle 666 This is a bit of speculative flexibility. While the current bundle
688 size of Native Client on ARM is 16 bytes, we&#8217;ve considered the 667 size of Native Client on ARM is 16 bytes, we&#8217;ve considered the
689 possibility of optional 32-byte bundles, to enable certain compiler 668 possibility of optional 32-byte bundles, to enable certain compiler
690 improvements. While this option isn&#8217;t available to untrusted programs 669 improvements. While this option isn&#8217;t available to untrusted programs
691 today, we&#8217;re trying to keep the system &#8220;32-byte clean&#8221;. 670 today, we&#8217;re trying to keep the system &#8220;32-byte clean&#8221;.
692 </aside> 671 </aside>
693 </section><section id="inside-a-trampoline">
694 <h4 id="inside-a-trampoline">Inside a Trampoline</h4> 672 <h4 id="inside-a-trampoline">Inside a Trampoline</h4>
695 <p>When we introduced trampolines, we mentioned that they can do things 673 <p>When we introduced trampolines, we mentioned that they can do things
696 that untrusted programs can&#8217;t. To be more specific, trampolines can jump 674 that untrusted programs can&#8217;t. To be more specific, trampolines can jump
697 to locations outside the sandbox. On ARM, this is all they do. Here&#8217;s a 675 to locations outside the sandbox. On ARM, this is all they do. Here&#8217;s a
698 typical trampoline fragment on ARM:</p> 676 typical trampoline fragment on ARM:</p>
699 <pre> 677 <pre>
700 ; Even trampoline bundle: 678 ; Even trampoline bundle:
701 push { r0-r3 } ; Save arguments that may be in registers. 679 push { r0-r3 } ; Save arguments that may be in registers.
702 push { lr } ; Save the untrusted return address, 680 push { lr } ; Save the untrusted return address,
703 ; separate step because it must be on top. 681 ; separate step because it must be on top.
704 ldr r0, [pc, #4] ; Load the destination address from 682 ldr r0, [pc, #4] ; Load the destination address from
705 ; the next bundle. 683 ; the next bundle.
706 blx r0 ; Go! 684 blx r0 ; Go!
707 ; The odd trampoline that immediately follows: 685 ; The odd trampoline that immediately follows:
708 bkpt 0x5be0 ; Prevent entry to this data bundle. 686 bkpt 0x5be0 ; Prevent entry to this data bundle.
709 .word address_of_routine 687 .word address_of_routine
710 </pre> 688 </pre>
711 <p>The only odd thing here is that we push the incoming value of <code>lr</code> , 689 <p>The only odd thing here is that we push the incoming value of <code>lr</code> ,
712 and then use <code>blx</code>&#8212;not <code>bx</code>&#8212;to escape the sand box. This is 690 and then use <code>blx</code>&#8212;not <code>bx</code>&#8212;to escape the sand box. This is
713 because, in practice, all trampolines jump to the same routine in the 691 because, in practice, all trampolines jump to the same routine in the
714 trusted runtime, called the syscall hook. It uses the return address 692 trusted runtime, called the syscall hook. It uses the return address
715 produced by the final <code>blx</code> instruction to determine which trampoline 693 produced by the final <code>blx</code> instruction to determine which trampoline
716 was called.</p> 694 was called.</p>
717 </section></section><section id="loose-ends">
718 <h3 id="loose-ends">Loose Ends</h3> 695 <h3 id="loose-ends">Loose Ends</h3>
719 <section id="forbidden-instructions">
720 <h4 id="forbidden-instructions">Forbidden Instructions</h4> 696 <h4 id="forbidden-instructions">Forbidden Instructions</h4>
721 <p>To complete the sandbox, the validator ensures that the program does not 697 <p>To complete the sandbox, the validator ensures that the program does not
722 try to use certain forbidden instructions.</p> 698 try to use certain forbidden instructions.</p>
723 <ul class="small-gap"> 699 <ul class="small-gap">
724 <li>We forbid instructions that directly interact with the operating 700 <li>We forbid instructions that directly interact with the operating
725 system by going around the trusted runtime. We prevent this to limit 701 system by going around the trusted runtime. We prevent this to limit
726 the functionality of the untrusted program, and to ensure portability 702 the functionality of the untrusted program, and to ensure portability
727 across operating systems.</li> 703 across operating systems.</li>
728 <li>We forbid instructions that change the processor&#8217;s execution mode to 704 <li>We forbid instructions that change the processor&#8217;s execution mode to
729 Thumb, ThumbEE, or Jazelle. This would cause the code to be 705 Thumb, ThumbEE, or Jazelle. This would cause the code to be
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 <li><code>STM</code>, kernel version: not available to user code.</li> 741 <li><code>STM</code>, kernel version: not available to user code.</li>
766 <li><code>STR*T</code> (unprivileged store operations): theoretically harmless, 742 <li><code>STR*T</code> (unprivileged store operations): theoretically harmless,
767 but suspicious when found in user code. Use <code>STR</code> instead.</li> 743 but suspicious when found in user code. Use <code>STR</code> instead.</li>
768 <li><code>SVC</code>/<code>SWI</code>: allows direct operating system interactio n.</li> 744 <li><code>SVC</code>/<code>SWI</code>: allows direct operating system interactio n.</li>
769 <li>Any unassigned hint instruction: difficult to reason about, so 745 <li>Any unassigned hint instruction: difficult to reason about, so
770 treated as suspicious.</li> 746 treated as suspicious.</li>
771 </ul> 747 </ul>
772 <p>More details are available in the <a class="reference external" href="http:// src.chromium.org/viewvc/native_client/trunk/src/native_client/src/trusted/valida tor_arm/armv7.table">ARMv7 instruction table definition</a>.</p> 748 <p>More details are available in the <a class="reference external" href="http:// src.chromium.org/viewvc/native_client/trunk/src/native_client/src/trusted/valida tor_arm/armv7.table">ARMv7 instruction table definition</a>.</p>
773 749
774 </aside> 750 </aside>
775 </section><section id="coprocessors">
776 <h4 id="coprocessors">Coprocessors</h4> 751 <h4 id="coprocessors">Coprocessors</h4>
777 <p>ARM has traditionally added new instruction set features through 752 <p>ARM has traditionally added new instruction set features through
778 coprocessors. Coprocessors are accessed through a small set of 753 coprocessors. Coprocessors are accessed through a small set of
779 instructions, and often have their own register files. Floating point 754 instructions, and often have their own register files. Floating point
780 and the NEON vector extensions are both implemented as coprocessors, as 755 and the NEON vector extensions are both implemented as coprocessors, as
781 is the MMU.</p> 756 is the MMU.</p>
782 <p>We&#8217;re confident that the side-effects of coprocessors in slots 10 and 1 1 757 <p>We&#8217;re confident that the side-effects of coprocessors in slots 10 and 1 1
783 (that is, floating point, NEON, etc.) are well-understood. These are in 758 (that is, floating point, NEON, etc.) are well-understood. These are in
784 the coprocessor space reserved by ARM Ltd. for their own extensions 759 the coprocessor space reserved by ARM Ltd. for their own extensions
785 (<code>CP8</code>&#8211;<code>CP15</code>), and are unlikely to change significa ntly. So, we 760 (<code>CP8</code>&#8211;<code>CP15</code>), and are unlikely to change significa ntly. So, we
786 allow untrusted code to use coprocessors 10 and 11, and we mandate the 761 allow untrusted code to use coprocessors 10 and 11, and we mandate the
787 presence of at least VFPv3 and NEON/AdvancedSIMD. Multiprocessor 762 presence of at least VFPv3 and NEON/AdvancedSIMD. Multiprocessor
788 Extension, VFPv4, FP16 and other extensions are allowed but not 763 Extension, VFPv4, FP16 and other extensions are allowed but not
789 required, and may fail on processors that do not support them, it is 764 required, and may fail on processors that do not support them, it is
790 therefore the program&#8217;s responsibility to validate their availability 765 therefore the program&#8217;s responsibility to validate their availability
791 before executing them.</p> 766 before executing them.</p>
792 <p>We don&#8217;t allow access to any other ARM-reserved coprocessor 767 <p>We don&#8217;t allow access to any other ARM-reserved coprocessor
793 (<code>CP8</code>&#8211;<code>CP9</code> or <code>CP12</code>&#8211;<code>CP15</ code>). It&#8217;s possible that read 768 (<code>CP8</code>&#8211;<code>CP9</code> or <code>CP12</code>&#8211;<code>CP15</ code>). It&#8217;s possible that read
794 access to <code>CP15</code> might be useful, and we might allow it in the 769 access to <code>CP15</code> might be useful, and we might allow it in the
795 future&#8212;but again, it&#8217;s easier to loosen the restrictions than tighte n 770 future&#8212;but again, it&#8217;s easier to loosen the restrictions than tighte n
796 them, so we ban it for now.</p> 771 them, so we ban it for now.</p>
797 <p>We do not, and probably never will, allow access to the vendor-specific 772 <p>We do not, and probably never will, allow access to the vendor-specific
798 coprocessor space, <code>CP0</code>&#8211;<code>CP7</code>. We&#8217;re simply n ot confident in our 773 coprocessor space, <code>CP0</code>&#8211;<code>CP7</code>. We&#8217;re simply n ot confident in our
799 ability to model the operations on these coprocessors, given that 774 ability to model the operations on these coprocessors, given that
800 vendors often leave them poorly-specified. Unfortunately this eliminates 775 vendors often leave them poorly-specified. Unfortunately this eliminates
801 some legacy floating point and vector implementations, but these are 776 some legacy floating point and vector implementations, but these are
802 superceded on ARMv7-A parts anyway.</p> 777 superceded on ARMv7-A parts anyway.</p>
803 </section><section id="validator-code">
804 <h4 id="validator-code">Validator Code</h4> 778 <h4 id="validator-code">Validator Code</h4>
805 <p>By now you&#8217;re itching to see the sandbox validator&#8217;s code and dis sect 779 <p>By now you&#8217;re itching to see the sandbox validator&#8217;s code and dis sect
806 it. You&#8217;ll have a disapointing read: at less that 500 lines of code 780 it. You&#8217;ll have a disapointing read: at less that 500 lines of code
807 <a class="reference external" href="http://src.chromium.org/viewvc/native_client /trunk/src/native_client/src/trusted/validator_arm/validator.cc">validator.cc</a > 781 <a class="reference external" href="http://src.chromium.org/viewvc/native_client /trunk/src/native_client/src/trusted/validator_arm/validator.cc">validator.cc</a >
808 is quite simple to understand and much shorter than this document. It&#8217;s 782 is quite simple to understand and much shorter than this document. It&#8217;s
809 of course dependent on the <a class="reference external" href="http://src.chromi um.org/viewvc/native_client/trunk/src/native_client/src/trusted/validator_arm/ar mv7.table">ARMv7 instruction table definition</a>, 783 of course dependent on the <a class="reference external" href="http://src.chromi um.org/viewvc/native_client/trunk/src/native_client/src/trusted/validator_arm/ar mv7.table">ARMv7 instruction table definition</a>,
810 which teaches it about the ARMv7 instruction set.</p> 784 which teaches it about the ARMv7 instruction set.</p>
811 </section></section></section></section> 785 </section>
812 786
813 {{/partials.standard_nacl_article}} 787 {{/partials.standard_nacl_article}}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698