OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <dlfcn.h> | 5 #include <dlfcn.h> |
6 #include <fcntl.h> | 6 #include <fcntl.h> |
7 #include <pthread.h> | 7 #include <pthread.h> |
8 #include <stdio.h> | 8 #include <stdio.h> |
9 #include <sys/socket.h> | 9 #include <sys/socket.h> |
10 #include <sys/stat.h> | 10 #include <sys/stat.h> |
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
522 static bool EnterSandbox(bool* using_suid_sandbox, bool* has_started_new_init) { | 522 static bool EnterSandbox(bool* using_suid_sandbox, bool* has_started_new_init) { |
523 *using_suid_sandbox = false; | 523 *using_suid_sandbox = false; |
524 *has_started_new_init = false; | 524 *has_started_new_init = false; |
525 | 525 |
526 PreSandboxInit(); | 526 PreSandboxInit(); |
527 SkiaFontConfigSetImplementation( | 527 SkiaFontConfigSetImplementation( |
528 new FontConfigIPC(Zygote::kMagicSandboxIPCDescriptor)); | 528 new FontConfigIPC(Zygote::kMagicSandboxIPCDescriptor)); |
529 | 529 |
530 const char* const sandbox_fd_string = getenv(kSUIDSandboxVar); | 530 const char* const sandbox_fd_string = getenv(kSUIDSandboxVar); |
531 if (sandbox_fd_string) { | 531 if (sandbox_fd_string) { |
532 char* endptr; | |
532 // Use the SUID sandbox. This still allows the seccomp sandbox to | 533 // Use the SUID sandbox. This still allows the seccomp sandbox to |
533 // be enabled by the process later. | 534 // be enabled by the process later. |
534 *using_suid_sandbox = true; | 535 *using_suid_sandbox = true; |
535 | 536 |
536 char* endptr; | 537 // Check if the SUID sandbox provides the correct API version. |
Brad Chen
2012/06/02 15:57:03
Are you adding these checks only for sandbox use i
jln (very slow on Chromium)
2012/06/04 19:26:23
Ohh yes, both. Well, in official builds it's unlik
| |
538 const char* const sandbox_api_string = | |
539 getenv(base::kSandboxEnvironmentApiProvides); | |
540 // Assume API version 0 if no environment was found | |
541 long sandbox_api_num = 0; | |
542 if (sandbox_api_string) { | |
543 errno = 0; | |
544 sandbox_api_num = strtol(sandbox_api_string, &endptr, 10); | |
545 if (errno || *endptr) { | |
546 return false; | |
547 } | |
548 } | |
549 | |
550 if (sandbox_api_num != base::kSUIDSandboxApiNumber) { | |
551 LOG(WARNING) << "You are using a wrong version of the setuid binary!\n" | |
552 "Please read " | |
553 "https://code.google.com/p/chromium/wiki/LinuxSUIDSandboxDevelopment." | |
Brad Chen
2012/06/02 15:57:03
Should this doc be updated to document the version
jln (very slow on Chromium)
2012/06/04 19:26:23
Yes, good point. I'll do it when this lands.
| |
554 "\n\n"; | |
555 } | |
556 | |
557 // Get the file descriptor to signal the chroot helper. | |
558 errno = 0; | |
537 const long fd_long = strtol(sandbox_fd_string, &endptr, 10); | 559 const long fd_long = strtol(sandbox_fd_string, &endptr, 10); |
538 if (!*sandbox_fd_string || *endptr || fd_long < 0 || fd_long > INT_MAX) | 560 if (errno || !*sandbox_fd_string || *endptr || fd_long < 0 || |
561 fd_long > INT_MAX) { | |
539 return false; | 562 return false; |
563 } | |
540 const int fd = fd_long; | 564 const int fd = fd_long; |
541 | 565 |
542 static const char kMsgChrootMe = 'C'; | 566 static const char kMsgChrootMe = 'C'; |
543 static const char kMsgChrootSuccessful = 'O'; | 567 static const char kMsgChrootSuccessful = 'O'; |
544 | 568 |
545 if (HANDLE_EINTR(write(fd, &kMsgChrootMe, 1)) != 1) { | 569 if (HANDLE_EINTR(write(fd, &kMsgChrootMe, 1)) != 1) { |
546 LOG(ERROR) << "Failed to write to chroot pipe: " << errno; | 570 LOG(ERROR) << "Failed to write to chroot pipe: " << errno; |
547 return false; | 571 return false; |
548 } | 572 } |
549 | 573 |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
690 } | 714 } |
691 } | 715 } |
692 #endif // SECCOMP_SANDBOX | 716 #endif // SECCOMP_SANDBOX |
693 | 717 |
694 Zygote zygote(sandbox_flags, forkdelegate, proc_fd_for_seccomp); | 718 Zygote zygote(sandbox_flags, forkdelegate, proc_fd_for_seccomp); |
695 // This function call can return multiple times, once per fork(). | 719 // This function call can return multiple times, once per fork(). |
696 return zygote.ProcessRequests(); | 720 return zygote.ProcessRequests(); |
697 } | 721 } |
698 | 722 |
699 } // namespace content | 723 } // namespace content |
OLD | NEW |