From nobody Fri Nov 15 13:00:51 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 4XqcZq5mP6z5d6mV; Fri, 15 Nov 2024 13:00:51 +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 4XqcZq2dsTz4pSR; Fri, 15 Nov 2024 13:00:51 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1731675651; 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=qAHzXa5vkQ2TsYqhFfsk14UDFTP28UUrwv8SfS6yi8c=; b=r0Hmn1J460Nb35AR7yhYA1YyuLnBeZvJ8DEf+wP93SOqNLRXut3LqjFzpzFdQ8419M44SH sPnmC27Q3ouTYN7sbfk00it5RcdVFASovf848tXuxKV7Yi/NmaCEMie1H9d1HOYXknIAId TCare4Lfb+n/nfjVyTiamNe4pUN01HCRgzeW6m+fHSArD1Q2bu3ODETpvpDvgOJrGfdQEP v3cXauteQ+Czb7cBfvA559xqASmBuIbXvrbni0g9KU/Dz6S0JvwFXP2eYqyrGSL/asNMzP YRlPEe3zCYq5Lus/rdOXTDVebPP5nMEJC52MTSBatZh6IvvsPjQrzkHVGKccJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1731675651; 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=qAHzXa5vkQ2TsYqhFfsk14UDFTP28UUrwv8SfS6yi8c=; b=uocGzC9fD9XvSYqChnZRdf1EJUZNTeOFvPykLeobixbNR/3ryMrqaZDb0ss5dEGkEeWqqD u96vOF9HZIXx6RjojqYx2PxAfp33cxWA30PGcz+Dszxk6ZvcX5G2yFJIH6TkIvqv2RVr5e 66TkvS7XDfDl0WcOcQMLNKHi+/H/2Hdt6EahGeBCv6npIQBZwnKvFLH9wwvfLur2VqWxlc jRV/yOQQdICPp3LGIaW1CbeN+6iOx7ixDyh+4vZ2F2ciMq3fdy/8M6An78Vti59SBh4IR2 eiANOHRT309Smfel1ma3CcD3JMuDsbJ2bjAH4197K5AFb6AONW0GDfmdeg6nkQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1731675651; a=rsa-sha256; cv=none; b=Nm8Fy70VQBYhWi8kvW4fNJ7zUQKGmbnF6Pr3NkqJJG1G06wG+f8BhMphuUwKaxkZx5pmJ9 TUYfrQmE8zCYXvjXYbvjE1/pnq2YXkAy+fNhCQ/1fyISXCUxQRxeT8EQ0s1j7iv8yyGSVd RCQqc7gM87d3PQuRhTfwgoACpjEp2L55SxPHJl1ymVDWHB7DMgowsEVysDyK26O+D9jYPO SbEERzBA7jAKLQdZgLl0DH3oEhQu5m3B+MZvpsd3cVRjVVx9dPF15P39ajpkvM+e/R2HsP zUOCl36gP2ATUOmk+8Sz27Uh0tc5eoBA2mQ7vw/JqSoFJZwCowDzaKSXNr9qIA== 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 4XqcZq231pzNnV; Fri, 15 Nov 2024 13:00:51 +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 4AFD0pWe071241; Fri, 15 Nov 2024 13:00:51 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4AFD0pZq071238; Fri, 15 Nov 2024 13:00:51 GMT (envelope-from git) Date: Fri, 15 Nov 2024 13:00:51 GMT Message-Id: <202411151300.4AFD0pZq071238@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: 5e24f53a2d5d - stable/13 - cred: groupmember() and co.: Sanity check cred's groups (INVARIANTS) 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: 5e24f53a2d5d3dc7d695ba0a037c1ba66ec75ba9 Auto-Submitted: auto-generated The branch stable/13 has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=5e24f53a2d5d3dc7d695ba0a037c1ba66ec75ba9 commit 5e24f53a2d5d3dc7d695ba0a037c1ba66ec75ba9 Author: Olivier Certner AuthorDate: 2024-11-01 15:11:23 +0000 Commit: Olivier Certner CommitDate: 2024-11-15 12:59:09 +0000 cred: groupmember() and co.: Sanity check cred's groups (INVARIANTS) Leverage the normalization check functions introduced in the previous commit in all public-facing groups search functions to catch programming errors early. Approved by: markj (mentor) MFC after: 3 days (cherry picked from commit 634675067867090e538b08e62ff9b14d3ffae5a3) Approved by: markj (mentor) --- sys/kern/kern_prot.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/sys/kern/kern_prot.c b/sys/kern/kern_prot.c index 6cdfea2774c0..ede79f7d6bd2 100644 --- a/sys/kern/kern_prot.c +++ b/sys/kern/kern_prot.c @@ -1354,6 +1354,8 @@ int group_is_supplementary(const gid_t gid, const struct ucred *const cred) { + groups_check_normalized(cred->cr_ngroups, cred->cr_groups); + /* * Perform a binary search of the supplementary groups. This is * possible because we sort the groups in crsetgroups(). @@ -1377,7 +1379,9 @@ groupmember(gid_t gid, const struct ucred *cred) if (cred->cr_ngroups == 0) return (0); - if (cred->cr_groups[0] == gid) + groups_check_positive_len(cred->cr_ngroups); + + if (gid == cred->cr_groups[0]) return (1); return (group_is_supplementary(gid, cred)); @@ -1390,6 +1394,14 @@ groupmember(gid_t gid, const struct ucred *cred) int realgroupmember(gid_t gid, const struct ucred *cred) { + /* + * Although the equality test on 'cr_rgid' below doesn't access + * 'cr_groups', we check for the latter's length here as we assume that, + * if 'cr_ngroups' is 0, the passed 'struct ucred' is invalid, and + * 'cr_rgid' may not have been filled. + */ + groups_check_positive_len(cred->cr_ngroups); + if (gid == cred->cr_rgid) return (1);