Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern Return EIO for empty memory transfer from ptrace(2)



details:   https://anonhg.NetBSD.org/src/rev/c68cdf552dab
branches:  trunk
changeset: 450925:c68cdf552dab
user:      kamil <kamil%NetBSD.org@localhost>
date:      Tue Apr 30 20:50:30 2019 +0000

description:
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.

diffstat:

 sys/kern/sys_ptrace_common.c |  12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)

diffs (40 lines):

diff -r 8aa3af17ae87 -r c68cdf552dab sys/kern/sys_ptrace_common.c
--- a/sys/kern/sys_ptrace_common.c      Tue Apr 30 16:23:44 2019 +0000
+++ b/sys/kern/sys_ptrace_common.c      Tue Apr 30 20:50:30 2019 +0000
@@ -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 @@
                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 @@
                        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;
 



Home | Main Index | Thread Index | Old Index