OLD | NEW |
---|---|
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 Loading... | |
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(scoped_ptr<T>& header, | |
ivanpe
2015/07/16 00:45:23
Please, move the out parameter to the end. Also t
liuandrew
2015/07/16 17:07:02
Done.
| |
86 MinidumpMemoryRegion *memory, | |
87 uint64_t base_address) { | |
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(((char *) header.get()) + i, &my_byte, sizeof(uint8_t)); | |
92 } | |
93 } | |
94 | |
95 // Loads the Program Header Table of the module present in the given | |
96 // memory region into the scoped array. | |
97 // This method takes a scoped array in which the header table data is | |
98 // loaded, the memory region containing the table, the base address of | |
99 // the program header table, and the number of entries in the table. | |
100 template<typename T> | |
101 void LoadElfHeaderTable(scoped_array<T>& table, | |
102 MinidumpMemoryRegion *memory, | |
103 uint64_t base_address, | |
104 uint16_t e_phnum) { | |
ivanpe
2015/07/16 00:45:23
Please, update the function signature as follows:
liuandrew
2015/07/16 17:07:02
Done.
| |
105 uint64_t offset = 0; | |
106 for (size_t i = 0; i < e_phnum; i++) { | |
107 for (size_t j = 0; j < sizeof(T); j++) { | |
108 uint8_t my_byte = 0; | |
109 memory->GetMemoryAtAddress(base_address + offset, &my_byte); | |
110 memcpy(((char *) table.get()) + offset, &my_byte, sizeof(uint8_t)); | |
111 offset++; | |
ivanpe
2015/07/16 00:45:23
This is a bit scary. I'm concerned about padding
liuandrew
2015/07/16 17:07:02
Done.
Good point. It never occurred to me since i
| |
112 } | |
113 } | |
114 } | |
115 | |
60 }; | 116 }; |
61 | 117 |
62 } // namespace google_breakpad | 118 } // namespace google_breakpad |
63 | 119 |
64 #endif // GOOGLE_BREAKPAD_PROCESSOR_EXPLOITABILITY_LINUX_H_ | 120 #endif // GOOGLE_BREAKPAD_PROCESSOR_EXPLOITABILITY_LINUX_H_ |
OLD | NEW |