Module Name:    src
Committed By:   kamil
Date:           Tue Apr 30 20:50:30 UTC 2019

Modified Files:
        src/sys/kern: sys_ptrace_common.c

Log Message:
Return EIO for empty memory transfer from ptrace(2)

Certain operations of PT_READ/PT_WRITE and PIOD_READ/PIOD_WRITE can result
in 0 byte transfer and the ptrace(2) call still returned success.

GDB had a special handling of this case for PT_IO checking piod_len != 0,
but in LLDB this corner case caused infinite loop and breakage. The LLDB
case has been enhanced.

Unfortunately the status of operation of PT_READ/PT_WRITE is not
distinguishable between successful operation and empty opeartion. This
renders this call into a questionable one.

Change the behavior and return error with EIO in scenarios of
truncated/empty byte transfers by PT_READ/PT_WRITE and empty byte transfers
from PT_IO.

No code changed is needed in GDB and LLDB.


To generate a diff of this commit:
cvs rdiff -u -r1.48 -r1.49 src/sys/kern/sys_ptrace_common.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/sys_ptrace_common.c
diff -u src/sys/kern/sys_ptrace_common.c:1.48 src/sys/kern/sys_ptrace_common.c:1.49
--- src/sys/kern/sys_ptrace_common.c:1.48	Fri Apr 26 08:38:25 2019
+++ src/sys/kern/sys_ptrace_common.c	Tue Apr 30 20:50:30 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: sys_ptrace_common.c,v 1.48 2019/04/26 08:38:25 pgoyette Exp $	*/
+/*	$NetBSD: sys_ptrace_common.c,v 1.49 2019/04/30 20:50:30 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -118,7 +118,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_ptrace_common.c,v 1.48 2019/04/26 08:38:25 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_ptrace_common.c,v 1.49 2019/04/30 20:50:30 kamil Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ptrace.h"
@@ -1106,6 +1106,10 @@ do_ptrace(struct ptrace_methods *ptm, st
 		piod.piod_op = write ? PIOD_WRITE_D : PIOD_READ_D;
 		if ((error = ptrace_doio(l, t, lt, &piod, addr, true)) != 0)
 			break;
+		if (piod.piod_len < sizeof(tmp)) {
+			error = EIO;
+			break;
+		}
 		if (!write)
 			*retval = tmp;
 		break;
@@ -1115,6 +1119,10 @@ do_ptrace(struct ptrace_methods *ptm, st
 			break;
 		if ((error = ptrace_doio(l, t, lt, &piod, addr, false)) != 0)
 			break;
+		if (piod.piod_len < 1) {
+			error = EIO;
+			break;
+		}
 		error = ptm->ptm_copyout_piod(&piod, addr, data);
 		break;
 

Reply via email to