From owner-svn-src-stable-12@freebsd.org Tue Sep 3 14:07:21 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 0D5B8DD909; Tue, 3 Sep 2019 14:07:21 +0000 (UTC) (envelope-from yuripv@freebsd.org) Received: from freefall.freebsd.org (freefall.freebsd.org [96.47.72.132]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "freefall.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 46N80S5F4xz4QW4; Tue, 3 Sep 2019 14:07:20 +0000 (UTC) (envelope-from yuripv@freebsd.org) Received: by freefall.freebsd.org (Postfix, from userid 1452) id 674AD1B4AA; Tue, 3 Sep 2019 14:06:36 +0000 (UTC) X-Original-To: yuripv@localmail.freebsd.org Delivered-To: yuripv@localmail.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [96.47.72.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client CN "mx1.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by freefall.freebsd.org (Postfix) with ESMTPS id C9273C01B; Mon, 22 Apr 2019 11:13:58 +0000 (UTC) (envelope-from owner-src-committers@freebsd.org) Received: from freefall.freebsd.org (freefall.freebsd.org [96.47.72.132]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "freefall.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 42ABB85C58; Mon, 22 Apr 2019 11:13:58 +0000 (UTC) (envelope-from owner-src-committers@freebsd.org) Received: by freefall.freebsd.org (Postfix, from userid 538) id 1DB61BFF7; Mon, 22 Apr 2019 11:13:58 +0000 (UTC) Delivered-To: src-committers@localmail.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client CN "mx1.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by freefall.freebsd.org (Postfix) with ESMTPS id F3C58BFF5 for ; Mon, 22 Apr 2019 11:13:54 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id B8A5C85C54; Mon, 22 Apr 2019 11:13:54 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 915D5C216; Mon, 22 Apr 2019 11:13:54 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3MBDscG033259; Mon, 22 Apr 2019 11:13:54 GMT (envelope-from markj@FreeBSD.org) Received: (from markj@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3MBDseR033257; Mon, 22 Apr 2019 11:13:54 GMT (envelope-from markj@FreeBSD.org) Message-Id: <201904221113.x3MBDseR033257@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: markj set sender to markj@FreeBSD.org using -f From: Mark Johnston To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346540 - in stable/12: sys/kern tests/sys/kern X-SVN-Group: stable-12 X-SVN-Commit-Author: markj X-SVN-Commit-Paths: in stable/12: sys/kern tests/sys/kern X-SVN-Commit-Revision: 346540 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk X-Loop: FreeBSD.org Sender: owner-src-committers@freebsd.org X-Rspamd-Queue-Id: 42ABB85C58 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.98 / 15.00]; local_wl_from(0.00)[freebsd.org]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.98)[-0.976,0]; ASN(0.00)[asn:11403, ipnet:96.47.64.0/20, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] Status: O X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Date: Tue, 03 Sep 2019 14:07:22 -0000 X-Original-Date: Mon, 22 Apr 2019 11:13:54 +0000 (UTC) X-List-Received-Date: Tue, 03 Sep 2019 14:07:22 -0000 Author: markj Date: Mon Apr 22 11:13:53 2019 New Revision: 346540 URL: https://svnweb.freebsd.org/changeset/base/346540 Log: MFC r346009: Set the p_oppid field of orphans when exiting. Modified: stable/12/sys/kern/kern_exit.c stable/12/tests/sys/kern/ptrace_test.c Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/kern/kern_exit.c ============================================================================== --- stable/12/sys/kern/kern_exit.c Mon Apr 22 11:09:24 2019 (r346539) +++ stable/12/sys/kern/kern_exit.c Mon Apr 22 11:13:53 2019 (r346540) @@ -521,6 +521,11 @@ exit1(struct thread *td, int rval, int signo) */ while ((q = LIST_FIRST(&p->p_orphans)) != NULL) { PROC_LOCK(q); + KASSERT(q->p_oppid == p->p_pid, + ("orphan %p of %p has unexpected oppid %d", q, p, + q->p_oppid)); + q->p_oppid = q->p_reaper->p_pid; + /* * If we are the real parent of this process * but it has been reparented to a debugger, then Modified: stable/12/tests/sys/kern/ptrace_test.c ============================================================================== --- stable/12/tests/sys/kern/ptrace_test.c Mon Apr 22 11:09:24 2019 (r346539) +++ stable/12/tests/sys/kern/ptrace_test.c Mon Apr 22 11:13:53 2019 (r346540) @@ -453,6 +453,67 @@ ATF_TC_BODY(ptrace__parent_sees_exit_after_unrelated_d } /* + * Make sure that we can collect the exit status of an orphaned process. + */ +ATF_TC_WITHOUT_HEAD(ptrace__parent_exits_before_child); +ATF_TC_BODY(ptrace__parent_exits_before_child, tc) +{ + ssize_t n; + int cpipe1[2], cpipe2[2], gcpipe[2], status; + pid_t child, gchild; + + ATF_REQUIRE(pipe(cpipe1) == 0); + ATF_REQUIRE(pipe(cpipe2) == 0); + ATF_REQUIRE(pipe(gcpipe) == 0); + + ATF_REQUIRE(procctl(P_PID, getpid(), PROC_REAP_ACQUIRE, NULL) == 0); + + ATF_REQUIRE((child = fork()) != -1); + if (child == 0) { + CHILD_REQUIRE((gchild = fork()) != -1); + if (gchild == 0) { + status = 1; + do { + n = read(gcpipe[0], &status, sizeof(status)); + } while (n == -1 && errno == EINTR); + _exit(status); + } + + CHILD_REQUIRE(write(cpipe1[1], &gchild, sizeof(gchild)) == + sizeof(gchild)); + CHILD_REQUIRE(read(cpipe2[0], &status, sizeof(status)) == + sizeof(status)); + _exit(status); + } + + ATF_REQUIRE(read(cpipe1[0], &gchild, sizeof(gchild)) == sizeof(gchild)); + + ATF_REQUIRE(ptrace(PT_ATTACH, gchild, NULL, 0) == 0); + + status = 0; + ATF_REQUIRE(write(cpipe2[1], &status, sizeof(status)) == + sizeof(status)); + ATF_REQUIRE(waitpid(child, &status, 0) == child); + ATF_REQUIRE(WIFEXITED(status) && WEXITSTATUS(status) == 0); + + status = 0; + ATF_REQUIRE(write(gcpipe[1], &status, sizeof(status)) == + sizeof(status)); + ATF_REQUIRE(waitpid(gchild, &status, 0) == gchild); + ATF_REQUIRE(WIFSTOPPED(status)); + ATF_REQUIRE(ptrace(PT_DETACH, gchild, (caddr_t)1, 0) == 0); + ATF_REQUIRE(waitpid(gchild, &status, 0) == gchild); + ATF_REQUIRE(WIFEXITED(status) && WEXITSTATUS(status) == 0); + + ATF_REQUIRE(close(cpipe1[0]) == 0); + ATF_REQUIRE(close(cpipe1[1]) == 0); + ATF_REQUIRE(close(cpipe2[0]) == 0); + ATF_REQUIRE(close(cpipe2[1]) == 0); + ATF_REQUIRE(close(gcpipe[0]) == 0); + ATF_REQUIRE(close(gcpipe[1]) == 0); +} + +/* * The parent process should always act the same regardless of how the * debugger is attached to it. */ @@ -3851,6 +3912,7 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC(tp, ptrace__parent_wait_after_attach); ATF_TP_ADD_TC(tp, ptrace__parent_sees_exit_after_child_debugger); ATF_TP_ADD_TC(tp, ptrace__parent_sees_exit_after_unrelated_debugger); + ATF_TP_ADD_TC(tp, ptrace__parent_exits_before_child); ATF_TP_ADD_TC(tp, ptrace__follow_fork_both_attached); ATF_TP_ADD_TC(tp, ptrace__follow_fork_child_detached); ATF_TP_ADD_TC(tp, ptrace__follow_fork_parent_detached);