| 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 "sandbox/linux/seccomp-bpf/die.h" | 5 #include "sandbox/linux/seccomp-bpf/die.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <signal.h> | 8 #include <signal.h> |
| 9 #include <stdio.h> | 9 #include <stdio.h> |
| 10 #include <sys/prctl.h> | 10 #include <sys/prctl.h> |
| 11 #include <sys/syscall.h> | 11 #include <sys/syscall.h> |
| 12 #include <unistd.h> | 12 #include <unistd.h> |
| 13 | 13 |
| 14 #include <string> | 14 #include <string> |
| 15 | 15 |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/posix/eintr_wrapper.h" | 17 #include "base/posix/eintr_wrapper.h" |
| 18 #include "sandbox/linux/seccomp-bpf/syscall.h" | 18 #include "sandbox/linux/seccomp-bpf/syscall.h" |
| 19 #include "sandbox/linux/services/syscall_wrappers.h" | |
| 20 #include "sandbox/linux/system_headers/linux_signal.h" | |
| 21 | 19 |
| 22 namespace sandbox { | 20 namespace sandbox { |
| 23 | 21 |
| 24 void Die::ExitGroup() { | 22 void Die::ExitGroup() { |
| 25 // exit_group() should exit our program. After all, it is defined as a | 23 // exit_group() should exit our program. After all, it is defined as a |
| 26 // function that doesn't return. But things can theoretically go wrong. | 24 // function that doesn't return. But things can theoretically go wrong. |
| 27 // Especially, since we are dealing with system call filters. Continuing | 25 // Especially, since we are dealing with system call filters. Continuing |
| 28 // execution would be very bad in most cases where ExitGroup() gets called. | 26 // execution would be very bad in most cases where ExitGroup() gets called. |
| 29 // So, we'll try a few other strategies too. | 27 // So, we'll try a few other strategies too. |
| 30 Syscall::Call(__NR_exit_group, 1); | 28 Syscall::Call(__NR_exit_group, 1); |
| 31 | 29 |
| 32 // We have no idea what our run-time environment looks like. So, signal | 30 // We have no idea what our run-time environment looks like. So, signal |
| 33 // handlers might or might not do the right thing. Try to reset settings | 31 // handlers might or might not do the right thing. Try to reset settings |
| 34 // to a defined state; but we have not way to verify whether we actually | 32 // to a defined state; but we have not way to verify whether we actually |
| 35 // succeeded in doing so. Nonetheless, triggering a fatal signal could help | 33 // succeeded in doing so. Nonetheless, triggering a fatal signal could help |
| 36 // us terminate. | 34 // us terminate. |
| 37 struct sigaction sa = {}; | 35 signal(SIGSEGV, SIG_DFL); |
| 38 sa.sa_handler = LINUX_SIG_DFL; | |
| 39 sa.sa_flags = LINUX_SA_RESTART; | |
| 40 sys_sigaction(LINUX_SIGSEGV, &sa, nullptr); | |
| 41 Syscall::Call(__NR_prctl, PR_SET_DUMPABLE, (void*)0, (void*)0, (void*)0); | 36 Syscall::Call(__NR_prctl, PR_SET_DUMPABLE, (void*)0, (void*)0, (void*)0); |
| 42 if (*(volatile char*)0) { | 37 if (*(volatile char*)0) { |
| 43 } | 38 } |
| 44 | 39 |
| 45 // If there is no way for us to ask for the program to exit, the next | 40 // If there is no way for us to ask for the program to exit, the next |
| 46 // best thing we can do is to loop indefinitely. Maybe, somebody will notice | 41 // best thing we can do is to loop indefinitely. Maybe, somebody will notice |
| 47 // and file a bug... | 42 // and file a bug... |
| 48 // We in fact retry the system call inside of our loop so that it will | 43 // We in fact retry the system call inside of our loop so that it will |
| 49 // stand out when somebody tries to diagnose the problem by using "strace". | 44 // stand out when somebody tries to diagnose the problem by using "strace". |
| 50 for (;;) { | 45 for (;;) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 // probably prefer them over a loop that blocks. | 79 // probably prefer them over a loop that blocks. |
| 85 ignore_result( | 80 ignore_result( |
| 86 HANDLE_EINTR(Syscall::Call(__NR_write, 2, s.c_str(), s.length()))); | 81 HANDLE_EINTR(Syscall::Call(__NR_write, 2, s.c_str(), s.length()))); |
| 87 } | 82 } |
| 88 } | 83 } |
| 89 | 84 |
| 90 bool Die::simple_exit_ = false; | 85 bool Die::simple_exit_ = false; |
| 91 bool Die::suppress_info_ = false; | 86 bool Die::suppress_info_ = false; |
| 92 | 87 |
| 93 } // namespace sandbox | 88 } // namespace sandbox |
| OLD | NEW |