From nobody Wed Jun 19 20:37:09 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 4W4Fm62Sfnz5Nn6n; Wed, 19 Jun 2024 20:37:10 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4W4Fm56kJXz4PD7; Wed, 19 Jun 2024 20:37:09 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1718829429; 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=yiRK9OZw5PvQgyhSP2GBPtOghyibdThpfxqFLkiYdxU=; b=rjbSt9OxqvRVYp5605nadLOZAiw1Kla9PVLGi8erq29f0LaoB9IUhPI+0hLgFrRagr4kG5 br6OymaPNsY5IuRHVOnAUrpS7PbTcdmkclBullVCOwLM9bfYd0ufkiDotPUASw4Id45E2Z Zv/WLhgpX/MK4/LyVCmVxyoLZupe18oz6mRLE08YqxdJn7/glbx0OPthTJPU1m//xfN183 s/1vAvUL3cb4C+WwJ9x42o11OahbRxAElGpd9AlRm/etHgrQgzRq681di9kubNu9RHNSYb zgaG8jPHS3gukwKcxVpnwoR+PJJQ9q/X3Pp/Hf0RMNoDQ7tmpe/VF1cHGRHZNQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1718829429; a=rsa-sha256; cv=none; b=FVTpy9u61v8hIkfvbx4zFIIEwuGI6PAK3Cbu19bnfgJwSg4REr4Prl0pqa8g2O4SNnNAFA Ej2Ka+ubuM/e2SEjrKOpnzgCrMPfLVVH1wR3rSXvGR3NKCSCNs82w3628nn4UwrICL89kK ZMhjPYFeP9xY0rCFR3wvCvrkfLW662jf67ybo/q3nmaOEqgA1oL3I0lxxEQ9oE7+9bAyP4 LR1KQKD1nTD66zsWr0PRg7MdXb2LQB3nwaecdCk6I1fnKXjUuT13zIRkhmBejWXuOtsww2 +QaZtc6+CrwcbuPzuS4smho52MtOPS3FXssXScOiaypa2l1WCuyi7PqxEGUKpQ== 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=1718829429; 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=yiRK9OZw5PvQgyhSP2GBPtOghyibdThpfxqFLkiYdxU=; b=xlxifj+DorBm/Cmld9hrKe3mCXb5DycFqGBv649yGBRZcSCGsQr/0Lof3NEftdIGQXpsjF 3xs0GQh98FiEeYgWq1cFkCnCV7z45NThpnGgY5x4L8z3hYCqgEZljdsyfyxMEagS5nSHwy a2QprxUQrjUElWnypEpTsI/k4ZKZwINtaJLg6zI1KniGfcZqp8wQQmFLlCj6BRuHZdj1Cx DqiC5bCmpuhulS4qZhp9yVD+yWgFBQYzGZ3Xb7GNHDGzPNmi23fnc78+aUCnwkkVjXcpMw Ysw6OiHuo0WmBfd5N1Yd1QwcE/pYrJ6f9hLsu27p/gzX4c8i7um9NyvnBbCeWQ== 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 4W4Fm56LqczwpZ; Wed, 19 Jun 2024 20:37:09 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 45JKb99M002405; Wed, 19 Jun 2024 20:37:09 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 45JKb9FE002402; Wed, 19 Jun 2024 20:37:09 GMT (envelope-from git) Date: Wed, 19 Jun 2024 20:37:09 GMT Message-Id: <202406192037.45JKb9FE002402@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Gordon Tetlow Subject: git: eb410545d00d - releng/13.3 - killpg(): more carefully avoid LoR 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: gordon X-Git-Repository: src X-Git-Refname: refs/heads/releng/13.3 X-Git-Reftype: branch X-Git-Commit: eb410545d00d55a40c4c30eb42b9d2ef5bb2361d Auto-Submitted: auto-generated The branch releng/13.3 has been updated by gordon: URL: https://cgit.FreeBSD.org/src/commit/?id=eb410545d00d55a40c4c30eb42b9d2ef5bb2361d commit eb410545d00d55a40c4c30eb42b9d2ef5bb2361d Author: Konstantin Belousov AuthorDate: 2023-07-07 17:19:33 +0000 Commit: Gordon Tetlow CommitDate: 2024-06-18 17:26:29 +0000 killpg(): more carefully avoid LoR Approved by: so Security: FreeBSD-EN-24:12.killpg (cherry picked from commit 7a70f17ac4bd64dc1a5020f963ba4380cf37b7e5) (cherry picked from commit cd73b38955f62d9c05ded8e641a7462ca0f06179) --- sys/kern/kern_proc.c | 15 +++++++++++++-- sys/kern/kern_prot.c | 6 ++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c index 61c389f0b345..0db3718e15ff 100644 --- a/sys/kern/kern_proc.c +++ b/sys/kern/kern_proc.c @@ -587,8 +587,12 @@ enterpgrp(struct proc *p, pid_t pgid, struct pgrp *pgrp, struct session *sess) ("enterpgrp: session leader attempted setpgrp")); old_pgrp = p->p_pgrp; - if (!sx_try_xlock(&old_pgrp->pg_killsx)) + if (!sx_try_xlock(&old_pgrp->pg_killsx)) { + sx_xunlock(&proctree_lock); + sx_xlock(&old_pgrp->pg_killsx); + sx_xunlock(&old_pgrp->pg_killsx); return (ERESTART); + } MPASS(old_pgrp == p->p_pgrp); if (sess != NULL) { @@ -656,11 +660,18 @@ enterthispgrp(struct proc *p, struct pgrp *pgrp) ("%s: p %p belongs to pgrp %p", __func__, p, pgrp)); old_pgrp = p->p_pgrp; - if (!sx_try_xlock(&old_pgrp->pg_killsx)) + if (!sx_try_xlock(&old_pgrp->pg_killsx)) { + sx_xunlock(&proctree_lock); + sx_xlock(&old_pgrp->pg_killsx); + sx_xunlock(&old_pgrp->pg_killsx); return (ERESTART); + } MPASS(old_pgrp == p->p_pgrp); if (!sx_try_xlock(&pgrp->pg_killsx)) { sx_xunlock(&old_pgrp->pg_killsx); + sx_xunlock(&proctree_lock); + sx_xlock(&pgrp->pg_killsx); + sx_xunlock(&pgrp->pg_killsx); return (ERESTART); } diff --git a/sys/kern/kern_prot.c b/sys/kern/kern_prot.c index a91b7ec3015f..5dea43971e3d 100644 --- a/sys/kern/kern_prot.c +++ b/sys/kern/kern_prot.c @@ -345,10 +345,8 @@ again: error = EPERM; } else { error = enterpgrp(p, p->p_pid, newpgrp, newsess); - if (error == ERESTART) { - sx_xunlock(&proctree_lock); + if (error == ERESTART) goto again; - } MPASS(error == 0); td->td_retval[0] = p->p_pid; newpgrp = NULL; @@ -458,11 +456,11 @@ again: error = enterthispgrp(targp, pgrp); } done: - sx_xunlock(&proctree_lock); KASSERT(error == 0 || newpgrp != NULL, ("setpgid failed and newpgrp is NULL")); if (error == ERESTART) goto again; + sx_xunlock(&proctree_lock); uma_zfree(pgrp_zone, newpgrp); return (error); }