Skip to content
Snippets Groups Projects
Commit 44655976 authored by Robert Morrison's avatar Robert Morrison
Browse files

lrdp-v2: Add KASLR support

Add '--kaslr-offset' option.  This specifies the offset for loading symbols
for a KASLR-enabled kernel.

Change-Id: I208d964ea3ca58536a0b80a32b4e334c73aae534
parent cf837b0c
No related branches found
No related tags found
No related merge requests found
......@@ -56,9 +56,10 @@ class GdbMI(object):
print('GDB Version: ' + g.version())
"""
def __init__(self, gdb_path, elf):
def __init__(self, gdb_path, elf, kaslr_offset=0):
self.gdb_path = gdb_path
self.elf = elf
self.kaslr_offset = kaslr_offset
self._cache = {}
self._gdbmi = None
......@@ -214,7 +215,7 @@ class GdbMI(object):
'0xc0b0006a'
"""
result = self._run_for_one('print /x &{0}'.format(symbol))
return int(result.split(' ')[-1], 16)
return int(result.split(' ')[-1], 16) + self.kaslr_offset
def get_symbol_info(self, address):
"""Returns a GdbSymbol representing the nearest symbol found at
......
......@@ -420,6 +420,7 @@ class RamDump():
def __init__(self, options, nm_path, gdb_path, objdump_path):
self.ebi_files = []
self.phys_offset = None
self.kaslr_offset = options.kaslr_offset
self.tz_start = 0
self.ebi_start = 0
self.cpu_type = None
......@@ -432,7 +433,8 @@ class RamDump():
self.objdump_path = objdump_path
self.outdir = options.outdir
self.imem_fname = None
self.gdbmi = gdbmi.GdbMI(self.gdb_path, self.vmlinux)
self.gdbmi = gdbmi.GdbMI(self.gdb_path, self.vmlinux,
self.kaslr_offset or 0)
self.gdbmi.open()
self.arm64 = options.arm64
self.page_offset = 0xc0000000
......@@ -447,6 +449,7 @@ class RamDump():
self.ipc_log_help = options.ipc_help
self.use_stdout = options.stdout
self.kernel_version = (0, 0, 0)
if options.ram_addr is not None:
# TODO sanity check to make sure the memory regions don't overlap
for file_path, start, end in options.ram_addr:
......@@ -815,8 +818,12 @@ class RamDump():
'PER.S.F C15:0x202 %L 0x80030000\n'.encode('ascii', 'ignore'))
startup_script.write('mmu.on\n'.encode('ascii', 'ignore'))
startup_script.write('mmu.scan\n'.encode('ascii', 'ignore'))
startup_script.write(
('data.load.elf ' + os.path.abspath(self.vmlinux) + ' /nocode\n').encode('ascii', 'ignore'))
where = os.path.abspath(self.vmlinux)
if self.kaslr_offset is not None:
where += ' 0x{0:x}'.format(self.kaslr_offset)
dloadelf = 'data.load.elf {} /nocode\n'.format(where)
startup_script.write(dloadelf.encode('ascii', 'ignore'))
if t32_host_system != 'Linux':
if self.arm64:
......@@ -990,10 +997,16 @@ class RamDump():
def setup_symbol_tables(self):
stream = os.popen(self.nm_path + ' -n ' + self.vmlinux)
symbols = stream.readlines()
kaslr = 0
if self.kaslr_offset is not None:
kaslr = int(self.kaslr_offset)
for line in symbols:
s = line.split(' ')
if len(s) == 3:
self.lookup_table.append((int(s[0], 16), s[2].rstrip()))
self.lookup_table.append((int(s[0], 16) + kaslr,
s[2].rstrip()))
stream.close()
def address_of(self, symbol):
......
......@@ -110,6 +110,9 @@ if __name__ == '__main__':
dest='stdout', help='Dump to stdout instead of the file')
parser.add_option('', '--phys-offset', type='int',
dest='phys_offset', help='use custom phys offset')
parser.add_option('', '--kaslr-offset', type='int',
dest='kaslr_offset',
help='Offset for address space layout randomization')
parser.add_option('', '--page-offset', type='int',
dest='page_offset', help='use custom page offset')
parser.add_option('', '--force-hardware', type='int',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment