[OpenWrt-Devel] [PATCH procd 1/2] trace: Use properly sized type for PTRACE_GETEVENTMSG

Michal Sojka sojkam1 at fel.cvut.cz
Mon Jul 30 03:32:18 EDT 2018


From: Michal Sojka <michal.sojka at cvut.cz>

Without this, on 64-bit systems, ptrace call corrupts memory because
it stores 64bit value to 32bit pid_t variable.

Signed-off-by: Michal Sojka <michal.sojka at cvut.cz>
---
 trace/trace.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/trace/trace.c b/trace/trace.c
index 27cf108..665c22e 100644
--- a/trace/trace.c
+++ b/trace/trace.c
@@ -211,7 +211,9 @@ static void tracer_cb(struct uloop_process *c, int ret)
 			   (ret >> 8) == (SIGTRAP | (PTRACE_EVENT_CLONE << 8))) {
 			struct tracee *child = calloc(1, sizeof(struct tracee));
 
-			ptrace(PTRACE_GETEVENTMSG, c->pid, 0, &child->proc.pid);
+			unsigned long msg;
+			ptrace(PTRACE_GETEVENTMSG, c->pid, 0, &msg);
+			child->proc.pid = msg;
 			child->proc.cb = tracer_cb;
 			ptrace(ptrace_restart, child->proc.pid, 0, 0);
 			uloop_process_add(&child->proc);
-- 
2.18.0


_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list