exploitability_linux.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // Copyright (c) 2013 Google Inc.
  2. // All rights reserved.
  3. //
  4. // Redistribution and use in source and binary forms, with or without
  5. // modification, are permitted provided that the following conditions are
  6. // met:
  7. //
  8. // * Redistributions of source code must retain the above copyright
  9. // notice, this list of conditions and the following disclaimer.
  10. // * Redistributions in binary form must reproduce the above
  11. // copyright notice, this list of conditions and the following disclaimer
  12. // in the documentation and/or other materials provided with the
  13. // distribution.
  14. // * Neither the name of Google Inc. nor the names of its
  15. // contributors may be used to endorse or promote products derived from
  16. // this software without specific prior written permission.
  17. //
  18. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. // exploitability_linux.h: Linux specific exploitability engine.
  30. //
  31. // Provides a guess at the exploitability of the crash for the Linux
  32. // platform given a minidump and process_state.
  33. //
  34. // Author: Matthew Riley
  35. #ifndef GOOGLE_BREAKPAD_PROCESSOR_EXPLOITABILITY_LINUX_H_
  36. #define GOOGLE_BREAKPAD_PROCESSOR_EXPLOITABILITY_LINUX_H_
  37. #include "google_breakpad/common/breakpad_types.h"
  38. #include "google_breakpad/processor/exploitability.h"
  39. namespace google_breakpad {
  40. class ExploitabilityLinux : public Exploitability {
  41. public:
  42. ExploitabilityLinux(Minidump *dump,
  43. ProcessState *process_state);
  44. // Parameters are the minidump to analyze, the object representing process
  45. // state, and whether to enable objdump disassembly.
  46. // Enabling objdump will allow exploitability analysis to call out to
  47. // objdump for diassembly. It is used to check the identity of the
  48. // instruction that caused the program to crash. If there are any
  49. // portability concerns, this should not be enabled.
  50. ExploitabilityLinux(Minidump *dump,
  51. ProcessState *process_state,
  52. bool enable_objdump);
  53. virtual ExploitabilityRating CheckPlatformExploitability();
  54. private:
  55. friend class ExploitabilityLinuxTest;
  56. // Takes the address of the instruction pointer and returns
  57. // whether the instruction pointer lies in a valid instruction region.
  58. bool InstructionPointerInCode(uint64_t instruction_ptr);
  59. // Checks the exception that triggered the creation of the
  60. // minidump and reports whether the exception suggests no exploitability.
  61. bool BenignCrashTrigger(const MDRawExceptionStream *raw_exception_stream);
  62. // This method checks if the crash occurred during a write to read-only or
  63. // invalid memory. It does so by checking if the instruction at the
  64. // instruction pointer is a write instruction, and if the target of the
  65. // instruction is at a spot in memory that prohibits writes.
  66. bool EndedOnIllegalWrite(uint64_t instruction_ptr);
  67. #ifndef _WIN32
  68. // Disassembles raw bytes via objdump and pipes the output into the provided
  69. // buffer, given the desired architecture, the file from which objdump will
  70. // read, and the buffer length. The method returns whether the disassembly
  71. // was a success, and the caller owns all pointers.
  72. static bool DisassembleBytes(const string &architecture,
  73. const uint8_t *raw_bytes,
  74. const unsigned int MAX_OBJDUMP_BUFFER_LEN,
  75. char *objdump_output_buffer);
  76. // Parses the objdump output given in |objdump_output_buffer| and extracts
  77. // the line of the first instruction into |instruction_line|. Returns true
  78. // when the instruction line is successfully extracted.
  79. static bool GetObjdumpInstructionLine(
  80. const char *objdump_output_buffer,
  81. string *instruction_line);
  82. // Tokenizes out the operation and operands from a line of instruction
  83. // disassembled by objdump. This method modifies the pointers to match the
  84. // tokens of the instruction, and returns if the tokenizing was a success.
  85. // The caller owns all pointers.
  86. static bool TokenizeObjdumpInstruction(const string &line,
  87. string *operation,
  88. string *dest,
  89. string *src);
  90. // Calculates the effective address of an expression in the form reg+a or
  91. // reg-a, where 'reg' is a register and 'a' is a constant, and writes the
  92. // result in the pointer. The method returns whether the calculation was
  93. // a success. The caller owns the pointer.
  94. static bool CalculateAddress(const string &address_expression,
  95. const DumpContext &context,
  96. uint64_t *write_address);
  97. #endif // _WIN32
  98. // Checks if the stack pointer points to a memory mapping that is not
  99. // labelled as the stack.
  100. bool StackPointerOffStack(uint64_t stack_ptr);
  101. // Checks if the stack or heap are marked executable according
  102. // to the memory mappings.
  103. bool ExecutableStackOrHeap();
  104. // Whether this exploitability engine is permitted to shell out to objdump
  105. // to disassemble raw bytes.
  106. bool enable_objdump_;
  107. };
  108. } // namespace google_breakpad
  109. #endif // GOOGLE_BREAKPAD_PROCESSOR_EXPLOITABILITY_LINUX_H_