From nobody Fri Nov 15 10:49:00 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 4XqYfh65q9z5d07H; Fri, 15 Nov 2024 10:49:00 +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 4XqYfh2g2kz4Wyf; Fri, 15 Nov 2024 10:49:00 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1731667740; 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=ADJM8QDmTx/YG0QEUn6wis41hN8MfW9pVtT9dqWxuK8=; b=P4FbzKe/wNQXVKryL9/TjnGGKz9SBZAXfIWeCE8iDl7av3jQbEayQ7Glj7BjzaBDVg2SI+ 4/Qz3PuSpkeotcbAo+FaO6qDT5yOzckK7eU66wEWJizAjkwCt4PTxAIkwYqDsUrMkiaYZv FUB73Kg5FIqLblBomRBsjCX5SCccLx9lfTjjodb/l7MswoA6FIhdZe+wvMWIzehX3u861/ 3KvRK+ev6CUt5td89tustmmDjzZujEn0gzZ7uf5qR6xRM9aGycsAbfW52rhkYPOPJIyoJ0 VRiEkmo0tBicsavWhKOxm+eKNkcScfhdG9EBTwn8ZCBjPJTIZ95pcerXT4yprg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1731667740; 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=ADJM8QDmTx/YG0QEUn6wis41hN8MfW9pVtT9dqWxuK8=; b=HW7IEv5a/uOC8kJUojRf4/8yjTnK/4eJZHZieo2Pa4A5yc+sRGlQH5YaEv5SsYR8wbBKRe 7i64cH69Y8Lq6iLT1isu2IaTNAY2XmCWs0107ak2uI21l6nlrTX1r6837alF4uNQTOPB4A z4uGHhUhG0mczZbgrD0tXcD6GvR4uCY3Ueg0e88IR9k/1prE/uYY0m3uV3FjOrxeKMrVDV eat2p5FsNQOHfvrgA1NrwROQ4P+tjM7iC1F/Gq9KJ9SA4bBdlql6od7ataBcewpH1IOHnr ks3wCh+mUYiEgPeD0+NcUKn/xDZOW18ZFp0NEfMGANlkr7BNsCdWIGgSkthfmQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1731667740; a=rsa-sha256; cv=none; b=CZCYOhaTh7UBEkiDFkOkDyU6Fzo4VdOO6TlrYCJwOXvEA9BkGcsBZrvyrmDx+5ppJvgtN3 1prhtGwmPgCu2WFMZZo7clur5hm6RdHQXKbKcjCMfSj4QGXTI8dbR87SFR1Yx7Nqm64cH5 y1FSqzvgmI4dZLK/5Yg8wzDWiFfNA8tlR9/ZSP0Y/EqpHzeOYwZj4VL4UST/wz6UvorNOq 3UJ48TjYtVmfLzyzaMyNpnLgDHLW/cqTIieMI7U6Yr6xGXzKDjMVnTNK1UgTK10eKDehtM BMlhHkb4tLJb1Hh/c3KIleaQ/N0TMbao7BLo3uYG9bCXZxmHA8dF8jn/ImriaA== 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 4XqYfh15SyzKQs; Fri, 15 Nov 2024 10:49:00 +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 4AFAn0lu018075; Fri, 15 Nov 2024 10:49:00 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4AFAn0lJ018072; Fri, 15 Nov 2024 10:49:00 GMT (envelope-from git) Date: Fri, 15 Nov 2024 10:49:00 GMT Message-Id: <202411151049.4AFAn0lJ018072@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: 9deb689a752d - stable/14 - 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/14 X-Git-Reftype: branch X-Git-Commit: 9deb689a752ddb6398ea39f06b5ec35756450694 Auto-Submitted: auto-generated The branch stable/14 has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=9deb689a752ddb6398ea39f06b5ec35756450694 commit 9deb689a752ddb6398ea39f06b5ec35756450694 Author: Olivier Certner AuthorDate: 2024-11-01 15:11:23 +0000 Commit: Olivier Certner CommitDate: 2024-11-15 10:47:42 +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 | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/sys/kern/kern_prot.c b/sys/kern/kern_prot.c index f3d8f2a235d5..d6dd71599d86 100644 --- a/sys/kern/kern_prot.c +++ b/sys/kern/kern_prot.c @@ -1358,6 +1358,8 @@ bool 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(). @@ -1381,6 +1383,8 @@ groupmember(gid_t gid, const struct ucred *cred) if (cred->cr_ngroups == 0) return (false); + groups_check_positive_len(cred->cr_ngroups); + if (gid == cred->cr_groups[0]) return (true); @@ -1394,6 +1398,14 @@ groupmember(gid_t gid, const struct ucred *cred) bool 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 (true);