From nobody Sat Nov 02 20:39:27 2024 X-Original-To: dev-commits-src-main@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 4XgqMz4Xvrz5chDT; Sat, 02 Nov 2024 20:39:27 +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 4XgqMz293Vz449f; Sat, 2 Nov 2024 20:39:27 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730579967; 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=bBozr4ElGQJjQfRZYRm75CWPOoImM3NnRcCu8MaCLQw=; b=YbNYpKsdUaRN9yRFIJdhRNstg+bzeD6lCY1yjW2Y/d6tHvxM5Wuu76VrDlnaAgMvFHNRma r0Tb+rHgnMkih3TJ784lgOlIJ8L0qStrSIh5oLYjHDPSoUQRbEbyXcS4CAu8jcU6tOIAiR GsWarm/Vs/WFBlAZL3x7weGTYfewbQSwWOB/4n88mynVbi9dH2nhFoNa8y/t+ZTgYBsNSa oLb2ctCgb4mYeTWnirM8dJn5fAIWB/GScu+VegAHn+zJCYM/DMqPvw2FgPe1RgaOldHz9L 6IA2dAcve3/7mxDV+8GHci2Ck+JOZoj6a7A6gGm8UK3BnXWxyO2P4cUfLH3jHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730579967; 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=bBozr4ElGQJjQfRZYRm75CWPOoImM3NnRcCu8MaCLQw=; b=Stm6pC4mXBipfyFdKe7eAo2Dw0sgyYVd2fUkg30cbh8n/AgY+HK9nb4o8LRGoTsLLv837X wL0T/U124olnIZvqhIvJtovCCgg+0khsrc85MpbzXqXxlOGzsVCs7KV6he1I6Z3DXeYHPT P8fOsf00b4PBlPtDeEsdAuAy+Arz72OrYJe5iA1uaSIBdh367j5II8O0NvMwcPAr/ZybDu cIM+TWmmNB6XKr9tFShIYw+DlUXne72aFw3cuMMq8oAt0w2OF25nR/9z/nL8Hp4SXr8btO wQP6dDDH1R1G0cQ8DF2EOocH/r+qa966TqimXNap/9L7g3PGf3T879+0I1lZ5Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1730579967; a=rsa-sha256; cv=none; b=AcHIFh1pWG3mx1tj8zPNr1hMWl2GlN6+kMGFgV6s2zxKMiXvEMZem/2U6DzkyW8wOkP2Ee cOB6axh4xVzzOXDwtg0IKYtw/vfNkneyW9+IUFh8fTrMYWwT2AoYZrH7Zub52oUHK3ILYK KrQdwvLj7N6Mr+8qQ2mJ4zSID4deYkpI3GtAc3fmntYUke9roGglANOsf8jiX3US1FfiAR i1zY6kzUgAsDyvrVq3Lbqs4gETsybGjmtbEP6e6Pw+ePoTCCd+JDQsu+s5xDs7E0r4R8Mo BSZQSRINuLtd0Nb4GZNr4EYnL0Lv5o103fTKkYQRJfPZwi2C3grjLn1aJtLfFA== 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 4XgqMz1n5zzKYG; Sat, 2 Nov 2024 20:39:27 +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 4A2KdRJA046109; Sat, 2 Nov 2024 20:39:27 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4A2KdRBI046106; Sat, 2 Nov 2024 20:39:27 GMT (envelope-from git) Date: Sat, 2 Nov 2024 20:39:27 GMT Message-Id: <202411022039.4A2KdRBI046106@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Olivier Certner Subject: git: 372605478c6f - main - cred: group_is_supplementary(): Use bsearch() List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: 372605478c6fe2c628f25428af201f866d7eb015 Auto-Submitted: auto-generated The branch main has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=372605478c6fe2c628f25428af201f866d7eb015 commit 372605478c6fe2c628f25428af201f866d7eb015 Author: Olivier Certner AuthorDate: 2024-07-19 11:23:19 +0000 Commit: Olivier Certner CommitDate: 2024-11-02 20:37:40 +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 --- 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 b2511ce1e6c8..5ba5afc52915 100644 --- a/sys/kern/kern_prot.c +++ b/sys/kern/kern_prot.c @@ -50,6 +50,7 @@ #include #include #include +#include #include #include #include @@ -832,6 +833,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) { @@ -1282,24 +1292,13 @@ sys___setugid(struct thread *td, struct __setugid_args *uap) static bool 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); } /*