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

Side by Side Diff: components/nacl/loader/nonsfi/nonsfi_sandbox.cc

Issue 247563004: Non-SFI NaCl: Disallow mmap with PROT_EXEC (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 6 years, 8 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
« no previous file with comments | « no previous file | components/nacl/loader/nonsfi/nonsfi_sandbox_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/nacl/loader/nonsfi/nonsfi_sandbox.h" 5 #include "components/nacl/loader/nonsfi/nonsfi_sandbox.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <linux/net.h> 9 #include <linux/net.h>
10 #include <sys/prctl.h> 10 #include <sys/prctl.h>
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 sb->Cond(0, ErrorCode::TP_32BIT, ErrorCode::OP_EQUAL, 103 sb->Cond(0, ErrorCode::TP_32BIT, ErrorCode::OP_EQUAL,
104 SYS_RECVMSG, 104 SYS_RECVMSG,
105 ErrorCode(ErrorCode::ERR_ALLOWED), 105 ErrorCode(ErrorCode::ERR_ALLOWED),
106 sb->Cond(0, ErrorCode::TP_32BIT, ErrorCode::OP_EQUAL, 106 sb->Cond(0, ErrorCode::TP_32BIT, ErrorCode::OP_EQUAL,
107 SYS_SHUTDOWN, 107 SYS_SHUTDOWN,
108 ErrorCode(ErrorCode::ERR_ALLOWED), 108 ErrorCode(ErrorCode::ERR_ALLOWED),
109 sb->Trap(sandbox::CrashSIGSYS_Handler, NULL))))); 109 sb->Trap(sandbox::CrashSIGSYS_Handler, NULL)))));
110 } 110 }
111 #endif 111 #endif
112 112
113 ErrorCode RestrictMemoryProtection(SandboxBPF* sb, int argno) { 113 ErrorCode RestrictMprotect(SandboxBPF* sb) {
114 // TODO(jln, keescook, drewry): Limit the use of mmap/mprotect by 114 // TODO(jln, keescook, drewry): Limit the use of mprotect by adding
115 // adding some features to linux kernel. 115 // some features to linux kernel.
116 const uint32_t denied_mask = ~(PROT_READ | PROT_WRITE | PROT_EXEC); 116 const uint32_t denied_mask = ~(PROT_READ | PROT_WRITE | PROT_EXEC);
117 return sb->Cond(argno, ErrorCode::TP_32BIT, 117 return sb->Cond(2, ErrorCode::TP_32BIT,
118 ErrorCode::OP_HAS_ANY_BITS, 118 ErrorCode::OP_HAS_ANY_BITS,
119 denied_mask, 119 denied_mask,
120 sb->Trap(sandbox::CrashSIGSYS_Handler, NULL), 120 sb->Trap(sandbox::CrashSIGSYS_Handler, NULL),
121 ErrorCode(ErrorCode::ERR_ALLOWED)); 121 ErrorCode(ErrorCode::ERR_ALLOWED));
122 } 122 }
123 123
124 ErrorCode RestrictMmap(SandboxBPF* sb) { 124 ErrorCode RestrictMmap(SandboxBPF* sb) {
125 const uint32_t denied_flag_mask = ~(MAP_SHARED | MAP_PRIVATE | 125 const uint32_t denied_flag_mask = ~(MAP_SHARED | MAP_PRIVATE |
126 MAP_ANONYMOUS | MAP_STACK | MAP_FIXED); 126 MAP_ANONYMOUS | MAP_STACK | MAP_FIXED);
127 // TODO(hamaji): Disallow RWX mmap. 127 // When PROT_EXEC is specified, IRT mmap of Non-SFI NaCl helper
128 // calls mmap without PROT_EXEC and then add PROT_EXEC by mprotect,
Mark Seaborn 2014/04/26 00:26:01 "adds"
hamaji 2014/04/26 02:13:25 Done.
129 // so we do not need to allow PROT_EXEC in mmap.
130 const uint32_t denied_prot_mask = ~(PROT_READ | PROT_WRITE);
128 return sb->Cond(3, ErrorCode::TP_32BIT, 131 return sb->Cond(3, ErrorCode::TP_32BIT,
129 ErrorCode::OP_HAS_ANY_BITS, 132 ErrorCode::OP_HAS_ANY_BITS,
130 denied_flag_mask, 133 denied_flag_mask,
131 sb->Trap(sandbox::CrashSIGSYS_Handler, NULL), 134 sb->Trap(sandbox::CrashSIGSYS_Handler, NULL),
132 RestrictMemoryProtection(sb, 2)); 135 sb->Cond(2, ErrorCode::TP_32BIT,
136 ErrorCode::OP_HAS_ANY_BITS,
137 denied_prot_mask,
138 sb->Trap(sandbox::CrashSIGSYS_Handler, NULL),
139 ErrorCode(ErrorCode::ERR_ALLOWED)));
133 } 140 }
134 141
135 ErrorCode RestrictSocketpair(SandboxBPF* sb) { 142 ErrorCode RestrictSocketpair(SandboxBPF* sb) {
136 // Only allow AF_UNIX, PF_UNIX. Crash if anything else is seen. 143 // Only allow AF_UNIX, PF_UNIX. Crash if anything else is seen.
137 COMPILE_ASSERT(AF_UNIX == PF_UNIX, af_unix_pf_unix_different); 144 COMPILE_ASSERT(AF_UNIX == PF_UNIX, af_unix_pf_unix_different);
138 return sb->Cond(0, ErrorCode::TP_32BIT, 145 return sb->Cond(0, ErrorCode::TP_32BIT,
139 ErrorCode::OP_EQUAL, AF_UNIX, 146 ErrorCode::OP_EQUAL, AF_UNIX,
140 ErrorCode(ErrorCode::ERR_ALLOWED), 147 ErrorCode(ErrorCode::ERR_ALLOWED),
141 sb->Trap(sandbox::CrashSIGSYS_Handler, NULL)); 148 sb->Trap(sandbox::CrashSIGSYS_Handler, NULL));
142 } 149 }
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 return RestrictFcntlCommands(sb); 267 return RestrictFcntlCommands(sb);
261 268
262 #if defined(__x86_64__) 269 #if defined(__x86_64__)
263 case __NR_mmap: 270 case __NR_mmap:
264 #endif 271 #endif
265 #if defined(__i386__) || defined(__arm__) 272 #if defined(__i386__) || defined(__arm__)
266 case __NR_mmap2: 273 case __NR_mmap2:
267 #endif 274 #endif
268 return RestrictMmap(sb); 275 return RestrictMmap(sb);
269 case __NR_mprotect: 276 case __NR_mprotect:
270 return RestrictMemoryProtection(sb, 2); 277 return RestrictMprotect(sb);
271 278
272 case __NR_prctl: 279 case __NR_prctl:
273 return RestrictPrctl(sb); 280 return RestrictPrctl(sb);
274 281
275 #if defined(__i386__) 282 #if defined(__i386__)
276 case __NR_socketcall: 283 case __NR_socketcall:
277 return RestrictSocketcall(sb); 284 return RestrictSocketcall(sb);
278 #endif 285 #endif
279 #if defined(__x86_64__) || defined(__arm__) 286 #if defined(__x86_64__) || defined(__arm__)
280 case __NR_recvmsg: 287 case __NR_recvmsg:
(...skipping 25 matching lines...) Expand all
306 scoped_ptr<sandbox::SandboxBPFPolicy>( 313 scoped_ptr<sandbox::SandboxBPFPolicy>(
307 new nacl::nonsfi::NaClNonSfiBPFSandboxPolicy())); 314 new nacl::nonsfi::NaClNonSfiBPFSandboxPolicy()));
308 if (!sandbox_is_initialized) 315 if (!sandbox_is_initialized)
309 return false; 316 return false;
310 RunSandboxSanityChecks(); 317 RunSandboxSanityChecks();
311 return true; 318 return true;
312 } 319 }
313 320
314 } // namespace nonsfi 321 } // namespace nonsfi
315 } // namespace nacl 322 } // namespace nacl
OLDNEW
« no previous file with comments | « no previous file | components/nacl/loader/nonsfi/nonsfi_sandbox_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698