Source-Changes-HG archive

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

src: Pull up following revision(s) (requested by kamil in ticket...



details:   https://anonhg.NetBSD.org/src/rev/7d8adfa68e0b
branches:  netbsd-8
changeset: 318099:7d8adfa68e0b
user:      martin <martin%NetBSD.org@localhost>
date:      Thu Apr 12 13:42:48 2018 +0000
description:
Pull up following revision(s) (requested by kamil in ticket #713):

        sys/modules/procfs/Makefile: revision 1.4
        sys/miscfs/procfs/procfs_vfsops.c: revision 1.98
        bin/ps/ps.1: revision 1.108
        sys/compat/linux/arch/i386/linux_ptrace.c: revision 1.32
        sys/miscfs/procfs/procfs_vnops.c: revision 1.198
        sys/kern/sys_ptrace_common.c: revision 1.23
        sys/kern/sys_ptrace_common.c: revision 1.24
        sbin/mount_procfs/mount_procfs.8: revision 1.36
        sys/kern/sys_ptrace_common.c: revision 1.25
        sys/kern/sys_ptrace.c: revision 1.5
        sys/compat/linux/arch/powerpc/linux_ptrace.c: revision 1.30
        sys/sys/proc.h: revision 1.342
        sys/kern/sys_ptrace_common.c: revision 1.26
        sys/miscfs/procfs/procfs_ctl.c: file removal
        sys/kern/sys_ptrace_common.c: revision 1.27
        sys/miscfs/procfs/procfs_subr.c: revision 1.109
        sys/kern/sys_ptrace_common.c: revision 1.28
        sys/secmodel/extensions/secmodel_extensions.c: revision 1.8
        sys/kern/sys_ptrace_common.c: revision 1.29
        sys/sys/ptrace.h: revision 1.62
        sys/compat/netbsd32/netbsd32_signal.c: revision 1.45
        share/man/man9/kauth.9: revision 1.109
        sys/miscfs/procfs/files.procfs: revision 1.12
        sys/compat/netbsd32/netbsd32.h: revision 1.115
        sys/miscfs/procfs/procfs.h: revision 1.72
        sys/compat/netbsd32/netbsd32_ptrace.c: revision 1.5
        sys/kern/kern_sig.c: revision 1.337
        sys/sys/kauth.h: revision 1.75
        sys/sys/sysctl.h: revision 1.224
        sys/kern/sys_ptrace_common.c: revision 1.30
        sys/kern/sys_ptrace_common.c: revision 1.31
        sys/kern/sys_ptrace_common.c: revision 1.32
        sys/kern/sys_ptrace_common.c: revision 1.33
        sys/compat/linux/arch/arm/linux_ptrace.c: revision 1.20
        sys/kern/sys_ptrace_common.c: revision 1.34
        sys/kern/sys_ptrace_common.c: revision 1.36
        sys/kern/kern_proc.c: revision 1.207
        sys/kern/kern_exit.c: revision 1.269
        doc/TODO.ptrace: revision 1.29

Make {s,g}et{db,fp,}regs work again for PK_32 processes
XXX: pullup-8

add disgusting magic to handle compat_netbsd32 as a module.

use process_*reg32 instead of struct *reg32.

Remove the filesystem tracing feature

This is a legacy interface from 4.4BSD, and it was
introduced to overcome shortcomings of ptrace(2) at that time, which are
no longer relevant (performance). Today /proc/#/ctl offers a narrow
subset of ptrace(2) commands and is not applicable for modern
applications use beyond simplistic tracing scenarios.

This removal will simplify kernel internals. Users will still be able to
use all the other /proc files.

This change won't affect other procfs files neither Linux compat
features within mount_procfs(8). /proc/#/ctl isn't available on Linux.

Remove:
 - /proc/#/ctl from mount_procfs(8)
 - P_FSTRACE note from the documentation of ps(1)
 - /proc/#/ctl and filesystem tracing documentation from mount_procfs(8)
 - KAUTH_REQ_PROCESS_PROCFS_CTL documentation from kauth(9)
 - source code file miscfs/procfs/procfs_ctl.c
 - PFSctl and procfs_doctl() from sys/miscfs/procfs/procfs.h
 - KAUTH_REQ_PROCESS_PROCFS_CTL from sys/sys/kauth.h
 - PSL_FSTRACE (0x00010000) from sys/sys/proc.h
 - P_FSTRACE (0x00010000) from sys/sys/sysctl.h

Reduce code complexity after removal of this functionality.

Update TODO.ptrace accordingly: remove two entries about /proc tracing.

Do not keep legacy notes as comments in the headers about removed

PSL_FSTRACE / P_FSTRACE, as this interface had little number of users
(close or equal to zero).
Proposed on tech-kern@.

All filesystem tracing utility users are encouraged to switch to ptrace(2).

Sponsored by <The NetBSD Foundation>

untangle the mess:
- factor out common code
- break each ptrace subcall to its own sub-function
  .. more to come ...
- reduce ifdef ugliness by moving it up top.
- factor out PT_IO and make PT_{READ,WRITE}_{I,D} use it
- factor out PT_DUMPCORE
- factor out sendsig code
  .. more to come ...

handle siginfo requests for ptrace32

ptrace: Partially undo PT_{READ,WRITE}_{I,D} and unbreak these commands

The refactored code did not work and was generating EFAULT.

Sponsored by <The NetBSD Foundation>

Merge the code back; the problem was that since we are reading/writing
to a kernel address for PT_{READ,WRITE}_{I,D} we need the kernel vmspace.
provide separate read and write functions to accomodate register functions
that need a size argument.

don't ignore error from copyout_piod

Use the proper process (the tracee) to get information about lwps and
registers and the tracer for vmspace.

Add new sysctl(3) entry: security.models.extensions.user_set_dbregs

Model this new sysctl(3) entry after "user_set_cpu_affinity" in the same
level of sysctl(3) switches.

Allow to read unconditionally Debug Registers (no change here). This is
convenient as even if a user of a debugger does not use hardware assisted
watchpoints/breakpoints, a debugger can still prompt these values to store
in an internal cache with context of registers. Reading them should have
no security concerns.

Add a paranoid MI switch that prohibits by default setting these registers
by a regular user (non-superuser). Make this switch disabled by default.
There are enough reserved bits out there to allow using them
unconditionally on hardened hosts.

Features shipped with Debug Registers are optional features in debuggers.
There is no reduction in elementary functionality.

Reviewed by <christos>

Sponsored by <The NetBSD Foundation>

diffstat:

 bin/ps/ps.1                                  |     3 +-
 doc/TODO.ptrace                              |     7 +-
 sbin/mount_procfs/mount_procfs.8             |    53 +-
 share/man/man9/kauth.9                       |     3 +-
 sys/compat/linux/arch/arm/linux_ptrace.c     |     7 +-
 sys/compat/linux/arch/i386/linux_ptrace.c    |    13 +-
 sys/compat/linux/arch/powerpc/linux_ptrace.c |    13 +-
 sys/compat/netbsd32/netbsd32.h               |    11 +-
 sys/compat/netbsd32/netbsd32_ptrace.c        |    59 +-
 sys/compat/netbsd32/netbsd32_signal.c        |    47 +-
 sys/kern/kern_exit.c                         |    11 +-
 sys/kern/kern_proc.c                         |     5 +-
 sys/kern/kern_sig.c                          |     7 +-
 sys/kern/sys_ptrace.c                        |    47 +-
 sys/kern/sys_ptrace_common.c                 |  1543 +++++++++++++------------
 sys/miscfs/procfs/files.procfs               |     3 +-
 sys/miscfs/procfs/procfs.h                   |     6 +-
 sys/miscfs/procfs/procfs_ctl.c               |   412 ------
 sys/miscfs/procfs/procfs_subr.c              |     8 +-
 sys/miscfs/procfs/procfs_vfsops.c            |    11 +-
 sys/miscfs/procfs/procfs_vnops.c             |     7 +-
 sys/modules/procfs/Makefile                  |     4 +-
 sys/sys/kauth.h                              |     3 +-
 sys/sys/proc.h                               |     5 +-
 sys/sys/ptrace.h                             |     8 +-
 sys/sys/sysctl.h                             |     3 +-
 26 files changed, 967 insertions(+), 1332 deletions(-)

diffs (truncated from 3111 to 300 lines):

diff -r e54f5dc83980 -r 7d8adfa68e0b bin/ps/ps.1
--- a/bin/ps/ps.1       Thu Apr 12 13:08:16 2018 +0000
+++ b/bin/ps/ps.1       Thu Apr 12 13:42:48 2018 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: ps.1,v 1.106 2016/12/02 21:59:03 christos Exp $
+.\"    $NetBSD: ps.1,v 1.106.6.1 2018/04/12 13:42:48 martin Exp $
 .\"
 .\" Copyright (c) 1980, 1990, 1991, 1993, 1994
 .\"    The Regents of the University of California.  All rights reserved.
@@ -308,7 +308,6 @@
 .It Dv "P_EXEC" Ta No "0x00004000      process called" Xr execve 2
 .It Dv "P_OWEUPC" Ta No "0x00008000    owe process an addupc() call at next ast"
 .\" the routine addupc is not documented in the man pages
-.It Dv "P_FSTRACE" Ta No "0x00010000   tracing via file system"
 .It Dv "P_NOCLDWAIT" Ta No "0x00020000 no zombies when children die"
 .It Dv "P_32" Ta No "0x00040000        32-bit process (used on 64-bit kernels)"
 .It Dv "P_BIGLOCK" Ta No "0x00080000   process needs kernel ``big lock'' to run"
diff -r e54f5dc83980 -r 7d8adfa68e0b doc/TODO.ptrace
--- a/doc/TODO.ptrace   Thu Apr 12 13:08:16 2018 +0000
+++ b/doc/TODO.ptrace   Thu Apr 12 13:42:48 2018 +0000
@@ -1,4 +1,4 @@
-$NetBSD: TODO.ptrace,v 1.28 2017/04/08 01:08:36 kamil Exp $
+$NetBSD: TODO.ptrace,v 1.28.4.1 2018/04/12 13:42:49 martin Exp $
 
 Items we (currently) plan to finish in the ptrace(2) field:
 
@@ -8,11 +8,6 @@
  - reiterate over FreeBSD tests and add missing ones if applicable
  - add PT_DUMPCORE tests in the ATF framework
  - add ATF tests for PT_WRITE_I and PIOD_WRITE_I - test mprotect restrictions
- - add tests for the procfs interface covering all functions available on the
-   same level as ptrace(2)
- - remove 4.4BSD tracing with /proc, restrict /proc to Linux compat, to be
-   superseded with kevent tracing, the original purpose of /proc debugging is
-   long gone (performance issues with PT_WRITE_* and PT_READ_*)
  - research kevent support for tracing a process over a file descriptor,
    this means alternative to wait(2)-based events with passing events over the
    kqueue API - signal handlers are global per application and they clash with
diff -r e54f5dc83980 -r 7d8adfa68e0b sbin/mount_procfs/mount_procfs.8
--- a/sbin/mount_procfs/mount_procfs.8  Thu Apr 12 13:08:16 2018 +0000
+++ b/sbin/mount_procfs/mount_procfs.8  Thu Apr 12 13:42:48 2018 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: mount_procfs.8,v 1.34 2009/02/24 12:45:37 pooka Exp $
+.\"    $NetBSD: mount_procfs.8,v 1.34.38.1 2018/04/12 13:42:49 martin Exp $
 .\"
 .\" Copyright (c) 1992, 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -90,38 +90,6 @@
 corresponding to the process' command line arguments.
 For a system or zombie process, this file contains only a string
 with the name of the process.
-.It Pa ctl
-a writeonly file which supports a variety of control operations.
-Control commands are written as strings to the
-.Pa ctl
-file.
-The control commands are:
-.Bl -tag -width detach -compact
-.It attach
-stops the target process and arranges for the sending
-process to become the debug control process.
-.It detach
-continue execution of the target process and
-remove it from control by the debug process.
-.It run
-continue running the target process until
-a signal is delivered, a breakpoint is hit, or the
-target process exits.
-.It step
-single step the target process, with no signal delivery.
-.It wait
-wait for the target process to stop.
-The target process must be stopped before
-any of the run, step, or signal commands are allowed.
-.El
-.Pp
-The string can also be the name of a signal, lower case
-and without the
-.Dv SIG
-prefix,
-in which case that signal is delivered to the process
-(see
-.Xr sigaction 2 ) .
 .It Pa cwd
 A symbolic link that points to the current working directory of the
 process.
@@ -226,29 +194,10 @@
 all comma separated.
 .El
 .El
-.Pp
-In a normal debugging environment,
-where the target is fork/exec'd by the debugger,
-the debugger should fork and the child should stop
-itself (with a self-inflicted
-.Dv SIGSTOP
-for example).
-The parent should issue a
-.Dv wait
-and then an
-.Dv attach
-command via the appropriate
-.Pa ctl
-file.
-The child process will receive a
-.Dv SIGTRAP
-immediately after the call to exec (see
-.Xr execve 2 ) .
 .Sh FILES
 .Bl -tag -width /proc/curproc -compact
 .It Pa /proc/#
 .It Pa /proc/#/cmdline
-.It Pa /proc/#/ctl
 .It Pa /proc/#/cwd
 .It Pa /proc/#/exe
 .It Pa /proc/#/file
diff -r e54f5dc83980 -r 7d8adfa68e0b share/man/man9/kauth.9
--- a/share/man/man9/kauth.9    Thu Apr 12 13:08:16 2018 +0000
+++ b/share/man/man9/kauth.9    Thu Apr 12 13:42:48 2018 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: kauth.9,v 1.107 2017/03/18 19:01:01 riastradh Exp $
+.\" $NetBSD: kauth.9,v 1.107.4.1 2018/04/12 13:42:49 martin Exp $
 .\"
 .\" Copyright (c) 2005, 2006 Elad Efrat <elad%NetBSD.org@localhost>
 .\" All rights reserved.
@@ -553,7 +553,6 @@
 for the target element in the target process, and
 .Ar arg2
 is the access type, which can be either
-.Dv KAUTH_REQ_PROCESS_PROCFS_CTL ,
 .Dv KAUTH_REQ_PROCESS_PROCFS_READ ,
 .Dv KAUTH_REQ_PROCESS_PROCFS_RW ,
 or
diff -r e54f5dc83980 -r 7d8adfa68e0b sys/compat/linux/arch/arm/linux_ptrace.c
--- a/sys/compat/linux/arch/arm/linux_ptrace.c  Thu Apr 12 13:08:16 2018 +0000
+++ b/sys/compat/linux/arch/arm/linux_ptrace.c  Thu Apr 12 13:42:48 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: linux_ptrace.c,v 1.19 2015/10/13 08:24:35 pgoyette Exp $       */
+/*     $NetBSD: linux_ptrace.c,v 1.19.10.1 2018/04/12 13:42:49 martin Exp $    */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux_ptrace.c,v 1.19 2015/10/13 08:24:35 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_ptrace.c,v 1.19.10.1 2018/04/12 13:42:49 martin Exp $");
 
 #include <sys/param.h>
 #include <sys/mount.h>
@@ -157,8 +157,7 @@
         * 3. It is not being traced by _you_, or
         * 4. It is not currently stopped.
         */
-       if (ISSET(t->p_slflag, PSL_FSTRACE) || t->p_pptr != p ||
-           t->p_stat != SSTOP || !t->p_waited) {
+       if (t->p_pptr != p || t->p_stat != SSTOP || !t->p_waited) {
                mutex_exit(t->p_lock);
                mutex_exit(proc_lock);
                error = EBUSY;
diff -r e54f5dc83980 -r 7d8adfa68e0b sys/compat/linux/arch/i386/linux_ptrace.c
--- a/sys/compat/linux/arch/i386/linux_ptrace.c Thu Apr 12 13:08:16 2018 +0000
+++ b/sys/compat/linux/arch/i386/linux_ptrace.c Thu Apr 12 13:42:48 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: linux_ptrace.c,v 1.31 2015/10/13 08:24:35 pgoyette Exp $       */
+/*     $NetBSD: linux_ptrace.c,v 1.31.10.1 2018/04/12 13:42:48 martin Exp $    */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux_ptrace.c,v 1.31 2015/10/13 08:24:35 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_ptrace.c,v 1.31.10.1 2018/04/12 13:42:48 martin Exp $");
 
 #include <sys/param.h>
 #include <sys/mount.h>
@@ -197,13 +197,10 @@
                goto out;
        }
        /*
-        * 2. It is being traced by procfs (which has different signal
-        *    delivery semantics),
-        * 3. It is not being traced by _you_, or
-        * 4. It is not currently stopped.
+        * 2. It is not being traced by _you_, or
+        * 3. It is not currently stopped.
         */
-       if (ISSET(t->p_slflag, PSL_FSTRACE) || t->p_pptr != p ||
-           t->p_stat != SSTOP || !t->p_waited) {
+       if (t->p_pptr != p || t->p_stat != SSTOP || !t->p_waited) {
                mutex_exit(t->p_lock);
                mutex_exit(proc_lock);
                error = EBUSY;
diff -r e54f5dc83980 -r 7d8adfa68e0b sys/compat/linux/arch/powerpc/linux_ptrace.c
--- a/sys/compat/linux/arch/powerpc/linux_ptrace.c      Thu Apr 12 13:08:16 2018 +0000
+++ b/sys/compat/linux/arch/powerpc/linux_ptrace.c      Thu Apr 12 13:42:48 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: linux_ptrace.c,v 1.29 2015/10/13 08:24:35 pgoyette Exp $ */
+/*     $NetBSD: linux_ptrace.c,v 1.29.10.1 2018/04/12 13:42:49 martin Exp $ */
 
 /*-
  * Copyright (c) 1999, 2001 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux_ptrace.c,v 1.29 2015/10/13 08:24:35 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_ptrace.c,v 1.29.10.1 2018/04/12 13:42:49 martin Exp $");
 
 #include <sys/param.h>
 #include <sys/mount.h>
@@ -174,13 +174,10 @@
                goto out;
        }
        /*
-        * 2. It is being traced by procfs (which has different signal
-        *    delivery semantics),
-        * 3. It is not being traced by _you_, or
-        * 4. It is not currently stopped.
+        * 2. It is not being traced by _you_, or
+        * 3. It is not currently stopped.
         */
-       if (ISSET(t->p_slflag, PSL_FSTRACE) || t->p_pptr != p ||
-           t->p_stat != SSTOP || !t->p_waited) {
+       if (t->p_pptr != p || t->p_stat != SSTOP || !t->p_waited) {
                mutex_exit(t->p_lock);
                mutex_exit(proc_lock);
                error = EBUSY;
diff -r e54f5dc83980 -r 7d8adfa68e0b sys/compat/netbsd32/netbsd32.h
--- a/sys/compat/netbsd32/netbsd32.h    Thu Apr 12 13:08:16 2018 +0000
+++ b/sys/compat/netbsd32/netbsd32.h    Thu Apr 12 13:42:48 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: netbsd32.h,v 1.114 2016/11/13 13:52:41 rin Exp $       */
+/*     $NetBSD: netbsd32.h,v 1.114.8.1 2018/04/12 13:42:49 martin Exp $        */
 
 /*
  * Copyright (c) 1998, 2001, 2008, 2015 Matthew R. Green
@@ -292,6 +292,13 @@
                                           actual count (out) */
 };
 
+struct netbsd32_ptrace_siginfo {
+       siginfo32_t     psi_siginfo;    /* signal information structure */
+       lwpid_t         psi_lwpid;      /* destination LWP of the signal
+                                        * value 0 means the whole process
+                                        * (route signal to all LWPs) */
+};
+
 /* from <sys/quotactl.h> */
 typedef netbsd32_pointer_t netbsd32_quotactlargsp_t;
 struct netbsd32_quotactlargs {
@@ -1121,6 +1128,8 @@
 void netbsd32_adjust_limits(struct proc *);
 
 void   netbsd32_si_to_si32(siginfo32_t *, const siginfo_t *);
+void   netbsd32_si32_to_si(siginfo_t *, const siginfo32_t *);
+
 void   netbsd32_ksi32_to_ksi(struct _ksiginfo *si, const struct __ksiginfo32 *si32);
 
 #ifdef KTRACE
diff -r e54f5dc83980 -r 7d8adfa68e0b sys/compat/netbsd32/netbsd32_ptrace.c
--- a/sys/compat/netbsd32/netbsd32_ptrace.c     Thu Apr 12 13:08:16 2018 +0000
+++ b/sys/compat/netbsd32/netbsd32_ptrace.c     Thu Apr 12 13:42:48 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: netbsd32_ptrace.c,v 1.4 2017/02/23 03:34:22 kamil Exp $        */
+/*     $NetBSD: netbsd32_ptrace.c,v 1.4.6.1 2018/04/12 13:42:49 martin Exp $   */
 
 /*
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_ptrace.c,v 1.4 2017/02/23 03:34:22 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_ptrace.c,v 1.4.6.1 2018/04/12 13:42:49 martin Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ptrace.h"
@@ -54,18 +54,14 @@
  * PTRACE methods
  */
 
-static int netbsd32_copyinpiod(struct ptrace_io_desc *, const void *);
-static void netbsd32_copyoutpiod(const struct ptrace_io_desc *, void *);
-static int netbsd32_doregs(struct lwp *, struct lwp *, struct uio *);
-static int netbsd32_dofpregs(struct lwp *, struct lwp *, struct uio *);
-static int netbsd32_dodbregs(struct lwp *, struct lwp *, struct uio *);
-
-
 static int
-netbsd32_copyinpiod(struct ptrace_io_desc *piod, const void *addr)
+netbsd32_copyin_piod(struct ptrace_io_desc *piod, const void *addr, size_t len)
 {
        struct netbsd32_ptrace_io_desc piod32;
 
+       if (len != 0 && sizeof(piod32) != len)
+               return EINVAL;



Home | Main Index | Thread Index | Old Index