From nobody Tue Oct 17 19:43:38 2023 X-Original-To: dev-commits-src-branches@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 4S94Ct5klLz4xvd7; Tue, 17 Oct 2023 19:43:38 +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 4S94Ct4yG9z3LD7; Tue, 17 Oct 2023 19:43:38 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1697571818; 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=cBR5f4Yl+a4RXAzL5mF8tVhY8PjrvEDFWRQP5U9onJo=; b=yz4kGQfXOzDBjTRDP5zHhPIDBmWjdy9OoFGn+ql9dfdcFbGJSbghE2SGs8dABS+UM3KDv7 gCoJJHbEOIydihhEJnIg+CrBiBD2lWpvqoVsBoT1kL6MT/BmHJlOpZrIHdmxa8HVTOPJvk pwYgyzzBfAOciRPfgaNXjWks4zNpFSwBbQXMav/NYxqhrT4FQZXqoqI3b3yOmT319/9pRL o1bJou+WWOzxd0Ok3Tt7CTs+7hcTvtVXesiLd0zgxJ8wI3cLfb+rjfi+9y/hNpFSpGMDrS qSfQjUn/Kb0UQZGgEM7TRhSu/DIZOYwNbaOTcCfixyQNOc9XlPGxMNCE8WlnVQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1697571818; a=rsa-sha256; cv=none; b=wb3ZKoH/JpH8AnYAchAiBX0eT7PUn25cK84jOCdP/pBlCGOj1adSonLoxjYDY1N+9OGV2N HdpW+UIQx4deojqH7XYwA17ufgOzNRJYlqvQTh9pouIBMS2I7tRYN16TRfRnqFak8WBKDi YHJ2AnWYuptg6mUm/VNQCJsmSFZK5Wpr1ui1AAyvxV7PRwuIeswOxH2neBAsu+wMSi84ph t6pYi4EpRqNn5LjGZlyb65nwYud96cfTy5dZb/mzuTeFgFlblXs15vHHRbySEVdGToN2C6 b5/oKU+c8u2Pd2Gz1y6tpxvPpLvTDme8TAaq99oWPArlIjChW737h2z5kK1mFg== 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=1697571818; 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=cBR5f4Yl+a4RXAzL5mF8tVhY8PjrvEDFWRQP5U9onJo=; b=jgV9N0LYGFCOQvdpKwpc7FUzuaIcAdJ4dSBsCFxlYdkn5A7jLDaWZQ9+EC9mIGsvcuZXgP yjCrALwopxAYIm5Upx/qnTf+uriwvmSJqM/FqqN3tmTgmUzBB44e8NqBuD3Uc5R24mtqof KzGkQ7QQguJ+tzI0/I2Vl0yPtICLGoc4FT7wHuK1DuJH5h9noJH0jA9xGGYAli5blw1fva 0TvxbBBjdGLTyL2Y5e44bkkHql+G+l5tOeEqpRuNQupbWWXUn6bub3vOGstFoGOKeIXFDs xZ+buUgrJyVm7ag7BRFluR3Pp3V4wgbb2cyOx1liUVCdHbKNgEFJqMsZE5iLfA== 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 4S94Ct443Lzcr8; Tue, 17 Oct 2023 19:43:38 +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 39HJhc8l013420; Tue, 17 Oct 2023 19:43:38 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 39HJhcPR013417; Tue, 17 Oct 2023 19:43:38 GMT (envelope-from git) Date: Tue, 17 Oct 2023 19:43:38 GMT Message-Id: <202310171943.39HJhcPR013417@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mitchell Horne Subject: git: f3de805ace48 - stable/14 - groupmember(): Extract the supplementary group search in a separate function List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mhorne X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: f3de805ace484db4a3bf9191a150ef4843ae92f3 Auto-Submitted: auto-generated The branch stable/14 has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=f3de805ace484db4a3bf9191a150ef4843ae92f3 commit f3de805ace484db4a3bf9191a150ef4843ae92f3 Author: Olivier Certner AuthorDate: 2023-08-17 23:54:44 +0000 Commit: Mitchell Horne CommitDate: 2023-10-17 19:42:59 +0000 groupmember(): Extract the supplementary group search in a separate function This is in preparation for the introduction of the new realgroupmember() function, which does the same search into supplementary groups as groupmember(). Reviewed by: mhorne MFC after: 2 weeks Sponsored by: Kumacom SAS Differential Revision: https://reviews.freebsd.org/D40640 (cherry picked from commit b725f232f3b09b4bcbc426854fe1545234c66965) --- sys/kern/kern_prot.c | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/sys/kern/kern_prot.c b/sys/kern/kern_prot.c index 648c067dc528..21f5e5d3bc16 100644 --- a/sys/kern/kern_prot.c +++ b/sys/kern/kern_prot.c @@ -1273,36 +1273,43 @@ sys___setugid(struct thread *td, struct __setugid_args *uap) } /* - * Check if gid is a member of the group set. + * Returns whether gid designates a supplementary group in cred. */ -int -groupmember(gid_t gid, struct ucred *cred) +static int +supplementary_group_member(gid_t gid, struct ucred *cred) { - int l; - int h; - int m; - - if (cred->cr_groups[0] == gid) - return(1); + int l, h, m; /* - * If gid was not our primary group, perform a binary search - * of the supplemental groups. This is possible because we - * sort the groups in crsetgroups(). + * Perform a binary search of the supplemental groups. This is possible + * because we sort the groups in crsetgroups(). */ l = 1; h = cred->cr_ngroups; + while (l < h) { - m = l + ((h - l) / 2); + m = l + (h - l) / 2; if (cred->cr_groups[m] < gid) - l = m + 1; + l = m + 1; else - h = m; + h = m; } - if ((l < cred->cr_ngroups) && (cred->cr_groups[l] == gid)) + + return (l < cred->cr_ngroups && cred->cr_groups[l] == gid); +} + +/* + * Check if gid is a member of the (effective) group set (i.e., effective and + * supplementary groups). + */ +int +groupmember(gid_t gid, struct ucred *cred) +{ + + if (cred->cr_groups[0] == gid) return (1); - return (0); + return (supplementary_group_member(gid, cred)); } /*