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

Side by Side Diff: base/debug/stack_trace_posix.cc

Issue 1267423002: CFI: Add diagnostic information to likely CFI violation stack traces. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/debug/stack_trace.h" 5 #include "base/debug/stack_trace.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <signal.h> 9 #include <signal.h>
10 #include <stdio.h> 10 #include <stdio.h>
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 PrintToStderr(" <unknown> "); 274 PrintToStderr(" <unknown> ");
275 } 275 }
276 if (signal == SIGBUS || signal == SIGFPE || 276 if (signal == SIGBUS || signal == SIGFPE ||
277 signal == SIGILL || signal == SIGSEGV) { 277 signal == SIGILL || signal == SIGSEGV) {
278 internal::itoa_r(reinterpret_cast<intptr_t>(info->si_addr), 278 internal::itoa_r(reinterpret_cast<intptr_t>(info->si_addr),
279 buf, sizeof(buf), 16, 12); 279 buf, sizeof(buf), 16, 12);
280 PrintToStderr(buf); 280 PrintToStderr(buf);
281 } 281 }
282 PrintToStderr("\n"); 282 PrintToStderr("\n");
283 283
284 #if defined(CFI_ENFORCEMENT)
285 if (signal == SIGILL && info->si_code == ILL_ILLOPN) {
286 PrintToStderr(
287 "CFI: Most likely a control flow integrity violation; for more "
288 "information see:\n");
289 PrintToStderr(
290 "https://sites.google.com/a/chromium.org/dev/developers/testing/"
291 "control-flow-integrity\n");
Avi (use Gerrit) 2015/08/05 15:19:35 FYI, rather than the sites page URL, use https://
pcc1 2015/08/05 19:58:15 Done.
292 }
293 #endif
294
284 debug::StackTrace().Print(); 295 debug::StackTrace().Print();
285 296
286 #if defined(OS_LINUX) 297 #if defined(OS_LINUX)
287 #if ARCH_CPU_X86_FAMILY 298 #if ARCH_CPU_X86_FAMILY
288 ucontext_t* context = reinterpret_cast<ucontext_t*>(void_context); 299 ucontext_t* context = reinterpret_cast<ucontext_t*>(void_context);
289 const struct { 300 const struct {
290 const char* label; 301 const char* label;
291 greg_t value; 302 greg_t value;
292 } registers[] = { 303 } registers[] = {
293 #if ARCH_CPU_32_BITS 304 #if ARCH_CPU_32_BITS
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 "ip: %x, cs: %x, ds: %x, es: %x, fs: %x, gs: %x\n", 399 "ip: %x, cs: %x, ds: %x, es: %x, fs: %x, gs: %x\n",
389 context->uc_mcontext->__ss.__eip, 400 context->uc_mcontext->__ss.__eip,
390 context->uc_mcontext->__ss.__cs, 401 context->uc_mcontext->__ss.__cs,
391 context->uc_mcontext->__ss.__ds, 402 context->uc_mcontext->__ss.__ds,
392 context->uc_mcontext->__ss.__es, 403 context->uc_mcontext->__ss.__es,
393 context->uc_mcontext->__ss.__fs, 404 context->uc_mcontext->__ss.__fs,
394 context->uc_mcontext->__ss.__gs)); 405 context->uc_mcontext->__ss.__gs));
395 write(STDERR_FILENO, buf, std::min(len, sizeof(buf) - 1)); 406 write(STDERR_FILENO, buf, std::min(len, sizeof(buf) - 1));
396 #endif // ARCH_CPU_32_BITS 407 #endif // ARCH_CPU_32_BITS
397 #endif // defined(OS_MACOSX) 408 #endif // defined(OS_MACOSX)
409
410 #if defined(CFI_ENFORCEMENT)
411 if (signal == SIGILL && info->si_code == ILL_ILLOPN) {
412 PrintToStderr("CFI: Aborting\n");
413 }
414 #endif
415
398 _exit(1); 416 _exit(1);
399 } 417 }
400 418
401 class PrintBacktraceOutputHandler : public BacktraceOutputHandler { 419 class PrintBacktraceOutputHandler : public BacktraceOutputHandler {
402 public: 420 public:
403 PrintBacktraceOutputHandler() {} 421 PrintBacktraceOutputHandler() {}
404 422
405 void HandleOutput(const char* output) override { 423 void HandleOutput(const char* output) override {
406 // NOTE: This code MUST be async-signal safe (it's used by in-process 424 // NOTE: This code MUST be async-signal safe (it's used by in-process
407 // stack dumping signal handler). NO malloc or stdio is allowed here. 425 // stack dumping signal handler). NO malloc or stdio is allowed here.
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 *ptr = *start; 843 *ptr = *start;
826 *start++ = ch; 844 *start++ = ch;
827 } 845 }
828 return buf; 846 return buf;
829 } 847 }
830 848
831 } // namespace internal 849 } // namespace internal
832 850
833 } // namespace debug 851 } // namespace debug
834 } // namespace base 852 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698