| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium OS 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 // Some portions Copyright (c) 2009 The Chromium Authors. | 4 // Some portions Copyright (c) 2009 The Chromium Authors. |
| 5 // | 5 // |
| 6 // Default implementation of the Env interface. | 6 // Default implementation of the Env interface. |
| 7 | 7 |
| 8 #include "minijail/env.h" | 8 #include "minijail/env.h" |
| 9 | 9 |
| 10 #include <asm/unistd.h> | 10 #include <asm/unistd.h> |
| 11 #include <errno.h> | 11 #include <errno.h> |
| 12 #include <fcntl.h> | 12 #include <fcntl.h> |
| 13 #include <grp.h> | 13 #include <grp.h> |
| 14 #include <pwd.h> | 14 #include <pwd.h> |
| 15 #include <sched.h> | 15 #include <sched.h> |
| 16 #include <signal.h> | 16 #include <signal.h> |
| 17 #include <stdarg.h> | 17 #include <stdarg.h> |
| 18 #include <stdbool.h> | 18 #include <stdbool.h> |
| 19 #include <stdio.h> | 19 #include <stdio.h> |
| 20 #include <stdlib.h> | 20 #include <stdlib.h> |
| 21 #include <string.h> | 21 #include <string.h> |
| 22 #include <sys/capability.h> | 22 #include <sys/capability.h> |
| 23 #include <sys/mount.h> | 23 #include <sys/mount.h> |
| 24 #include <sys/prctl.h> | 24 #include <sys/prctl.h> |
| 25 #include <sys/resource.h> | 25 #include <sys/resource.h> |
| 26 #include <sys/socket.h> | 26 #include <sys/socket.h> |
| 27 #include <sys/stat.h> | 27 #include <sys/stat.h> |
| 28 #include <sys/time.h> | 28 #include <sys/time.h> |
| 29 #include <sys/types.h> | 29 #include <sys/types.h> |
| 30 #include <sys/wait.h> |
| 30 #include <unistd.h> | 31 #include <unistd.h> |
| 31 | 32 |
| 32 #include <base/logging.h> | 33 #include <base/logging.h> |
| 33 | 34 |
| 34 // prctl constants that are still missing in the headers. | 35 // prctl constants that are still missing in the headers. |
| 35 #define PR_GET_KEEPCAPS 7 | 36 #define PR_GET_KEEPCAPS 7 |
| 36 #define PR_SET_KEEPCAPS 8 | 37 #define PR_SET_KEEPCAPS 8 |
| 37 #define PR_CAPBSET_READ 23 | 38 #define PR_CAPBSET_READ 23 |
| 38 #define PR_CAPBSET_DROP 24 | 39 #define PR_CAPBSET_DROP 24 |
| 39 #define PR_GET_SECUREBITS 27 | 40 #define PR_GET_SECUREBITS 27 |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 } | 197 } |
| 197 DLOG(INFO) << "Entering namespaces " << namespaces; | 198 DLOG(INFO) << "Entering namespaces " << namespaces; |
| 198 // TODO(wad) support namespace args | 199 // TODO(wad) support namespace args |
| 199 const pid_t pid = syscall( | 200 const pid_t pid = syscall( |
| 200 __NR_clone, namespaces | CLONE_VFORK | SIGCHLD, 0, 0, 0); | 201 __NR_clone, namespaces | CLONE_VFORK | SIGCHLD, 0, 0, 0); |
| 201 if (pid == -1) { | 202 if (pid == -1) { |
| 202 PLOG(FATAL) << "Could not use PID namespacing"; | 203 PLOG(FATAL) << "Could not use PID namespacing"; |
| 203 return false; | 204 return false; |
| 204 } | 205 } |
| 205 if (pid) { | 206 if (pid) { |
| 207 // We want to wait on the child pid to ensure that pid-tracking code |
| 208 // isn't completely broken. |
| 209 int status = 0; |
| 210 waitpid(pid, &status, 0); |
| 206 // Kill the original process without atexit handlers. | 211 // Kill the original process without atexit handlers. |
| 207 DLOG(INFO) << "original process death:" << pid; | 212 DLOG(INFO) << "jailed process death:" << pid; |
| 208 _exit(0); | 213 if (WIFEXITED(status)) { |
| 214 _exit(WEXITSTATUS(status)); |
| 215 } |
| 216 if (WIFSIGNALED(status)) { |
| 217 _exit(WTERMSIG(status)); |
| 218 } |
| 219 DLOG(INFO) << "unknown terminal condition for child"; |
| 220 _exit(1); |
| 209 } | 221 } |
| 210 DLOG(INFO) << "Success: " << getpid(); | 222 DLOG(INFO) << "Success: " << getpid(); |
| 211 return true; | 223 return true; |
| 212 } | 224 } |
| 213 | 225 |
| 214 bool Env::Mount() const { | 226 bool Env::Mount() const { |
| 215 DLOG(INFO) << "Attempting to mount /proc RO."; | 227 DLOG(INFO) << "Attempting to mount /proc RO."; |
| 216 if (mount("proc", | 228 if (mount("proc", |
| 217 "/proc", | 229 "/proc", |
| 218 "proc", | 230 "proc", |
| (...skipping 11 matching lines...) Expand all Loading... |
| 230 for (char * const* arg = argv; *arg; ++arg) { | 242 for (char * const* arg = argv; *arg; ++arg) { |
| 231 DLOG(INFO) << "-> " << *arg; | 243 DLOG(INFO) << "-> " << *arg; |
| 232 } | 244 } |
| 233 execve(path, argv, envp); | 245 execve(path, argv, envp); |
| 234 PLOG(FATAL) << "failed to execute " << path; | 246 PLOG(FATAL) << "failed to execute " << path; |
| 235 return false; | 247 return false; |
| 236 } | 248 } |
| 237 | 249 |
| 238 } // namespace minijail | 250 } // namespace minijail |
| 239 } // namespace chromeos | 251 } // namespace chromeos |
| OLD | NEW |