From nobody Tue Sep 23 12:03:38 2025 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 4cWJXq5d8bz68Y9b; Tue, 23 Sep 2025 12:03:39 +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 "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4cWJXq2QpHz3Dl7; Tue, 23 Sep 2025 12:03:39 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1758629019; 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=KuQMJj9Mq/KZ8wozsD8MFUp4NZPNBqa6kaGl7Ojau9w=; b=tc7k4k+EF8UJpLO6/9LtXl+tNyRR02F4h3n/Zpo2szJ+UToyvUQy7aESsiTGLMhf/3h8gF ceOxnGeyX939hqkG1oui+Fu0NZ+WRJTWs9eEN7xJiup6Rbofzu/Ka7/y+4SWtvfXe82iwW 92NsFxSUf6K2b+CqXpyEjSrnW5bzx94k+arOCgDsJCFBZc/R0LzOpG813riKBk3qz/Mb/c 8qUW7oq9LYliyIfWNEv6IUZgy6q0febd99ix5HzyRBLKZvn7R5lBgrUl2G9UHwPehM+XaQ 8QcnYQHO+XaFJ/GjDJJeS86SAiwi8k4ZPBTYuFvc0oUpVvOZ85UzYpbJ/TN1bA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1758629019; 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=KuQMJj9Mq/KZ8wozsD8MFUp4NZPNBqa6kaGl7Ojau9w=; b=v88Z6rEqax4uCIIJo6cROXgHnsMRi7/JstY2uXAOKBv6Trsg1MwRDP+i9AnxkMllwHkcq4 yt1DPYROWu2uJRPRIg/tyfktvvPE8NYLoEOj+sPC83YJwPATreIQ0CU5R7L1Q6kjiG6Rkk AS9hoL4CUqwrfnVz1OKqPTppkuDcXoAXuq5nETWPa+lR6dDQ8of3Vmg02XPIvY1IiVjTkt XY8R4ZR6uUPgpefmVsxbJyEROZFy30BYKjFsVvm4P5mcWkPvIX+dh9VTINBiZbu0ZeG8aH qPgLNfa0t23wlWxAHoqkHtg6PIxB4PvDXa10frd1O1Hlxrrjo+p7vWEvHgRivQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1758629019; a=rsa-sha256; cv=none; b=Un2phaWSMxJi4DIFivMxPcUjf5/LEpqRPhX39LOBy61VlRvt0td6JMy0a2E7sn5GT91YqL j9ycg72jqqCe/G8eDMet88XAFBGyHcxOGEapgqqecO22i6AVAHpoRH5eiMVyiZM5TtEkZh mnQgtIpZg7YAOkA5QBrn4rTk2QsrYDB3noxwWrhubk5ZobdPE/W7Qn37s3PaoHGVCxSUn2 pC4lx5MDTFDk7Xn7lenaUcUnv2Duw1L0h22HjDqyFRYlI53RxqU6MeJnOsa1yJYh5FV88k 2dLZG75mpJwdNmvzgmNQalAktYJdJGoPPHXO8GZyahvLQbUDWuiu68xCqAt0dw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4cWJXq00pXzlqf; Tue, 23 Sep 2025 12:03:39 +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 58NC3ci3008619; Tue, 23 Sep 2025 12:03:38 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 58NC3cXV008616; Tue, 23 Sep 2025 12:03:38 GMT (envelope-from git) Date: Tue, 23 Sep 2025 12:03:38 GMT Message-Id: <202509231203.58NC3cXV008616@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: 8013a7137d3a - stable/15 - linux: Simplify further getgroups() after 'cr_gid' not in cr_groups[] 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/15 X-Git-Reftype: branch X-Git-Commit: 8013a7137d3ac5d6f0f3386fe8531594bcb067be Auto-Submitted: auto-generated The branch stable/15 has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=8013a7137d3ac5d6f0f3386fe8531594bcb067be commit 8013a7137d3ac5d6f0f3386fe8531594bcb067be Author: Olivier Certner AuthorDate: 2025-08-28 15:29:33 +0000 Commit: Olivier Certner CommitDate: 2025-09-23 12:02:44 +0000 linux: Simplify further getgroups() after 'cr_gid' not in cr_groups[] No functional change (intended). While here, fix/improve style a bit and in setgroups(). MFC after: 5 days MFC to: stable/15 Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D52276 (cherry picked from commit a207833f4fed5431cac853c082fa34dc8f33cba6) --- sys/compat/linux/linux_misc.c | 36 ++++++++++++++++-------------------- sys/compat/linux/linux_uid16.c | 36 ++++++++++++++++-------------------- 2 files changed, 32 insertions(+), 40 deletions(-) diff --git a/sys/compat/linux/linux_misc.c b/sys/compat/linux/linux_misc.c index 5e32353c6b8e..755eae057406 100644 --- a/sys/compat/linux/linux_misc.c +++ b/sys/compat/linux/linux_misc.c @@ -1028,18 +1028,19 @@ linux_nice(struct thread *td, struct linux_nice_args *args) int linux_setgroups(struct thread *td, struct linux_setgroups_args *args) { + const int ngrp = args->gidsetsize; struct ucred *newcred, *oldcred; l_gid_t *linux_gidset; - int ngrp, error; + int error; struct proc *p; - ngrp = args->gidsetsize; if (ngrp < 0 || ngrp >= ngroups_max) return (EINVAL); linux_gidset = malloc(ngrp * sizeof(*linux_gidset), M_LINUX, M_WAITOK); error = copyin(args->grouplist, linux_gidset, ngrp * sizeof(l_gid_t)); if (error) goto out; + newcred = crget(); crextend(newcred, ngrp); p = td->td_proc; @@ -1071,34 +1072,29 @@ out: int linux_getgroups(struct thread *td, struct linux_getgroups_args *args) { - struct ucred *cred; + const struct ucred *const cred = td->td_ucred; l_gid_t *linux_gidset; - gid_t *bsd_gidset; - int bsd_gidsetsz, ngrp, error; + int ngrp, error; - cred = td->td_ucred; - bsd_gidset = cred->cr_groups; - bsd_gidsetsz = cred->cr_ngroups; + ngrp = args->gidsetsize; - if ((ngrp = args->gidsetsize) == 0) { - td->td_retval[0] = bsd_gidsetsz; + if (ngrp == 0) { + td->td_retval[0] = cred->cr_ngroups; return (0); } - - if (ngrp < bsd_gidsetsz) + if (ngrp < cred->cr_ngroups) return (EINVAL); - ngrp = 0; - linux_gidset = malloc(bsd_gidsetsz * sizeof(*linux_gidset), - M_LINUX, M_WAITOK); - while (ngrp < bsd_gidsetsz) { - linux_gidset[ngrp] = bsd_gidset[ngrp]; - ngrp++; - } + ngrp = cred->cr_ngroups; + + linux_gidset = malloc(ngrp * sizeof(*linux_gidset), M_LINUX, M_WAITOK); + for (int i = 0; i < ngrp; ++i) + linux_gidset[i] = cred->cr_groups[i]; error = copyout(linux_gidset, args->grouplist, ngrp * sizeof(l_gid_t)); free(linux_gidset, M_LINUX); - if (error) + + if (error != 0) return (error); td->td_retval[0] = ngrp; diff --git a/sys/compat/linux/linux_uid16.c b/sys/compat/linux/linux_uid16.c index 1d9a19916412..07430f5b399b 100644 --- a/sys/compat/linux/linux_uid16.c +++ b/sys/compat/linux/linux_uid16.c @@ -85,12 +85,12 @@ linux_lchown16(struct thread *td, struct linux_lchown16_args *args) int linux_setgroups16(struct thread *td, struct linux_setgroups16_args *args) { + const int ngrp = args->gidsetsize; struct ucred *newcred, *oldcred; l_gid16_t *linux_gidset; - int ngrp, error; + int error; struct proc *p; - ngrp = args->gidsetsize; if (ngrp < 0 || ngrp >= ngroups_max) return (EINVAL); linux_gidset = malloc(ngrp * sizeof(*linux_gidset), M_LINUX, M_WAITOK); @@ -100,6 +100,7 @@ linux_setgroups16(struct thread *td, struct linux_setgroups16_args *args) free(linux_gidset, M_LINUX); return (error); } + newcred = crget(); p = td->td_proc; PROC_LOCK(p); @@ -133,34 +134,29 @@ out: int linux_getgroups16(struct thread *td, struct linux_getgroups16_args *args) { - struct ucred *cred; + const struct ucred *const cred = td->td_ucred; l_gid16_t *linux_gidset; - gid_t *bsd_gidset; - int bsd_gidsetsz, ngrp, error; + int ngrp, error; - cred = td->td_ucred; - bsd_gidset = cred->cr_groups; - bsd_gidsetsz = cred->cr_ngroups; + ngrp = args->gidsetsize; - if ((ngrp = args->gidsetsize) == 0) { - td->td_retval[0] = bsd_gidsetsz; + if (ngrp == 0) { + td->td_retval[0] = cred->cr_ngroups; return (0); } - - if (ngrp < bsd_gidsetsz) + if (ngrp < cred->cr_ngroups) return (EINVAL); - ngrp = 0; - linux_gidset = malloc(bsd_gidsetsz * sizeof(*linux_gidset), - M_LINUX, M_WAITOK); - while (ngrp < bsd_gidsetsz) { - linux_gidset[ngrp] = bsd_gidset[ngrp]; - ngrp++; - } + ngrp = cred->cr_ngroups; + + linux_gidset = malloc(ngrp * sizeof(*linux_gidset), M_LINUX, M_WAITOK); + for (int i = 0; i < ngrp; ++i) + linux_gidset[i] = cred->cr_groups[i]; error = copyout(linux_gidset, args->gidset, ngrp * sizeof(l_gid16_t)); free(linux_gidset, M_LINUX); - if (error) { + + if (error != 0) { LIN_SDT_PROBE1(uid16, linux_getgroups16, copyout_error, error); return (error); }