Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/kern Add additional hardening in PT_TRACE_M...
details: https://anonhg.NetBSD.org/src/rev/288c727d69fa
branches: trunk
changeset: 318617:288c727d69fa
user: kamil <kamil%NetBSD.org@localhost>
date: Tue May 01 14:09:53 2018 +0000
description:
Add additional hardening in PT_TRACE_ME and PT_ATTACH
Prohibit:
- calling PT_TRACE_ME by initproc (PID1),
- calling PT_ATTACH by initproc (PID1).
PID1 and its parent cannot become a tracer.
Sponsored by <The NetBSD Foundation>
diffstat:
sys/kern/sys_ptrace_common.c | 24 ++++++++++++++++++------
1 files changed, 18 insertions(+), 6 deletions(-)
diffs (62 lines):
diff -r 762fd6d0ec5c -r 288c727d69fa sys/kern/sys_ptrace_common.c
--- a/sys/kern/sys_ptrace_common.c Tue May 01 13:48:38 2018 +0000
+++ b/sys/kern/sys_ptrace_common.c Tue May 01 14:09:53 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sys_ptrace_common.c,v 1.38 2018/04/29 04:28:09 kamil Exp $ */
+/* $NetBSD: sys_ptrace_common.c,v 1.39 2018/05/01 14:09:53 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.38 2018/04/29 04:28:09 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_ptrace_common.c,v 1.39 2018/05/01 14:09:53 kamil Exp $");
#ifdef _KERNEL_OPT
#include "opt_ptrace.h"
@@ -385,7 +385,13 @@
return EPERM;
/*
- * (2) the child is already traced.
+ * (2) the process is initproc, or
+ */
+ if (p == initproc)
+ return EPERM;
+
+ /*
+ * (3) the child is already traced.
*/
if (ISSET(p->p_slflag, PSL_TRACED))
return EBUSY;
@@ -401,19 +407,25 @@
return EINVAL;
/*
- * (2) it's a system process
+ * (2) it's a system process,
*/
if (t->p_flag & PK_SYSTEM)
return EPERM;
/*
- * (3) it's already being traced, or
+ * (3) the tracer is initproc,
+ */
+ if (p == initproc)
+ return EPERM;
+
+ /*
+ * (4) it's already being traced, or
*/
if (ISSET(t->p_slflag, PSL_TRACED))
return EBUSY;
/*
- * (4) the tracer is chrooted, and its root directory is
+ * (5) the tracer is chrooted, and its root directory is
* not at or above the root directory of the tracee
*/
mutex_exit(t->p_lock); /* XXXSMP */
Home |
Main Index |
Thread Index |
Old Index