From nobody Fri Nov 15 13:00:44 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 4XqcZj0CFmz5d6ws; Fri, 15 Nov 2024 13:00:45 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XqcZh5T0Xz4pGs; Fri, 15 Nov 2024 13:00:44 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1731675644; 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=Lh+OQWWjhOAu2jnKsV/yp6WfqGFHpVkN485dpD44Sz8=; b=PT7TzuEIP5wW8fgmhRMki1YCKi/k9+hOoA0SrB1lhVBbyGlSQtbWssS0Xyr0HjHI34IRJp C3CQ0mxnrw4RoqfmNoq0x/NVnWopLk4K54c3i2Q/tFB+peHQ68hduvUGr9/cZ5/4DMvZTU ODRu5rMV6WAl9cpBjabuQvhgUElKYGRkVH3RfzHIit5HaCQ0tVu8Ys/m4Mv897wdVSJO9i H9XwbjJ4yv9mLXEjHheQz5pQIQ5oR8Gr64horyZ0KXJjduPWUKltIJjfAf3lIU94D9B7Qp QD8zOH7P+jxOQoBBYUlCdcuwGKzGt5/2fXXOvl0KzyR64gKxB7+GZ3sos42bOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1731675644; 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=Lh+OQWWjhOAu2jnKsV/yp6WfqGFHpVkN485dpD44Sz8=; b=ePYOlSQjtViH7fVefN5Ko799Vkm4h5FG8j5NalmQQBwSGyxbp8h8LDWARepdTXhTidrVSq nWQJuYF5Z7VD1BYRa51dEXrWSYCZKRKqi5AFG4NuLlrcpsa8wfeY3ckMwKcSDQuBWRSTP3 Atm8W6xi3AvM6lsUusLbrCrsA8Lay5SxHHRZKDLOuVpl0EGs2PmPtUjR278i7k+TQpPE5Q BMmXlLHK3l3M5zgf+B6JETBiWVIULThiNCNnxY2TsUdFzGGmd+NNUx8xF05ijTh0QdasCM T1GOrl++/ooFhjU7o5tRxj9d0azOdAvOx3H/uJnFuau0w7JSiusLBQxPbRNawA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1731675644; a=rsa-sha256; cv=none; b=UsXZbd4TyZxsQtdxw1ElSSloruEgk0jrc47j0swhKVffOv7x6mfqRD5WuyMPYHvX6DAYXR tKFUgcq7ka1p5v04mmBX88wBSaGgKjwlyk+gofJzPkQTOleqxknoCvpmwluIw8UPbnpN7b 9RVMgEh0AoLFKGzprRaw+EYpJRhHwUi18FJZTwFoWx81z75q5TIjnPPwGbzi6nFPavaKkH nnw4aTsZVNNOaGtJm62dL95LBN7r3h2DWHnWfhi1JyX4Sxsc+umRCPUc/5cDBV7HnDutn2 wK82e4xpj/nqtmvJ67HneHA73qPH0KuQSUtuTHze/XzyHlNga7Bje4r2r2ey8w== 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 4XqcZh4ZC8zN8s; Fri, 15 Nov 2024 13:00:44 +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 4AFD0iI3069837; Fri, 15 Nov 2024 13:00:44 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4AFD0iR5069834; Fri, 15 Nov 2024 13:00:44 GMT (envelope-from git) Date: Fri, 15 Nov 2024 13:00:44 GMT Message-Id: <202411151300.4AFD0iR5069834@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Olivier Certner Subject: git: 0c835785ebe4 - stable/13 - cred: group_is_supplementary(): Use bsearch() 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: olce X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 0c835785ebe48f6033d8f0007b00b659d4dd3a22 Auto-Submitted: auto-generated The branch stable/13 has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=0c835785ebe48f6033d8f0007b00b659d4dd3a22 commit 0c835785ebe48f6033d8f0007b00b659d4dd3a22 Author: Olivier Certner AuthorDate: 2024-07-19 11:23:19 +0000 Commit: Olivier Certner CommitDate: 2024-11-15 12:59:07 +0000 cred: group_is_supplementary(): Use bsearch() This makes that function use a more efficient version of binary search instead, and removes one more hand-rolled binary search code from the tree (and the kernel binary). Reviewed by: mhorne, emaste Approved by: markj (mentor) MFC after: 3 days Differential Revision: https://reviews.freebsd.org/D46907 (cherry picked from commit 372605478c6fe2c628f25428af201f866d7eb015) Approved by: markj (mentor) --- sys/kern/kern_prot.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/sys/kern/kern_prot.c b/sys/kern/kern_prot.c index 0ec3df305048..eb4910e1591a 100644 --- a/sys/kern/kern_prot.c +++ b/sys/kern/kern_prot.c @@ -52,6 +52,7 @@ #include #include #include +#include #include #include #include @@ -828,6 +829,15 @@ sys_setgroups(struct thread *td, struct setgroups_args *uap) return (error); } +static int +gidp_cmp(const void *p1, const void *p2) +{ + const gid_t g1 = *(const gid_t *)p1; + const gid_t g2 = *(const gid_t *)p2; + + return ((g1 > g2) - (g1 < g2)); +} + int kern_setgroups(struct thread *td, u_int ngrp, gid_t *groups) { @@ -1278,24 +1288,13 @@ sys___setugid(struct thread *td, struct __setugid_args *uap) static int group_is_supplementary(const gid_t gid, const struct ucred *const cred) { - int l, h, m; /* * Perform a binary search of the supplementary 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; - if (cred->cr_groups[m] < gid) - l = m + 1; - else - h = m; - } - - return (l < cred->cr_ngroups && cred->cr_groups[l] == gid); + return (bsearch(&gid, cred->cr_groups + 1, cred->cr_ngroups - 1, + sizeof(gid), gidp_cmp) != NULL); } /*