Module Name: src Committed By: kamil Date: Wed May 1 17:02:40 UTC 2019
Modified Files: src/sys/kern: sys_ptrace_common.c Log Message: Disallow resuming program with PC=0x0 in ptrace(2) If the address parameter is 0, report error. It's a popular mistake to set Program Counter to 0x0. In certain kernels this is allowable parameter and causes portability issue. Disallow explicitly zeroed PC, instead of triggering a harder to debug crash later. To generate a diff of this commit: cvs rdiff -u -r1.50 -r1.51 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.50 src/sys/kern/sys_ptrace_common.c:1.51 --- src/sys/kern/sys_ptrace_common.c:1.50 Tue Apr 30 22:32:01 2019 +++ src/sys/kern/sys_ptrace_common.c Wed May 1 17:02:40 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: sys_ptrace_common.c,v 1.50 2019/04/30 22:32:01 kamil Exp $ */ +/* $NetBSD: sys_ptrace_common.c,v 1.51 2019/05/01 17:02:40 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.50 2019/04/30 22:32:01 kamil Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sys_ptrace_common.c,v 1.51 2019/05/01 17:02:40 kamil Exp $"); #ifdef _KERNEL_OPT #include "opt_ptrace.h" @@ -1246,6 +1246,21 @@ do_ptrace(struct ptrace_methods *ptm, st } } + /* + * If the address parameter is 0, report error. + * + * It's a popular mistake to set Program Counter to 0x0. + * In certain kernels this is allowable parameter and causes + * portability issue. + * + * Disallow explicitly zeroed PC, instead of triggering + * a harder to debug crash later. + */ + if (addr == 0) { + error = EINVAL; + break; + } + /* If the address parameter is not (int *)1, set the pc. */ if ((int *)addr != (int *)1) { error = process_set_pc(lt, addr);