Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling of the program base address in Linux #2500

Merged
merged 3 commits into from
Nov 18, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions manticore/platforms/linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,9 @@ def __init__(
self.envp = envp
self.argv = argv
self.stubs = SyscallStubs(parent=self)
# Load addresses
self.interp_base: Optional[int] = None
self.program_base: Optional[int] = None

# dict of [int -> (int, int)] where tuple is (soft, hard) limits
self._rlimits = {
Expand Down Expand Up @@ -1028,7 +1031,8 @@ def __getstate__(self):
state["syscall_trace"] = self.syscall_trace
state["argv"] = self.argv
state["envp"] = self.envp
state["base"] = self.base
state["interp_base"] = self.interp_base
state["program_base"] = self.program_base
state["elf_bss"] = self.elf_bss
state["end_code"] = self.end_code
state["end_data"] = self.end_data
Expand Down Expand Up @@ -1090,7 +1094,8 @@ def __setstate__(self, state: Dict) -> None:
self.syscall_trace = state["syscall_trace"]
self.argv = state["argv"]
self.envp = state["envp"]
self.base = state["base"]
self.interp_base = state["interp_base"]
self.program_base = state["program_base"]
self.elf_bss = state["elf_bss"]
self.end_code = state["end_code"]
self.end_data = state["end_data"]
Expand Down Expand Up @@ -1546,7 +1551,8 @@ def _clean_interp_stream() -> None:
logger.debug(f"Mappings:")
for m in str(cpu.memory).split("\n"):
logger.debug(f" {m}")
self.base = base
self.interp_base = base
self.program_base = self.load_addr
self.elf_bss = elf_bss
self.end_code = end_code
self.end_data = end_data
Expand Down Expand Up @@ -2852,7 +2858,7 @@ def wait(self, readfds, writefds, timeout) -> None:
self.check_timers()

def awake(self, procid) -> None:
""" Remove procid from waitlists and reestablish it in the running list """
"""Remove procid from waitlists and reestablish it in the running list"""
logger.debug(
f"Remove procid:{procid} from waitlists and reestablish it in the running list"
)
Expand All @@ -2877,7 +2883,7 @@ def connections(self, fd: int) -> Optional[int]:
return fd - 1

def signal_receive(self, fd: int) -> None:
""" Awake one process waiting to receive data on fd """
"""Awake one process waiting to receive data on fd"""
connections = self.connections
connection = connections(fd)
if connection:
Expand All @@ -2887,7 +2893,7 @@ def signal_receive(self, fd: int) -> None:
self.awake(procid)

def signal_transmit(self, fd: int) -> None:
""" Awake one process waiting to transmit data on fd """
"""Awake one process waiting to transmit data on fd"""
connection = self.connections(fd)
if connection is None or not self.fd_table.has_entry(connection):
return
Expand All @@ -2898,7 +2904,7 @@ def signal_transmit(self, fd: int) -> None:
self.awake(procid)

def check_timers(self) -> None:
""" Awake process if timer has expired """
"""Awake process if timer has expired"""
if self._current is None:
# Advance the clocks. Go to future!!
advance = min([self.clocks] + [x for x in self.timers if x is not None]) + 1
Expand Down