From nobody Tue Aug 27 15:25:06 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4WtWZB5PdMz52L9m; Tue, 27 Aug 2024 15:25:06 +0000 (UTC) (envelope-from git@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) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4WtWZB4rnMz4FL6; Tue, 27 Aug 2024 15:25:06 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1724772306; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=zjluDdZld2UPFb/go8qS83Phup36TK7kI2nraZeIpZQ=; b=nOOPyiYTCZb3pFb4J4UpS4pbSSaT9FudLhk5goLNgLqlR1RJx2ydB4/uhenxWTgXY2V3Qz jOu/t/uLcVcFZeuy3TiS4WChpQmeokXovLKS3Lwp8yjJajui6y4RCBV5trza323z9tVOTp bYu+cdpN4DDfzQTr9SZ9xmfvxVnmy+pMWRt5LFoYnvdeyBV44Bx2moEEbYmLkvh6G32rB8 ywr1/PlsH4kE1kZof0/AY1HqSjxV7egEBYpf0+l+oMN9ephMBfKcXJ4XNX0CP4Svs6yLjD 730jL+p+aTf9nJEri9lOoLZJDSY9x5/ZcVPhD16cetS51bDbDPHnw9dyHs8YeQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1724772306; a=rsa-sha256; cv=none; b=syXhrEndY5XTRrLSUWcPnkCxxh+mRyqWf1ksu3Si+IEASSb2MXDFZH7vZQsjWPlByvnqss 1ebUb8GXeqH9RU/aSFykSzI7s9+TlA9fyiN/N0E5Vk3YJ0PqXhZTevpD6i8X+yWPSTLzzY GeZZCEtZcjBeQs8h3d75/puEiX5/B7oEMG5p4Ux+kAd/HfgQztWD9lXAOi71WuzPowwg6t XhUCKU77d0/Yp1aLWtaWGLykXKxMVs+qYpmWgr2xvMCDfQtdE2VJcD1u1wUQPU/pU5/2r2 2Q2fqvLu2VoiRn7vlZBMYp7rWDYTYQtFibpt/eRL2IxxZfqUvt1fRU55mAbqVw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1724772306; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=zjluDdZld2UPFb/go8qS83Phup36TK7kI2nraZeIpZQ=; b=qZfqz5B0AXxkIhhfC/fiWYLRgK5pmYYdM1/N4qpYsN8vXbg0jQZYJjXqZhdRpe9QXcS90j ZiNd6725yNSlpHQP9SsYEHg5UbKhI3CvdUSIm/QmaA0sFE5ChCqO86NzS/pTwOMvsYVj3s IsvcHg0LCuDY4PM2vKaMWu3LZ8TFsYgIL6bV7+fV9yItKcCcGswbURr04wFfRBw9SlHMlU IxQfJpu3i4ZIW6BiU8cxgrFtFCmAWdRlFHB2Tirp/ajDW/1OMnlkXY80LB+f1kyUZ0dI4a 03SJutfwV34zNkrTUH3mjGJIw8qgcqEjC+yuUNzVt1W1H4Pwex+iD6bKt0DCQA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4WtWZB4RyKzvGD; Tue, 27 Aug 2024 15:25:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 47RFP6MS021272; Tue, 27 Aug 2024 15:25:06 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 47RFP6D8021269; Tue, 27 Aug 2024 15:25:06 GMT (envelope-from git) Date: Tue, 27 Aug 2024 15:25:06 GMT Message-Id: <202408271525.47RFP6D8021269@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mariusz Zaborski Subject: git: d0675399d09f - main - capsicum: allow subset of wait4(2) functionality List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: oshogbo X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: d0675399d09f02d347912e23d004329710338450 Auto-Submitted: auto-generated The branch main has been updated by oshogbo: URL: https://cgit.FreeBSD.org/src/commit/?id=d0675399d09f02d347912e23d004329710338450 commit d0675399d09f02d347912e23d004329710338450 Author: Edward Tomasz Napierala AuthorDate: 2024-08-27 15:19:24 +0000 Commit: Mariusz Zaborski CommitDate: 2024-08-27 15:22:12 +0000 capsicum: allow subset of wait4(2) functionality The usual way of handling process exit exit in capsicum(4) mode is by using process descriptors (pdfork(2)) instead of the traditional fork(2)/wait4(2) API. But most apps hadn't been converted this way, and many cannot because the wait is hidden behind a library APIs that revolve around PID numbers and not descriptors; GLib's g_spawn_check_wait_status(3) is one example. Thus, provide backwards compatibility by allowing the wait(2) family of functions in Capsicum mode, except for child processes created by pdfork(2). Reviewed by: brooks, oshogbo Sponsored by: Innovate UK Differential Revision: https://reviews.freebsd.org/D44372 --- contrib/capsicum-test/capmode.cc | 1 - lib/libsys/wait.2 | 10 +++++++--- sys/kern/kern_exit.c | 12 ++++++++++++ sys/kern/syscalls.master | 2 +- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/contrib/capsicum-test/capmode.cc b/contrib/capsicum-test/capmode.cc index f32d9e038744..5ff025290211 100644 --- a/contrib/capsicum-test/capmode.cc +++ b/contrib/capsicum-test/capmode.cc @@ -594,7 +594,6 @@ FORK_TEST_F(WithFiles, AllowedMiscSyscalls) { AWAIT_INT_MESSAGE(pipefds[0], MSG_CHILD_STARTED); errno = 0; EXPECT_CAPMODE(ptrace_(PTRACE_PEEKDATA_, pid, &pid, NULL)); - EXPECT_CAPMODE(waitpid(pid, NULL, WNOHANG)); SEND_INT_MESSAGE(pipefds[0], MSG_PARENT_REQUEST_CHILD_EXIT); if (verbose) fprintf(stderr, " child finished\n"); } diff --git a/lib/libsys/wait.2 b/lib/libsys/wait.2 index 8b504e070b7a..3c649f3dfa77 100644 --- a/lib/libsys/wait.2 +++ b/lib/libsys/wait.2 @@ -25,7 +25,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd June 24, 2022 +.Dd August 27, 2024 .Dt WAIT 2 .Os .Sh NAME @@ -605,9 +605,13 @@ must be checked against zero to determine if a process reported status. .Pp The .Fn wait -family of functions will not return a child process created with +family of functions will only return a child process created with .Xr pdfork 2 -unless specifically directed to do so by specifying its process ID. +if the calling process is not in +.Xr capsicum 4 +capability mode, and +.Nm +has been explicitly given the child's process ID. .Sh ERRORS The .Fn wait diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c index f83f0433f9cd..f6263cd46d06 100644 --- a/sys/kern/kern_exit.c +++ b/sys/kern/kern_exit.c @@ -1330,6 +1330,18 @@ loop_locked: return (0); } + /* + * When running in capsicum(4) mode, make wait(2) ignore + * processes created with pdfork(2). This is because one can + * disown them - by passing their process descriptor to another + * process - which means it needs to be prevented from touching + * them afterwards. + */ + if (IN_CAPABILITY_MODE(td) && p->p_procdesc != NULL) { + PROC_UNLOCK(p); + continue; + } + nfound++; PROC_LOCK_ASSERT(p, MA_OWNED); diff --git a/sys/kern/syscalls.master b/sys/kern/syscalls.master index 9fdd443955c7..fac1c2e1e96f 100644 --- a/sys/kern/syscalls.master +++ b/sys/kern/syscalls.master @@ -157,7 +157,7 @@ int fd ); } -7 AUE_WAIT4 STD { +7 AUE_WAIT4 STD|CAPENABLED { int wait4( int pid, _Out_opt_ int *status,