Closed lopsided98 closed 5 years ago
Are you planning to release a new version sometime? Having a tagged release would be helpful in getting new changes to be accepted downstream by Linux distributions.
Yeah, I'm happy to tag a new release. I'll do so sometime this week.
@lopsided98 I tagged 0.7.0!
Thanks!
This PR adds support for Linux on aarch64, which requires a number of changes besides the arch specific header.
Being a more recently architecture, Linux on aarch64 does not implement older syscalls such as
open
,fork
anddup2
. I added compatibility wrappers that emulatefork
usingclone
anddup2
usingdup3
. I replacedopen
withopenat
, which I believe is available on all supported systems.aarch64 also does not support certain ptrace requests, such as
PTRACE_GETREGS
,PTRACE_SETREGS
,PTRACE_PEEKUSER
andPTRACE_POKEUSER
. Instead,PTRACE_GETREGSET
andPTRACE_SETREGSET
must be used for all register manipulations. I believe these are available on all supported systems, so we shouldn't need special cases for aarch64.I also switched from using the
user
struct to usinguser_regs_struct
/user_regs
/pt_regs
depending on the architecture. aarch64 does not have auser
struct, and I felt that it would be more clear and consistent to use just the register struct on all arches. AFAIK, ptrace only fills the register part of theuser
struct anyway.I have tested these changes under Linux on x86_64, armv6l, armv7l, aarch64, and powerpc.
I attempted to test on FreeBSD 11.2, but running reptyr (even without this PR) results in a kernel panic. Besides whatever is wrong with reptyr, an unprivileged user being able to cause a panic seems like a fairly serious FreeBSD bug.
Panic backtrace
``` Fatal trap 12: page fault while in kernel mode cpuid = 0; apic id = 00 fault virtual address = 0x2b0 fault code = supervisor write data, page not present instruction pointer = 0x20:0xffffffff80b60eea stack pointer = 0x28:0xfffffe007af43760 frame pointer = 0x28:0xfffffe007af43880 code segment = base 0x0, limit 0xfffff, type 0x1b = DPL 0, pres 1, long 1, def32 0, gran 1 processor eflags = interrupt enabled, resume, IOPL = 0 current process = 747 (reptyr) trap number = 12 panic: page fault cpuid = 0 KDB: stack backtrace: #0 0xffffffff80b3d567 at kdb_backtrace+0x67 #1 0xffffffff80af6b07 at vpanic+0x177 #2 0xffffffff80af6983 at panic+0x43 #3 0xffffffff80f77faf at trap_fatal+0x35f #4 0xffffffff80f78009 at trap_pfault+0x49 #5 0xffffffff80f777d7 at trap+0x2c7 #6 0xffffffff80f5769c at calltrap+0x8 #7 0xffffffff80b5fa3d at sys_ptrace+0x18d #8 0xffffffff80f79038 at amd64_syscall+0xa38 #9 0xffffffff80f57eed at fast_syscall_common+0x101 ```