From nobody Sat Nov 02 20:39:33 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 4XgqN62mYfz5ch96; Sat, 02 Nov 2024 20:39:34 +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 4XgqN60vbCz44MH; Sat, 2 Nov 2024 20:39:34 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730579974; 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=0TQ7ty7VgrLBmC2yPMryAxuSDGfoD4TDDMgyPT+JvLI=; b=QXq+2IpGSPW3M2EPXsXjvHilhzZYCb91lAHtSd1jQHIx8/CpbGQg+mmJrCMgJIUU5yhvoC I+RT/NwLVXc6nBGD7Vx8utKwQtcJ5C+phAioer/B15t7BTMyV/EvUlrF22WXnFEZwvcB0v VMfmR+ulleVmyIO5B/U86qPPMy6FQer3noiCqFym/fC8umz0NOZ835FT1008tGj7ydRual cBllta2+Wo/Wj5vbwpkFcz5R164K6MtSHslK3Eayoxp8DUghY+i6y81wZeKEH/tchlnCMU i9OZzPcLDnkPij2EzlTe/Pm7a/2PhDPu/TG73+a3844MiaCN5X9VJXz38EBbYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730579974; 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=0TQ7ty7VgrLBmC2yPMryAxuSDGfoD4TDDMgyPT+JvLI=; b=LcR3kJVtPItdaz5wbIOadOTa355Oh1wfFeGmcDsFCgMnyXq+Z9geuDhIO7WZ0E4R98pTy/ 6ledKNyKGvFZpP42xcNJ+KhBqWQW1VYe30aiIf99O/HtFjeejOXcFaedLihn6X4QNuoHW9 rgoqN5rgM/AFeQiI19rMsqRWiXSKbIl6awMAyyUaaSPHkntDvDF/glW4Yq35QMMVoW2LsJ uubMVz4cyKTiHcbVJrITXCUbvpC4REYZaWmD0Zme0V72KeEvlMiF9eP1xTELw0MkIzjIYE tWoBO4WLK+6wOPBzuY/9RaX7f8qjnjPtK5zQDKNehTJeNDEQ/wC49c4jT8nvbg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1730579974; a=rsa-sha256; cv=none; b=qLscTySl3H33KSYXYpO6reaOCPzE3dai04QuEXrtKljUr+gNCeax58MB6auFyVfJDSBBvl tRzajWlnfV1ip4z8L0R5cLUuZ8qXxXcF0IhrrhgkXi9Ue2UbbHzfq87AvsvwwNnFpSNf8J mZ6USg/lDyANaQlC5Bq7tV4/uFIaX/qq+d/rCM3GBRDOcL2yrr8AgsWeb5lpXdLKvtCib/ TGZteakW/x/2AxNloKi0L/qsw/AZpQ0pjntTAUqOUq7I3NgzpxFqISu6L25UANKEF4S0gy FYKf9isbjFBGfXCOdHI13mYZP8vdV/3UIqmjQWqYvAHfdgIbWXvKl5Uf828Hhg== 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 4XgqN60SZHzKQp; Sat, 2 Nov 2024 20:39:34 +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 4A2KdX4Z046442; Sat, 2 Nov 2024 20:39:33 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4A2KdXmt046439; Sat, 2 Nov 2024 20:39:33 GMT (envelope-from git) Date: Sat, 2 Nov 2024 20:39:33 GMT Message-Id: <202411022039.4A2KdXmt046439@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: 634675067867 - main - 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/main X-Git-Reftype: branch X-Git-Commit: 634675067867090e538b08e62ff9b14d3ffae5a3 Auto-Submitted: auto-generated The branch main has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=634675067867090e538b08e62ff9b14d3ffae5a3 commit 634675067867090e538b08e62ff9b14d3ffae5a3 Author: Olivier Certner AuthorDate: 2024-11-01 15:11:23 +0000 Commit: Olivier Certner CommitDate: 2024-11-02 20:37: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 --- 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 d87d008e0bc2..a1dd3e934c35 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);