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

Side by Side Diff: src/processor/exploitability_linux.h

Issue 1233973002: Add ELF header analysis when checking for instruction pointer in code. (Closed) Base URL: http://google-breakpad.googlecode.com/svn/trunk/
Patch Set: Created 5 years, 5 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
« no previous file with comments | « no previous file | src/processor/exploitability_linux.cc » ('j') | 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) 2013 Google Inc. 1 // Copyright (c) 2013 Google Inc.
2 // All rights reserved. 2 // All rights reserved.
3 // 3 //
4 // Redistribution and use in source and binary forms, with or without 4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are 5 // modification, are permitted provided that the following conditions are
6 // met: 6 // met:
7 // 7 //
8 // * Redistributions of source code must retain the above copyright 8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer. 9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above 10 // * Redistributions in binary form must reproduce the above
(...skipping 19 matching lines...) Expand all
30 // exploitability_linux.h: Linux specific exploitability engine. 30 // exploitability_linux.h: Linux specific exploitability engine.
31 // 31 //
32 // Provides a guess at the exploitability of the crash for the Linux 32 // Provides a guess at the exploitability of the crash for the Linux
33 // platform given a minidump and process_state. 33 // platform given a minidump and process_state.
34 // 34 //
35 // Author: Matthew Riley 35 // Author: Matthew Riley
36 36
37 #ifndef GOOGLE_BREAKPAD_PROCESSOR_EXPLOITABILITY_LINUX_H_ 37 #ifndef GOOGLE_BREAKPAD_PROCESSOR_EXPLOITABILITY_LINUX_H_
38 #define GOOGLE_BREAKPAD_PROCESSOR_EXPLOITABILITY_LINUX_H_ 38 #define GOOGLE_BREAKPAD_PROCESSOR_EXPLOITABILITY_LINUX_H_
39 39
40 #include <elf.h>
41 #include <string.h>
42
43 #include "common/scoped_ptr.h"
40 #include "google_breakpad/common/breakpad_types.h" 44 #include "google_breakpad/common/breakpad_types.h"
41 #include "google_breakpad/processor/exploitability.h" 45 #include "google_breakpad/processor/exploitability.h"
42 46
43 namespace google_breakpad { 47 namespace google_breakpad {
44 48
49 enum LinuxArchitectureType {
50 // A 32-bit Linux architecture.
51 LINUX_32_BIT,
52
53 // A 64-bit Linux architecture.
54 LINUX_64_BIT,
55
56 // Some other architecture that is not Linux.
57 UNSUPPORTED_ARCHITECTURE
58 };
59
45 class ExploitabilityLinux : public Exploitability { 60 class ExploitabilityLinux : public Exploitability {
46 public: 61 public:
47 ExploitabilityLinux(Minidump *dump, 62 ExploitabilityLinux(Minidump *dump,
48 ProcessState *process_state); 63 ProcessState *process_state);
49 64
50 virtual ExploitabilityRating CheckPlatformExploitability(); 65 virtual ExploitabilityRating CheckPlatformExploitability();
51 66
52 private: 67 private:
53 // This method takes the address of the instruction pointer and returns 68 // This method takes the address of the instruction pointer and returns
54 // whether the instruction pointer lies in a valid instruction region. 69 // whether the instruction pointer lies in a valid instruction region.
55 bool InstructionPointerInCode(uint64_t instruction_ptr); 70 bool InstructionPointerInCode(uint64_t instruction_ptr);
56 71
57 // This method checks the exception that triggered the creation of the 72 // This method checks the exception that triggered the creation of the
58 // minidump and reports whether the exception suggests no exploitability. 73 // minidump and reports whether the exception suggests no exploitability.
59 bool BenignCrashTrigger(const MDRawExceptionStream *raw_exception_stream); 74 bool BenignCrashTrigger(const MDRawExceptionStream *raw_exception_stream);
75
76 // Checks if the minidump architecture is 32-bit or 64-bit.
77 LinuxArchitectureType ArchitectureType();
78
79 // Loads ELF header data of the module present in the given memory
80 // region into the scoped pointer.
81 // This method takes a scoped pointer in which the ELF header data is
82 // loaded, the memory region containing the ELF header, and the base
83 // address of the ELF header.
84 template<typename T>
85 void LoadElfHeader(MinidumpMemoryRegion *memory,
86 uint64_t base_address,
87 T *header) {
88 for (size_t i = 0; i < sizeof(T); i++) {
89 uint8_t my_byte = 0;
90 memory->GetMemoryAtAddress(base_address + i, &my_byte);
91 memcpy(reinterpret_cast<char *>(header) + i,
ivanpe 2015/07/16 17:20:57 You are copying a single byte here. Why not just
liuandrew 2015/07/16 17:35:08 Done.
92 &my_byte,
93 sizeof(uint8_t));
94 }
95 }
96
97 // Loads the Program Header Table of the module present in the given
98 // memory region into the scoped array.
99 // This method takes a scoped array in which the header table data is
100 // loaded, the memory region containing the table, the base address of
101 // the program header table, and the number of entries in the table.
102 template<typename T>
103 void LoadElfHeaderTable(MinidumpMemoryRegion *memory,
104 uint64_t base_address,
105 uint16_t e_phnum,
106 T table[]) {
107 uint64_t offset = 0;
108 for (size_t i = 0; i < e_phnum; i++) {
109 T *entry = &table[i];
110 for (size_t j = 0; j < sizeof(T); j++) {
111 uint8_t my_byte = 0;
112 memory->GetMemoryAtAddress(base_address + offset++, &my_byte);
113 memcpy(reinterpret_cast<char *>(entry) + j,
ivanpe 2015/07/16 17:20:57 *(reinterpret_cast<uint8_t *>(entry) + j) = my_byt
liuandrew 2015/07/16 17:35:08 Done.
114 &my_byte,
115 sizeof(uint8_t));
116 }
117 }
118 }
60 }; 119 };
61 120
62 } // namespace google_breakpad 121 } // namespace google_breakpad
63 122
64 #endif // GOOGLE_BREAKPAD_PROCESSOR_EXPLOITABILITY_LINUX_H_ 123 #endif // GOOGLE_BREAKPAD_PROCESSOR_EXPLOITABILITY_LINUX_H_
OLDNEW
« no previous file with comments | « no previous file | src/processor/exploitability_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698