From nobody Mon Jun 9 23:48:01 2025 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 4bGTBV5zz5z5ygk0; Mon, 09 Jun 2025 23:48:02 +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 4bGTBT74PXz3F24; Mon, 09 Jun 2025 23:48:01 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1749512882; 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=UNWKHFAAPZW0CF4jetl1o0giDecQe2E8APLvmJ7O8rY=; b=mXjrGz2XijF6PaoouEH5ExX8xdn3EUPQ8FzU0RsqKU/cw33efFjy2w9U+sFqVmI7GLL+yi n+2j3BCyxLhoOg/McWqeFuV18vTeFuwK6LPyAa8nw1h5uGqFnUse+zyDvZy+NBVQ+RX5Ux DI0FJcp2dPXf9lmaomiID/JBTvXvzl5JukSUihNZmTnM40sHpJnLy+CtfCZ0OH2cTj/7a/ kHLxDLg3WIYda17FmkS8FJwC9jl9oDdE2pgeTrGf6RgBJBsfe1RRiHKFi51eQWoMGgp4UY moRKqVpKp/w8qLd+Shdb1ncYU8QpC1pB/QEkgA20JjqthYcuIHzJrYGTqhjFvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1749512882; 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=UNWKHFAAPZW0CF4jetl1o0giDecQe2E8APLvmJ7O8rY=; b=s+5uL7ieU9CNymltCyyyts9hwt8mF9ZLOiP+uZ9Z3oxP7fu/J741Mh0SL7+AuNPsgCEFcx 8YnOjiRQW/KPqeenLr5PbppLv/Y6EI9QosTLpsb3WgQGTMH7isTFkoyZroRaX4JHsW5jFi Xt0TD14W0tEESzBQIoeqXdwVxLkBtmMXpqn4H3bi6GpyOFpXLnm6PXRF8hh3p3DFEnX/2I RcrfTELJqjyk1t4fewortSW1sbJkzw0v9/HZDdq9vWHg44C42pRRAXxyx/cuQR3Cpe5haP 1KHI7ajez69vHxU3GXj3lAf53odQrqQ4fQ25NBo2iNJyNCGrNrZQHeIolMADCw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1749512882; a=rsa-sha256; cv=none; b=oH0KX4nK/E7Q536Y5Qn92Itux5AVq8Jce9p3ky4E4jK88PLLxWu8pyznf6rhW0jwn8Gr6h acdcGdSOji/PW80RY+Gube2qm21OFUNa5WYOIOLYIuuGdj0B/ZGlvlrSfOCZ+vIO3amNGB pH7OrOQcplL78iSf/w81tXGc4HxpROX30soZ/5OTg74fmNK/rdkwjUAWn6kGAprAA0oIGy q8qQGeWvnpRPaUbV2xI19twhnow1i+gKQdAzzOWCLmSLgZjwksdlZov+df/2mhvDNN3mqm zhX/XSRU9JGhOC7TZepBwqEcIL+73BWQHOnRnbLs9mpC6Agb6QN/Krf5ywc4PQ== 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 4bGTBT6TBBz2P3; Mon, 09 Jun 2025 23:48:01 +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 559Nm10t088756; Mon, 9 Jun 2025 23:48:01 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 559Nm1tK088753; Mon, 9 Jun 2025 23:48:01 GMT (envelope-from git) Date: Mon, 9 Jun 2025 23:48:01 GMT Message-Id: <202506092348.559Nm1tK088753@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 0d5b6fb6aee8 - main - kern_prot: extract code to check that active ids are superset of obj ids 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: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 0d5b6fb6aee8faff5265d429daaf61e7b79c5252 Auto-Submitted: auto-generated The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=0d5b6fb6aee8faff5265d429daaf61e7b79c5252 commit 0d5b6fb6aee8faff5265d429daaf61e7b79c5252 Author: Konstantin Belousov AuthorDate: 2025-06-07 13:47:34 +0000 Commit: Konstantin Belousov CommitDate: 2025-06-09 23:47:12 +0000 kern_prot: extract code to check that active ids are superset of obj ids Export it as a helper cr_xids_subset(). Reviewed by: markj Sponsored by: NVidia networking Differential revision: https://reviews.freebsd.org/D50653 --- sys/kern/kern_prot.c | 64 ++++++++++++++++++++++++++++++++-------------------- sys/sys/ucred.h | 1 + 2 files changed, 40 insertions(+), 25 deletions(-) diff --git a/sys/kern/kern_prot.c b/sys/kern/kern_prot.c index cc140d28e13d..d9aeec68e620 100644 --- a/sys/kern/kern_prot.c +++ b/sys/kern/kern_prot.c @@ -2150,6 +2150,43 @@ SYSCTL_PROC(_security_bsd, OID_AUTO, unprivileged_proc_debug, CTLFLAG_MPSAFE, 0, 0, sysctl_unprivileged_proc_debug, "I", "Unprivileged processes may use process debugging facilities"); +/* + * Return true if the object owner/group ids are subset of the active + * credentials. + */ +bool +cr_xids_subset(struct ucred *active_cred, struct ucred *obj_cred) +{ + int i; + bool grpsubset, uidsubset; + + /* + * Is p's group set a subset of td's effective group set? This + * includes p's egid, group access list, rgid, and svgid. + */ + grpsubset = true; + for (i = 0; i < obj_cred->cr_ngroups; i++) { + if (!groupmember(obj_cred->cr_groups[i], active_cred)) { + grpsubset = false; + break; + } + } + grpsubset = grpsubset && + groupmember(obj_cred->cr_rgid, active_cred) && + groupmember(obj_cred->cr_svgid, active_cred); + + /* + * Are the uids present in obj_cred's credential equal to + * active_cred's effective uid? This includes obj_cred's + * euid, svuid, and ruid. + */ + uidsubset = (active_cred->cr_uid == obj_cred->cr_uid && + active_cred->cr_uid == obj_cred->cr_svuid && + active_cred->cr_uid == obj_cred->cr_ruid); + + return (uidsubset && grpsubset); +} + /*- * Determine whether td may debug p. * Returns: 0 for permitted, an errno value otherwise @@ -2161,7 +2198,7 @@ SYSCTL_PROC(_security_bsd, OID_AUTO, unprivileged_proc_debug, int p_candebug(struct thread *td, struct proc *p) { - int error, grpsubset, i, uidsubset; + int error; KASSERT(td == curthread, ("%s: td not curthread", __func__)); PROC_LOCK_ASSERT(p, MA_OWNED); @@ -2178,35 +2215,12 @@ p_candebug(struct thread *td, struct proc *p) if ((error = cr_bsd_visible(td->td_ucred, p->p_ucred))) return (error); - /* - * Is p's group set a subset of td's effective group set? This - * includes p's egid, group access list, rgid, and svgid. - */ - grpsubset = 1; - for (i = 0; i < p->p_ucred->cr_ngroups; i++) { - if (!groupmember(p->p_ucred->cr_groups[i], td->td_ucred)) { - grpsubset = 0; - break; - } - } - grpsubset = grpsubset && - groupmember(p->p_ucred->cr_rgid, td->td_ucred) && - groupmember(p->p_ucred->cr_svgid, td->td_ucred); - - /* - * Are the uids present in p's credential equal to td's - * effective uid? This includes p's euid, svuid, and ruid. - */ - uidsubset = (td->td_ucred->cr_uid == p->p_ucred->cr_uid && - td->td_ucred->cr_uid == p->p_ucred->cr_svuid && - td->td_ucred->cr_uid == p->p_ucred->cr_ruid); - /* * If p's gids aren't a subset, or the uids aren't a subset, * or the credential has changed, require appropriate privilege * for td to debug p. */ - if (!grpsubset || !uidsubset) { + if (!cr_xids_subset(td->td_ucred, p->p_ucred)) { error = priv_check(td, PRIV_DEBUG_DIFFCRED); if (error) return (error); diff --git a/sys/sys/ucred.h b/sys/sys/ucred.h index 7d04ea7de97f..ddd8f3ddb63d 100644 --- a/sys/sys/ucred.h +++ b/sys/sys/ucred.h @@ -237,6 +237,7 @@ void cru2xt(struct thread *td, struct xucred *xcr); void crsetgroups(struct ucred *cr, int ngrp, const gid_t *groups); void crsetgroups_fallback(struct ucred *cr, int ngrp, const gid_t *groups, const gid_t fallback); +bool cr_xids_subset(struct ucred *active_cred, struct ucred *obj_cred); /* * Returns whether gid designates a primary group in cred.