aboutsummaryrefslogtreecommitdiff
path: root/src/processor/exploitability_linux.h
blob: 2deb49918059911107e2e60d31ddc88b622ab2d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// Copyright (c) 2013 Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
//     * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
//     * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

// exploitability_linux.h: Linux specific exploitability engine.
//
// Provides a guess at the exploitability of the crash for the Linux
// platform given a minidump and process_state.
//
// Author: Matthew Riley

#ifndef GOOGLE_BREAKPAD_PROCESSOR_EXPLOITABILITY_LINUX_H_
#define GOOGLE_BREAKPAD_PROCESSOR_EXPLOITABILITY_LINUX_H_

#include "common/scoped_ptr.h"
#include "google_breakpad/common/breakpad_types.h"
#include "google_breakpad/processor/exploitability.h"

namespace google_breakpad {

enum LinuxArchitectureType {
  // A 32-bit Linux architecture.
  LINUX_32_BIT,

  // A 64-bit Linux architecture.
  LINUX_64_BIT,

  // Some other architecture that is not Linux.
  UNSUPPORTED_ARCHITECTURE
};

class ExploitabilityLinux : public Exploitability {
 public:
  ExploitabilityLinux(Minidump *dump,
                      ProcessState *process_state);

  virtual ExploitabilityRating CheckPlatformExploitability();

 private:
  // This method takes the address of the instruction pointer and returns
  // whether the instruction pointer lies in a valid instruction region.
  bool InstructionPointerInCode(uint64_t instruction_ptr);

  // This method checks the exception that triggered the creation of the
  // minidump and reports whether the exception suggests no exploitability.
  bool BenignCrashTrigger(const MDRawExceptionStream *raw_exception_stream);

  // Checks if the minidump architecture is 32-bit or 64-bit.
  LinuxArchitectureType ArchitectureType();

  // Loads ELF header data of the module present in the given memory
  // region into the scoped pointer.
  // This method takes a scoped pointer in which the ELF header data is
  // loaded, the memory region containing the ELF header, and the base
  // address of the ELF header.
  template<typename T>
  void LoadElfHeader(MinidumpMemoryRegion *memory,
                     uint64_t base_address,
                     T *header) {
    for (size_t i = 0; i < sizeof(T); i++) {
      uint8_t my_byte = 0;
      memory->GetMemoryAtAddress(base_address + i, &my_byte);
      *(reinterpret_cast<char *>(header) + i) = my_byte;
    }
  }

  // Loads the Program Header Table of the module present in the given
  // memory region into the scoped array.
  // This method takes a scoped array in which the header table data is
  // loaded, the memory region containing the table, the base address of
  // the program header table, and the number of entries in the table.
  template<typename T>
  void LoadElfHeaderTable(MinidumpMemoryRegion *memory,
                          uint64_t base_address,
                          uint16_t e_phnum,
                          T table[]) {
    uint64_t offset = 0;
    for (size_t i = 0; i < e_phnum; i++) {
      T *entry = &table[i];
      for (size_t j = 0; j < sizeof(T); j++) {
        uint8_t my_byte = 0;
        memory->GetMemoryAtAddress(base_address + offset++, &my_byte);
        *(reinterpret_cast<char *>(entry) + j) = my_byte;
      }
    }
  }
};

}  // namespace google_breakpad

#endif  // GOOGLE_BREAKPAD_PROCESSOR_EXPLOITABILITY_LINUX_H_