proot/test/test-ptrace-exec-trap.sh
Yichao Yu d0a8b690b6
Fix event handling on newer kernels (#288)
The event handler for the old kernel may still be called on new kernels.
This causes issues since the two event handlers maintains their own global states
unaware of each other.

In particular, execve+ptrace handling from the loader of the tracee
will issue an `execve(0x1, ...)` to signal proot of the start addresses.
This triggers a `SIGTRAP` to the tracee for the tracer to handle.
However, the event handler expect one initial `SIGTRAP` to have special meaning
and if the wrong event handler is called, it will incorrectly assume this `SIGTRAP`
is the special one and acts incorrectly. (In this case, causing the signaling `execve`
to run again and set the addresses incorrectly.)
2021-10-02 14:51:06 -04:00

26 lines
742 B
Bash

if [ -z `which mcookie` ] || [ -z `which cmp` ] || [ -z `which rm` ] || [ ! -x ${ROOTFS}/bin/ptrace-3 ] || [ ! -x ${ROOTFS}/bin/true ]; then
exit 125;
fi
TMP1=/tmp/$(mcookie)
TMP2=/tmp/$(mcookie)
${ROOTFS}/bin/ptrace-3 ${ROOTFS}/bin/true 2>&1 >${TMP1}
${PROOT} ${ROOTFS}/bin/ptrace-3 ${ROOTFS}/bin/true 2>&1 >${TMP2}
cmp ${TMP1} ${TMP2}
PTRACER_BEHAVIOR_1=1 ${ROOTFS}/bin/ptrace-3 ${ROOTFS}/bin/true 2>&1 >${TMP1}
PTRACER_BEHAVIOR_1=1 ${PROOT} ${ROOTFS}/bin/ptrace-3 ${ROOTFS}/bin/true 2>&1 >${TMP2}
cmp ${TMP1} ${TMP2}
PTRACER_BEHAVIOR_2=1 ${ROOTFS}/bin/ptrace-3 ${ROOTFS}/bin/true 2>&1 >${TMP1}
PTRACER_BEHAVIOR_2=1 ${PROOT} ${ROOTFS}/bin/ptrace-3 ${ROOTFS}/bin/true 2>&1 >${TMP2}
cmp ${TMP1} ${TMP2}
rm -f ${TMP1} ${TMP2}