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

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: 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
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 RestrictMemoryProtection(SandboxBPF* sb, int argno) {
jln (very slow on Chromium) 2014/04/24 16:46:38 Maybe change this to "RestrictMprotect", without |
hamaji 2014/04/25 01:44:47 No, I'd prefer renaming this to RestrictMprotect.
114 // TODO(jln, keescook, drewry): Limit the use of mmap/mprotect by 114 // TODO(jln, keescook, drewry): Limit the use of mmap/mprotect by
115 // adding some features to linux kernel. 115 // adding 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(argno, 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 const uint32_t denied_prot_mask = ~(PROT_READ | PROT_WRITE);
Mark Seaborn 2014/04/24 16:49:30 It's not really obvious why you'd want to do this.
hamaji 2014/04/25 01:44:47 I just guessed this would slight improve security.
128 return sb->Cond(3, ErrorCode::TP_32BIT, 128 return sb->Cond(3, ErrorCode::TP_32BIT,
129 ErrorCode::OP_HAS_ANY_BITS, 129 ErrorCode::OP_HAS_ANY_BITS,
130 denied_flag_mask, 130 denied_flag_mask,
131 sb->Trap(sandbox::CrashSIGSYS_Handler, NULL), 131 sb->Trap(sandbox::CrashSIGSYS_Handler, NULL),
132 RestrictMemoryProtection(sb, 2)); 132 sb->Cond(2, ErrorCode::TP_32BIT,
133 ErrorCode::OP_HAS_ANY_BITS,
134 denied_prot_mask,
135 sb->Trap(sandbox::CrashSIGSYS_Handler, NULL),
136 ErrorCode(ErrorCode::ERR_ALLOWED)));
133 } 137 }
134 138
135 ErrorCode RestrictSocketpair(SandboxBPF* sb) { 139 ErrorCode RestrictSocketpair(SandboxBPF* sb) {
136 // Only allow AF_UNIX, PF_UNIX. Crash if anything else is seen. 140 // Only allow AF_UNIX, PF_UNIX. Crash if anything else is seen.
137 COMPILE_ASSERT(AF_UNIX == PF_UNIX, af_unix_pf_unix_different); 141 COMPILE_ASSERT(AF_UNIX == PF_UNIX, af_unix_pf_unix_different);
138 return sb->Cond(0, ErrorCode::TP_32BIT, 142 return sb->Cond(0, ErrorCode::TP_32BIT,
139 ErrorCode::OP_EQUAL, AF_UNIX, 143 ErrorCode::OP_EQUAL, AF_UNIX,
140 ErrorCode(ErrorCode::ERR_ALLOWED), 144 ErrorCode(ErrorCode::ERR_ALLOWED),
141 sb->Trap(sandbox::CrashSIGSYS_Handler, NULL)); 145 sb->Trap(sandbox::CrashSIGSYS_Handler, NULL));
142 } 146 }
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 scoped_ptr<sandbox::SandboxBPFPolicy>( 310 scoped_ptr<sandbox::SandboxBPFPolicy>(
307 new nacl::nonsfi::NaClNonSfiBPFSandboxPolicy())); 311 new nacl::nonsfi::NaClNonSfiBPFSandboxPolicy()));
308 if (!sandbox_is_initialized) 312 if (!sandbox_is_initialized)
309 return false; 313 return false;
310 RunSandboxSanityChecks(); 314 RunSandboxSanityChecks();
311 return true; 315 return true;
312 } 316 }
313 317
314 } // namespace nonsfi 318 } // namespace nonsfi
315 } // namespace nacl 319 } // namespace nacl
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698