| 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 "common/scoped_ptr.h" | |
| 41 #include "google_breakpad/common/breakpad_types.h" | 40 #include "google_breakpad/common/breakpad_types.h" |
| 42 #include "google_breakpad/processor/exploitability.h" | 41 #include "google_breakpad/processor/exploitability.h" |
| 43 | 42 |
| 44 namespace google_breakpad { | 43 namespace google_breakpad { |
| 45 | 44 |
| 46 class ExploitabilityLinux : public Exploitability { | 45 class ExploitabilityLinux : public Exploitability { |
| 47 public: | 46 public: |
| 48 ExploitabilityLinux(Minidump *dump, | 47 ExploitabilityLinux(Minidump *dump, |
| 49 ProcessState *process_state); | 48 ProcessState *process_state); |
| 50 | 49 |
| 50 // Parameters are the minidump to analyze, the object representing process |
| 51 // state, and whether to enable objdump disassembly. |
| 52 // Enabling objdump will allow exploitability analysis to call out to |
| 53 // objdump for diassembly. It is used to check the identity of the |
| 54 // instruction that caused the program to crash. If there are any |
| 55 // portability concerns, this should not be enabled. |
| 56 ExploitabilityLinux(Minidump *dump, |
| 57 ProcessState *process_state, |
| 58 bool enable_objdump); |
| 59 |
| 51 virtual ExploitabilityRating CheckPlatformExploitability(); | 60 virtual ExploitabilityRating CheckPlatformExploitability(); |
| 52 | 61 |
| 53 private: | 62 private: |
| 63 friend class ExploitabilityLinuxTest; |
| 64 |
| 54 // Takes the address of the instruction pointer and returns | 65 // Takes the address of the instruction pointer and returns |
| 55 // whether the instruction pointer lies in a valid instruction region. | 66 // whether the instruction pointer lies in a valid instruction region. |
| 56 bool InstructionPointerInCode(uint64_t instruction_ptr); | 67 bool InstructionPointerInCode(uint64_t instruction_ptr); |
| 57 | 68 |
| 58 // Checks the exception that triggered the creation of the | 69 // Checks the exception that triggered the creation of the |
| 59 // minidump and reports whether the exception suggests no exploitability. | 70 // minidump and reports whether the exception suggests no exploitability. |
| 60 bool BenignCrashTrigger(const MDRawExceptionStream *raw_exception_stream); | 71 bool BenignCrashTrigger(const MDRawExceptionStream *raw_exception_stream); |
| 61 | 72 |
| 73 // This method checks if the crash occurred during a write to read-only or |
| 74 // invalid memory. It does so by checking if the instruction at the |
| 75 // instruction pointer is a write instruction, and if the target of the |
| 76 // instruction is at a spot in memory that prohibits writes. |
| 77 bool EndedOnIllegalWrite(uint64_t instruction_ptr); |
| 78 |
| 79 #ifndef _WIN32 |
| 80 // Disassembles raw bytes via objdump and pipes the output into the provided |
| 81 // buffer, given the desired architecture, the file from which objdump will |
| 82 // read, and the buffer length. The method returns whether the disassembly |
| 83 // was a success, and the caller owns all pointers. |
| 84 static bool DisassembleBytes(const string &architecture, |
| 85 const uint8_t *raw_bytes, |
| 86 const unsigned int MAX_OBJDUMP_BUFFER_LEN, |
| 87 char *objdump_output_buffer); |
| 88 |
| 89 // Tokenizes out the operation and operands from a line of instruction |
| 90 // disassembled by objdump. This method modifies the pointers to match the |
| 91 // tokens of the instruction, and returns if the tokenizing was a success. |
| 92 // The caller owns all pointers. |
| 93 static bool TokenizeObjdumpInstruction(const string &line, |
| 94 string *operation, |
| 95 string *dest, |
| 96 string *src); |
| 97 |
| 98 // Calculates the effective address of an expression in the form reg+a or |
| 99 // reg-a, where 'reg' is a register and 'a' is a constant, and writes the |
| 100 // result in the pointer. The method returns whether the calculation was |
| 101 // a success. The caller owns the pointer. |
| 102 static bool CalculateAddress(const string &address_expression, |
| 103 const DumpContext &context, |
| 104 uint64_t *write_address); |
| 105 #endif // _WIN32 |
| 106 |
| 62 // Checks if the stack pointer points to a memory mapping that is not | 107 // Checks if the stack pointer points to a memory mapping that is not |
| 63 // labelled as the stack. | 108 // labelled as the stack. |
| 64 bool StackPointerOffStack(uint64_t stack_ptr); | 109 bool StackPointerOffStack(uint64_t stack_ptr); |
| 65 | 110 |
| 66 // Checks if the stack or heap are marked executable according | 111 // Checks if the stack or heap are marked executable according |
| 67 // to the memory mappings. | 112 // to the memory mappings. |
| 68 bool ExecutableStackOrHeap(); | 113 bool ExecutableStackOrHeap(); |
| 114 |
| 115 // Whether this exploitability engine is permitted to shell out to objdump |
| 116 // to disassemble raw bytes. |
| 117 bool enable_objdump_; |
| 69 }; | 118 }; |
| 70 | 119 |
| 71 } // namespace google_breakpad | 120 } // namespace google_breakpad |
| 72 | 121 |
| 73 #endif // GOOGLE_BREAKPAD_PROCESSOR_EXPLOITABILITY_LINUX_H_ | 122 #endif // GOOGLE_BREAKPAD_PROCESSOR_EXPLOITABILITY_LINUX_H_ |
| OLD | NEW |