NetBSD Problem Report #51630

From www@NetBSD.org  Tue Nov 15 21:31:50 2016
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.netbsd.org", Issuer "Postmaster NetBSD.org" (verified OK))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 042ED7A293
	for <gnats-bugs@gnats.NetBSD.org>; Tue, 15 Nov 2016 21:31:50 +0000 (UTC)
Message-Id: <20161115213149.19AF17A2EA@mollari.NetBSD.org>
Date: Tue, 15 Nov 2016 21:31:49 +0000 (UTC)
From: n54@gmx.com
Reply-To: n54@gmx.com
To: gnats-bugs@NetBSD.org
Subject: ptrace(2) command PT_SET_EVENT_MASK: option PTRACE_VFORK unsupported
X-Send-Pr-Version: www-1.0

>Number:         51630
>Category:       kern
>Synopsis:       ptrace(2) command PT_SET_EVENT_MASK: option PTRACE_VFORK unsupported
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kamil
>State:          closed
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Tue Nov 15 21:35:00 +0000 2016
>Closed-Date:    Tue May 01 16:40:22 +0000 2018
>Last-Modified:  Tue May 01 16:50:00 +0000 2018
>Originator:     Kamil Rytarowski
>Release:        NetBSD 7.99.42 amd64
>Organization:
TNF
>Environment:
NetBSD chieftec 7.99.42 NetBSD 7.99.42 (GENERIC) #4: Mon Nov 14 17:24:18 CET 2016  kamil@chieftec:/public/netbsd-tmp/sys/arch/amd64/compile/GENERIC amd64
>Description:
Part of <sys/ptrace.h>:

/* PT_GET_PROCESS_STATE */
typedef struct ptrace_state {
        int     pe_report_event;
        pid_t   pe_other_pid;
} ptrace_state_t;

#define PTRACE_FORK     0x0001  /* Report forks */

There is missing option for PTRACE_VFORK. Currently vfork(2) isn't intercepted under PTRACE_FORK either.
>How-To-Repeat:
I'm going to commit the test to:

cd /usr/tests/kernel && atf-run t_ptrace_wait6 | atf-report

It will be moved out later once fixed to a dedicated file like t_ptrace_vfork_wait6
>Fix:
N/A

>Release-Note:

>Audit-Trail:
From: "Kamil Rytarowski" <kamil@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/51630 CVS commit: src/tests/kernel
Date: Tue, 15 Nov 2016 21:50:38 +0000

 Module Name:	src
 Committed By:	kamil
 Date:		Tue Nov 15 21:50:38 UTC 2016

 Modified Files:
 	src/tests/kernel: t_ptrace_wait.c

 Log Message:
 Add vfork1 test in t_ptrace_wait* and vfork2 in t_ptrace_wait{4,6,id,pid}

 These tests are exact clones for fork1 and fork2, however testing vfork(2).

 vfork1:
     Verify that vfork(2) is intercepted by ptrace(2) with EVENT_MASK set to
     PTRACE_VFORK.

 vfork2:
     Verify that vfork(2) is not intercepted by ptrace(2) with empty
     EVENT_MASK.

 vfork1 is supposed to test currently unimplemented PTRACE_VFORK option in
 EVENT_MASK, marked as failure and linked with PR kern/51630.

 Sponsored by <The NetBSD Foundation>


 To generate a diff of this commit:
 cvs rdiff -u -r1.17 -r1.18 src/tests/kernel/t_ptrace_wait.c

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

From: "Kamil Rytarowski" <kamil@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/51630 CVS commit: src/tests/kernel
Date: Sat, 14 Jan 2017 04:37:55 +0000

 Module Name:	src
 Committed By:	kamil
 Date:		Sat Jan 14 04:37:55 UTC 2017

 Modified Files:
 	src/tests/kernel: t_ptrace_wait.c

 Log Message:
 Add new tests eventmask[34] in t_ptrace_wait{,3,4,6,id,pid}

 eventmask3:
     Verify that PTRACE_VFORK in EVENT_MASK is preserved

 eventmask4:
     Verify that PTRACE_VFORK_DONE in EVENT_MASK is preserved

 Currently eventmask3 is failing and marked with PR kern/51630

 Sponsored by <The NetBSD Foundation>


 To generate a diff of this commit:
 cvs rdiff -u -r1.57 -r1.58 src/tests/kernel/t_ptrace_wait.c

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

From: "Kamil Rytarowski" <kamil@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/51630 CVS commit: src/tests/kernel
Date: Fri, 27 Jan 2017 00:34:52 +0000

 Module Name:	src
 Committed By:	kamil
 Date:		Fri Jan 27 00:34:52 UTC 2017

 Modified Files:
 	src/tests/kernel: t_ptrace_wait.c

 Log Message:
 Add new tests signal[67] in t_ptrace_wait{4,6,id,pid}

 signal6:
     Verify that masking SIGTRAP in tracee does not stop tracer from
     catching PTRACE_FORK breakpoint

 signal7:
     Verify that masking SIGTRAP in tracee does not stop tracer from
     catching PTRACE_VFORK breakpoint

 signal6 fails due to PR kern/51918
 signal6 fails due to PR kern/51918 and PR kern/51630

 Sponsored by <The NetBSD Foundation>


 To generate a diff of this commit:
 cvs rdiff -u -r1.65 -r1.66 src/tests/kernel/t_ptrace_wait.c

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

Responsible-Changed-From-To: kern-bug-people->kamil
Responsible-Changed-By: kamil@NetBSD.org
Responsible-Changed-When: Fri, 06 Oct 2017 23:12:26 +0200
Responsible-Changed-Why:
Take.


From: "Kamil Rytarowski" <kamil@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/51630 CVS commit: src/tests/lib/libc/sys
Date: Tue, 10 Apr 2018 22:45:39 +0000

 Module Name:	src
 Committed By:	kamil
 Date:		Tue Apr 10 22:45:39 UTC 2018

 Modified Files:
 	src/tests/lib/libc/sys: t_ptrace_wait.c

 Log Message:
 ATF t_ptrace_wait* refactoring: vforkdone1 and vforkdone2

 Merge vforkdone1 and vforkdone2 into other fork tests and reuse the same
 function body fork_test().

 There is an implicit enhancement in vforkdone2 that it was skipping
 PTRACE_VFORK check. This test is now marked as expected failure.

 PR kern/51630

 Sponsored by <The NetBSD Foundation>


 To generate a diff of this commit:
 cvs rdiff -u -r1.29 -r1.30 src/tests/lib/libc/sys/t_ptrace_wait.c

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

From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/51630 CVS commit: [netbsd-8] src/tests/lib/libc/sys
Date: Thu, 12 Apr 2018 13:02:21 +0000

 Module Name:	src
 Committed By:	martin
 Date:		Thu Apr 12 13:02:21 UTC 2018

 Modified Files:
 	src/tests/lib/libc/sys [netbsd-8]: msg.h t_ptrace_wait.c
 	    t_ptrace_wait.h t_ptrace_x86_wait.h

 Log Message:
 Pull up following revision(s) (requested by kamil in ticket #711):
 	tests/lib/libc/sys/t_ptrace_wait.c: revision 1.24-1.31
 	tests/lib/libc/sys/t_ptrace_wait.h: revision 1.2
 	tests/lib/libc/sys/t_ptrace_x86_wait.h: revision 1.4,1.5
 	tests/lib/libc/sys/msg.h: revision 1.2

 Correct all ATF failures in t_ptrace_x86_wait.h (debug registers)

 This code after refactoring stopped calling functions that were designed
 to trigger expected behavior and thus, tests were breaking.
 Sponsored by <The NetBSD Foundation>

 ATF: Correct a race bug in attach2 (t_ptrace_wait*)
 At the end of the test we resume a tracer and expect to observe it to
 collect the debuggee. We cannot from a parent point of view wait for
 collecting it with WNOHANG without a race.

 Remove the WNOHANG option from wait*(2) call. This corrects one type of
 race.

 This test is still racy for some other and unknown reason and this is bei=
 ng
 investigated.

 Sponsored by <The NetBSD Foundation>

 ATF: Reenable attach2 in t_ptrace_wait*

 The primary race specific to this test has been fixed in previous commit
 (wrong WNOHANG).

 This test is still racy and breaks like once every 30,000 execution.
 This is down like from once from every 100th execution in the past.
 The remaning race is not specific to attach2 and I can reproduce it with
 at least attach1. It still looks like being specific to NetBSD and it's
 not reproducible on Linux and FreeBSD. Perhaps a bug with pipe(2)/write(2=
 )/
 read(2) or close to these features.

 Sponsored by <The NetBSD Foundation>

 Add a new function in ATF t_ptrace_wait*: await_zombie_raw()

 Add await_zombie_raw() that is the same as await_zombie(), whith an
 addition of additional "useconds_t ms" parameter indicating delays betwee=
 n
 new polling for a zombie process.

 This new function will be used for testing a race condition that has been=
 observed occassionally crashing a test case -- returning duplicate entrie=
 s
 for KERN_PROC_PID.

 Sponsored by <The NetBSD Foundation>

 ATF t_ptrace_wait*: Disable debug messages in msg.h
 msg.h is a dummy IPC interface.

 Disable additional debugging logging here, especially wanted in race*
 tests.

 Sponsored by <The NetBSD Foundation>

 ATF: Add new test race1 in t_ptrace_wait*

 Reuse the attach1's test body for race1.

 Add a new test race1:
   Assert that await_zombie() in attach1 always finds a single
   process and no other error is reported
 race1 requires HAVE_PID in wait(2)-like function.

 This test is executed in a loop for 5 seconds (16k iterations on Intel i7=
 ).
 A buggy kernel was asserting an error within this timeframe almost always=
 =2E
 The bug in the kernel is now gone and this test is expected to pass
 correctly.

 Sponsored by <The NetBSD Foundation>

 Add check in ATF tests for security.models.extensions.user_set_dbregs
 Introduce a new function can_we_set_dbregs() in the ATF ptrace(2) tests.

 It uses lazy-bool evaluation whether a process can call PT_SETDBREGS.
 In case of not being able to do so, print a message and mark a test
 as skipped:
   Either run this test as root or set sysctl(3)
   security.models.extensions.user_set_dbregs to 1
 No functional change intended to the code flow of the existing tested
 scenarios.

 Sponsored by <The NetBSD Foundation>

 Improve documentation of the ATF test t_ptrace_wait*: traceme2
 Set the description to:
   Verify that a signal emitted by a tracer to a child is caught by
   a signal handler.

 Sponsored by <The NetBSD Foundation>

 Merge code in tests: fork1 and vfork1 (ATF t_ptrace_wait*)

 Marge bodies of two tests into the same function.

 Add few checks for regular fork or not (vfork).

 Sponsored by <The NetBSD Foundation>

 ATF: ptrace: Merge code in fork2 and vfork2 tests with (v)fork1 ones
 Reduce code duplication, use the same function body with conditional
 switches.

 Sponsored by <The NetBSD Foundation>

 ATF t_ptrace_wait* refactoring: vforkdone1 and vforkdone2

 Merge vforkdone1 and vforkdone2 into other fork tests and reuse the same
 function body fork_test().

 There is an implicit enhancement in vforkdone2 that it was skipping
 PTRACE_VFORK check. This test is now marked as expected failure.
 PR kern/51630

 Sponsored by <The NetBSD Foundation>

 Cover more fork/vfork/vforkdone scenarios in ATF ptrace(2) tests

 Use a shared common body for all the tests: fork1..fork8, vfork1..vfork8.=
 Merge vforkdone1 and vforkdone2 into vfork* tests.

 All the (v?)fork[1-8] tests cover:
  - calling either fork(2) or vfork(2)
  - tracking either enabled or disabled FORK, VFORK or VFORK_DONE

 All the PTRACE_VFORK tests are marked as expected failure.

 Sponsored by <The NetBSD Foundation>


 To generate a diff of this commit:
 cvs rdiff -u -r1.1 -r1.1.8.1 src/tests/lib/libc/sys/msg.h \
     src/tests/lib/libc/sys/t_ptrace_wait.h
 cvs rdiff -u -r1.9.2.2 -r1.9.2.3 src/tests/lib/libc/sys/t_ptrace_wait.c
 cvs rdiff -u -r1.1.8.1 -r1.1.8.2 src/tests/lib/libc/sys/t_ptrace_x86_wait.h

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

State-Changed-From-To: open->closed
State-Changed-By: kamil@NetBSD.org
State-Changed-When: Tue, 01 May 2018 18:40:22 +0200
State-Changed-Why:
Fixed in HEAD:

cvs rdiff -u -r1.204 -r1.205 src/sys/kern/kern_fork.c
cvs rdiff -u -r1.341 -r1.342 src/sys/kern/kern_sig.c
cvs rdiff -u -r1.39 -r1.40 src/sys/kern/sys_ptrace_common.c
cvs rdiff -u -r1.89 -r1.90 src/sys/sys/signalvar.h

NetBSD 8.99.14.


From: "Kamil Rytarowski" <kamil@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/51630 CVS commit: src
Date: Tue, 1 May 2018 16:37:24 +0000

 Module Name:	src
 Committed By:	kamil
 Date:		Tue May  1 16:37:23 UTC 2018

 Modified Files:
 	src/lib/libc/sys: ptrace.2
 	src/sys/kern: kern_fork.c kern_sig.c sys_ptrace_common.c
 	src/sys/sys: signalvar.h
 	src/tests/lib/libc/sys: t_ptrace_wait.c

 Log Message:
 Implement PTRACE_VFORK

 Add support for tracing vfork(2) events in the context of ptrace(2).

 This API covers other frontends to fork1(9) like posix_spawn(2) or clone(2),
 if they cause parent to wait for exec(2) or exit(2) of the child.

 Changes:
  - Add new argument to sigswitch() determining whether we need to acquire
    the proc_lock or whether it's already held.
  - Refactor fork1(9) for fork(2) and vfork(2)-like events.
    Call sigswitch() from fork(1) for forking or vforking parent, instead of
    emitting kpsignal(9). We need to emit the signal and suspend the parent,
    returning to user and relock proc_lock.
  - Add missing prototype for proc_stop_done() in kern_sig.c.
  - Make sigswitch a public function accessible from other kernel code
    including <sys/signalvar.h>.
  - Remove an entry about unimplemented PTRACE_VFORK in the ptrace(2) man page.
  - Permin PTRACE_VFORK in the ptrace(2) frontend for userland.
  - Remove expected failure for unimplemented PTRACE_VFORK tests in the ATF
    ptrace(2) test-suite.
  - Relax signal routing constraints under a debugger for a vfork(2)ed child.
    This intended to protect from signaling a parent of a vfork(2)ed child that
    called PT_TRACE_ME, but wrongly misrouted other signals in vfork(2)
    use-cases.

 Add XXX comments about still existing problems and future enhancements:
  - correct vfork(2) + PT_TRACE_ME handling.
  - fork1(2) handling of scenarios when a process is collected in valid but
    rare cases.

 All ATF ptrace(2) fork[1-8] and vfork[1-8] tests pass.

 Fix PR kern/51630 by Kamil Rytarowski (myself).

 Sponsored by <The NetBSD Foundation>


 To generate a diff of this commit:
 cvs rdiff -u -r1.68 -r1.69 src/lib/libc/sys/ptrace.2
 cvs rdiff -u -r1.204 -r1.205 src/sys/kern/kern_fork.c
 cvs rdiff -u -r1.341 -r1.342 src/sys/kern/kern_sig.c
 cvs rdiff -u -r1.39 -r1.40 src/sys/kern/sys_ptrace_common.c
 cvs rdiff -u -r1.89 -r1.90 src/sys/sys/signalvar.h
 cvs rdiff -u -r1.37 -r1.38 src/tests/lib/libc/sys/t_ptrace_wait.c

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

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.43 2018/01/16 07:36:43 maya Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2017 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.