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

Side by Side Diff: src/trusted/service_runtime/arch/arm/sel_addrspace_arm.c

Issue 7677036: Enable the service runtime to use a zero-based sandbox on Linux. (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client
Patch Set: more fixes for bots Created 9 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 /* 1 /*
2 * Copyright 2009 The Native Client Authors. All rights reserved. 2 * Copyright 2009 The Native Client Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can 3 * Use of this source code is governed by a BSD-style license that can
4 * be found in the LICENSE file. 4 * be found in the LICENSE file.
5 */ 5 */
6 6
7 #include "native_client/src/include/nacl_platform.h" 7 #include "native_client/src/include/nacl_platform.h"
8 #include "native_client/src/shared/platform/nacl_check.h" 8 #include "native_client/src/shared/platform/nacl_check.h"
9 #include "native_client/src/trusted/service_runtime/nacl_error_code.h" 9 #include "native_client/src/trusted/service_runtime/nacl_error_code.h"
10 #include "native_client/src/trusted/service_runtime/sel_ldr.h" 10 #include "native_client/src/trusted/service_runtime/sel_ldr.h"
11 #include "native_client/src/trusted/service_runtime/sel_memory.h" 11 #include "native_client/src/trusted/service_runtime/sel_memory.h"
12 12
13 13
14 #define POST_ADDR_SPACE_GUARD_SIZE (2 * NACL_PAGESIZE)
15
16 /* 14 /*
17 * On ARM, we cheat slightly: we add two pages to the requested allocation! 15 * On ARM, we cheat slightly: we add two pages to the requested allocation!
18 * This accomodates the guard region we require at the top end of untrusted 16 * This accomodates the guard region we require at the top end of untrusted
19 * memory. 17 * memory.
20 */ 18 */
19 #define POST_ADDR_SPACE_GUARD_SIZE (2 * NACL_PAGESIZE)
20
21 /* NOTE: This routine is almost identical to the x86_32 version.
22 */
21 NaClErrorCode NaClAllocateSpace(void **mem, size_t addrsp_size) { 23 NaClErrorCode NaClAllocateSpace(void **mem, size_t addrsp_size) {
22 CHECK(mem); 24 #if NACL_LINUX
25 const void *ONE_MEGABYTE = (void *)(1024*1024);
26 #endif
27 int result;
28
29 CHECK(NULL != mem);
23 30
24 addrsp_size += POST_ADDR_SPACE_GUARD_SIZE; 31 addrsp_size += POST_ADDR_SPACE_GUARD_SIZE;
32 #if NACL_LINUX
33 /*
34 * When creating a zero-based sandbox, we do not allocate the first 64K of
35 * pages beneath the trampolines, because -- on Linux at least -- we cannot.
36 * Instead, we allocate starting at the trampolines, and then coerce the
37 * "mem" out parameter.
38 */
25 addrsp_size -= NACL_TRAMPOLINE_START; 39 addrsp_size -= NACL_TRAMPOLINE_START;
26
27 *mem = (void *) NACL_TRAMPOLINE_START; 40 *mem = (void *) NACL_TRAMPOLINE_START;
28 if (NaCl_page_alloc_at_addr(mem, addrsp_size) != 0) { 41 /*
42 * On 32 bit Linux, a 1 gigabyte block of address space may be reserved at
43 * the zero-end of the address space during process creation, to address
44 * sandbox layout requirements on ARM and performance issues on Intel ATOM.
45 * Look for this pre-reserved block and if found, pass its address to the
46 * page allocation function.
47 */
48 if (NaCl_find_prereserved_sandbox_memory(mem, addrsp_size)) {
49 /* Sanity check zero sandbox base address. */
50 /* It should be within a few pages above the 64KB boundary. See */
Mark Seaborn 2011/08/23 18:26:36 Nit: Comment style
Brad Chen 2011/08/23 21:15:09 Done.
51 /* chrome/nacl/nacl_helper_bootstrap.c in the Chromium repository */
52 /* for more details. */
53 if (0 == *mem || ONE_MEGABYTE < *mem) {
bsy 2011/08/23 18:31:23 just assigned to *mem NACL_TRAMPOLINE_START, so al
Brad Chen 2011/08/23 21:15:09 I moved initialization into else clause where it i
54 NaClLog(LOG_ERROR, "NaClAllocateSpace:"
55 "Can't handle sandbox at high address"
56 "0x%08"NACL_PRIxPTR"\n",
57 (uintptr_t)*mem);
58 return LOAD_NO_MEMORY;
59 }
bsy 2011/08/23 18:43:19 if we find memory, we should ensure squatting betw
Brad Chen 2011/08/23 21:15:09 I think this is already taken care of. You need to
60 } else {
61 /* Zero-based sandbox not pre-reserved. Try anyways. */
62 /* TODO(bradchen): delete once new code is working. */
63 }
64 result = NaCl_page_alloc_at_addr(mem, addrsp_size);
bsy 2011/08/23 18:31:23 since NaCl_find_prereserved_sandbox_memory had zer
Brad Chen 2011/08/23 21:15:09 If *mem is zero after NaCl_fpsm(), then we will re
65 *mem = 0;
66 #else
67 # error "I only know how to allocate memory for ARM on Linux."
68 #endif
69 if (0 != result) {
29 NaClLog(2, 70 NaClLog(2,
30 "NaClAllocateSpace: NaCl_page_alloc_at_addr 0x%08"NACL_PRIxPTR 71 "NaClAllocateSpace: NaCl_page_alloc_at_addr 0x%08"NACL_PRIxPTR
31 " failed\n", 72 " failed\n",
32 (uintptr_t) *mem); 73 (uintptr_t) *mem);
33 return LOAD_NO_MEMORY; 74 return LOAD_NO_MEMORY;
34 } 75 }
35 NaClLog(4, "NaClAllocateSpace: %"NACL_PRIxPTR", %"NACL_PRIxS"\n", 76 NaClLog(4, "NaClAllocateSpace: %"NACL_PRIxPTR", %"NACL_PRIxS"\n",
36 (uintptr_t) *mem, 77 (uintptr_t) *mem,
37 addrsp_size); 78 addrsp_size);
38 79
39 /*
40 * makes sel_ldr think that the module's address space is at 0x0, this where
41 * it should be
42 */
43 *mem = 0x0;
44
45 return LOAD_OK; 80 return LOAD_OK;
46 } 81 }
47 82
48 /* 83 /*
49 * In the ARM sandboxing scheme we put the NaCl module at low virtual 84 * In the ARM sandboxing scheme we put the NaCl module at low virtual
50 * address -- and thus there can only ever be one running NaCl app per 85 * address -- and thus there can only ever be one running NaCl app per
51 * sel_ldr process -- to simplify the address masking etc needed for 86 * sel_ldr process -- to simplify the address masking etc needed for
52 * the sandboxing. All memory below ((uintptr_t) 1) << nap->addr_bits 87 * the sandboxing. All memory below ((uintptr_t) 1) << nap->addr_bits
53 * is accessible to the NaCl app, and modulo page protection, 88 * is accessible to the NaCl app, and modulo page protection,
54 * potentially writable. Page protection is, of course, used to 89 * potentially writable. Page protection is, of course, used to
(...skipping 11 matching lines...) Expand all
66 * address 0x0, so we mmap it at the start of a trampoline region. 101 * address 0x0, so we mmap it at the start of a trampoline region.
67 * Therefore, there is not need to mprotect at the start_addr. 102 * Therefore, there is not need to mprotect at the start_addr.
68 * 103 *
69 * However, we do create a vmmap entry to describe it. 104 * However, we do create a vmmap entry to describe it.
70 */ 105 */
71 NaClLog(3, 106 NaClLog(3,
72 ("NULL detection region start 0x%08"NACL_PRIxPTR", " 107 ("NULL detection region start 0x%08"NACL_PRIxPTR", "
73 "size 0x%08x, end 0x%08"NACL_PRIxPTR"\n"), 108 "size 0x%08x, end 0x%08"NACL_PRIxPTR"\n"),
74 0, NACL_SYSCALL_START_ADDR, 109 0, NACL_SYSCALL_START_ADDR,
75 NACL_SYSCALL_START_ADDR); 110 NACL_SYSCALL_START_ADDR);
111
76 if (!NaClVmmapAdd(&nap->mem_map, 112 if (!NaClVmmapAdd(&nap->mem_map,
77 nap->mem_start >> NACL_PAGESHIFT, 113 nap->mem_start >> NACL_PAGESHIFT,
78 NACL_SYSCALL_START_ADDR >> NACL_PAGESHIFT, 114 NACL_SYSCALL_START_ADDR >> NACL_PAGESHIFT,
79 PROT_NONE, 115 PROT_NONE,
80 (struct NaClMemObj *) NULL)) { 116 (struct NaClMemObj *) NULL)) {
81 NaClLog(LOG_ERROR, ("NaClMemoryProtection: NaClVmmapAdd failed" 117 NaClLog(LOG_ERROR, ("NaClMemoryProtection: NaClVmmapAdd failed"
82 " (NULL pointer guard page)\n")); 118 " (NULL pointer guard page)\n"));
83 return LOAD_MPROTECT_FAIL; 119 return LOAD_MPROTECT_FAIL;
84 } 120 }
85 121
(...skipping 17 matching lines...) Expand all
103 * NB: the pages just mapped are OUTSIDE of the address space of the 139 * NB: the pages just mapped are OUTSIDE of the address space of the
104 * NaCl module. We should not track them in the Vmmap structure, 140 * NaCl module. We should not track them in the Vmmap structure,
105 * since that's to track addressable memory for mapping and unmapping. 141 * since that's to track addressable memory for mapping and unmapping.
106 * 142 *
107 * This means that because these pages are implicit and not tracked, 143 * This means that because these pages are implicit and not tracked,
108 * we should have a hook to tear down these pages as part of the 144 * we should have a hook to tear down these pages as part of the
109 * NaClApp dtor. 145 * NaClApp dtor.
110 */ 146 */
111 return LOAD_OK; 147 return LOAD_OK;
112 } 148 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698