From nobody Fri Nov 15 10:48:53 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 4XqYfb1q6Fz5cyq5; Fri, 15 Nov 2024 10:48:55 +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 4XqYfY2ymqz4WYL; Fri, 15 Nov 2024 10:48:53 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1731667733; 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=cYmSevj93GMj4G7IIgv3A4r8Za7jx2hPvMA0B/6H+9I=; b=nfyu06wpTBtujkUQ2OXxAzx5b046ldk/uyZvKVJhTRCIhTc94+LfxiH89g03G19LSqShpD 7gV7yOVJbvu2hTA8Dan4DoSt/taYbiwFSYlmcsnqtoO87/YMmii7YG/ZoThQ4qBXac11e1 YlxTEHtnSl2mVW150shffSAPX7QpVKU+48xWnWkUiSRVMxi3rYuphw+82TlZn5igbnUraU M2jUNOZrwTE/akZSyJPnA9kvp3oLbYBxoqVtfAdSEl9KjLh3bXQwgknjxQu0nrBiD5CtwV Dgpkg7RHkNwZU0wWZAlkxzWl2XWCUzjJj2AeYgx7ASpus5uXjLy1TXFikBOXpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1731667733; 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=cYmSevj93GMj4G7IIgv3A4r8Za7jx2hPvMA0B/6H+9I=; b=bz65x04VMxtT2OYD3NvmIv2bEmce3W1dBi3lLdqEDvwBcU2493Dj7xIFH6i+j+9V62EzVA ghaXVARQ3FiA8wD70KbUVLpWN+/MbxjGR7iMVxzIhLu102h2td9TG/DRjD1s3D/hF+3TuR YYx+BggehL3USmQeeltTN/F9TWL9I5Z7fieo9lMAha3l2xjUPAdaIUJ4gLwQKsgw9lNf2f wkUBe3+efKpe1WnNjTyXejeOoqQzFqUqTGGaNTZfOof7lj4YukdBslS7d3yigAG9Pz3rTs tr7YuHS5dZgBqz16U2mpIH/94OWVZZAodo9lv8yLdBKEf8okwsK1wMPyIWTv0Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1731667733; a=rsa-sha256; cv=none; b=FYMQJEuJWsRWIDiTJ94MWiBqv5QIkubViHGw+Gbv+bqtLqiHfa3c2QopeWkOLEjL0mMSv0 R+72saRvO/5PuzrycYg4231SVfNyxivml8p8PtJcxwY7yuPxvvadX1YxQaXeBTw4lS34YY P9yr42b4pDMpaUCaykf0m78g4CgCzBRQcJkNdlPn1RSxBzuQZGCRcWFckAY8Lalp5SuCaA GIgDOeKXXdIk5K1R+obXfdOlQHJAyy6KgotuuUnbhRS4/1X/MD9sEYuJji8Lyc6W5GpJ00 mUHMnCzMFsNPlIl6iPeH2v0658G8oc+goXuDQv5IlqT/v7UjOGbF5u0+KNiONQ== 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 4XqYfY2QF6zKF2; Fri, 15 Nov 2024 10:48:53 +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 4AFAmrPK017730; Fri, 15 Nov 2024 10:48:53 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4AFAmrOo017727; Fri, 15 Nov 2024 10:48:53 GMT (envelope-from git) Date: Fri, 15 Nov 2024 10:48:53 GMT Message-Id: <202411151048.4AFAmrOo017727@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: 97c0b4e0eacd - stable/14 - 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/14 X-Git-Reftype: branch X-Git-Commit: 97c0b4e0eacd8d163795c11ce790259db56af935 Auto-Submitted: auto-generated The branch stable/14 has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=97c0b4e0eacd8d163795c11ce790259db56af935 commit 97c0b4e0eacd8d163795c11ce790259db56af935 Author: Olivier Certner AuthorDate: 2024-07-19 11:23:19 +0000 Commit: Olivier Certner CommitDate: 2024-11-15 10:47:41 +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 be7a71ae6879..ab2adbffa23b 100644 --- a/sys/kern/kern_prot.c +++ b/sys/kern/kern_prot.c @@ -52,6 +52,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); } /*