Skip to content

Commit 9fcb2ce

Browse files
retrocpugeekclaude
andcommitted
Handle MIPS Linux reserved-instruction exception
Same class of crash as the ARM/ARM64 fix: MIPS Linux only hooked the syscall exception, so any other CPU exception reached the unhandled-interrupt dispatcher and raised QlErrorCoreHook. In examples/shellcode_run.py the rootfs-less MIPS shellcode runs past its denied execve into the trailing "/bin/sh" string, which decodes as a reserved instruction (exception 20) -- delivered as SIGILL on a real kernel. Hook the reserved-instruction exception and route it through the existing hook_cpu_exception handler. Add a small EXCP enum to mips_const so the syscall and reserved-instruction codes are named rather than magic numbers. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 0626c1b commit 9fcb2ce

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

‎qiling/arch/mips_const.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,17 @@
33
# Cross Platform and Multi Architecture Advanced Binary Emulation Framework
44
#
55

6+
from enum import IntEnum
7+
68
from unicorn.mips_const import *
79

10+
11+
class EXCP(IntEnum):
12+
# subset of QEMU's MIPS exception codes, as reported to unicorn interrupt hooks
13+
SYSCALL = 17 # system call
14+
BREAK = 18 # breakpoint
15+
RI = 20 # reserved (illegal) instruction
16+
817
reg_map = {
918
"r0": UC_MIPS_REG_0,
1019
"r1": UC_MIPS_REG_1,

‎qiling/os/linux/linux.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from qiling.arch.x86_utils import GDTManager, SegmentManager86, SegmentManager64
1414
from qiling.arch import arm_utils
1515
from qiling.arch.cortex_m_const import EXCP
16+
from qiling.arch.mips_const import EXCP as MIPS_EXCP
1617
from qiling.cc import QlCC, intel, arm, mips, riscv, ppc
1718
from qiling.const import QL_ARCH, QL_OS
1819
from qiling.os.fcall import QlFunctionCall
@@ -68,7 +69,8 @@ def load(self):
6869

6970
# MIPS32
7071
elif self.ql.arch.type == QL_ARCH.MIPS:
71-
self.ql.hook_intno(self.hook_syscall, 17)
72+
self.ql.hook_intno(self.hook_syscall, MIPS_EXCP.SYSCALL)
73+
self.ql.hook_intno(self.hook_cpu_exception, MIPS_EXCP.RI)
7274
self.thread_class = thread.QlLinuxMIPS32Thread
7375

7476
# ARM64
@@ -149,7 +151,8 @@ def hook_cpu_exception(self, ql, intno = None):
149151
# terminal syscall (e.g. a denied execve) returns instead of replacing
150152
# the image.
151153
signame = {
152-
EXCP.UDEF: 'SIGILL',
154+
EXCP.UDEF: 'SIGILL', # ARM / ARM64 undefined instruction
155+
MIPS_EXCP.RI: 'SIGILL', # MIPS reserved (illegal) instruction
153156
}.get(intno, f'exception {intno:#x}')
154157

155158
pc = ql.arch.regs.arch_pc

0 commit comments

Comments
 (0)