https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=cc5a6627cbb7639cecd5d87fba1bfb61918b8ed5
commit cc5a6627cbb7639cecd5d87fba1bfb61918b8ed5 Author: Corinna Vinschen <[email protected]> AuthorDate: Fri Dec 5 17:07:08 2025 +0100 Commit: Corinna Vinschen <[email protected]> CommitDate: Mon Dec 22 12:37:23 2025 +0100 Cygwin: uinfo: correctly check and override primary group Commit dc7b67316d01 ("Cygwin: uinfo: prefer token primary group") broke the code overriding the primary group in two different ways: - It changed the way myself->gid was set before checking its value. Prior to dc7b67316d01, myself->gid was always set to the primary group from the passwd entry (pw_gid). With the patch, it was set to the primary group from the Windows user token (token_gid) in the first place. The following condition checking if pw_gid is different from token_gid did so, by checking token_gid against myself->gid, rather than against pw_gid. After dc7b67316d01 this was always false and the code block overriding the primary group in Cygwin and the Windows user token with pw_gid was never called anymore. The solution is obvious: Do not check token_gid against myself->gid, but against the desires primary GID value in pw_gid instead. - The code block overriding the primary group simply assumed that myself->gid was already set to pw_gid, but, as outlined above, this was not true anymore after dc7b67316d01. This is a subtle error, because it leads to having the wrong primary GID in `id' output, while the primary group SID in the user token was correctly set. But as soon as you run this under strace or GDB, the problem disappears, because the second process tree under GDB or strace takes over from the already changed user token. The solution is to override myself->gid with pw_gid once more, after successfully changing the primary GID to pw_gid. Fixes: dc7b67316d01 ("Cygwin: uinfo: prefer token primary group") Addresses: https://cygwin.com/pipermail/cygwin/2025-December/259068.html Signed-off-by: Corinna Vinschen <[email protected]> (cherry picked from commit 877dd793a94c54e651e9f755656add0e529749cf) Diff: --- winsup/cygwin/uinfo.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/winsup/cygwin/uinfo.cc b/winsup/cygwin/uinfo.cc index ffe71ee0726c..8e9b9e07de9d 100644 --- a/winsup/cygwin/uinfo.cc +++ b/winsup/cygwin/uinfo.cc @@ -174,7 +174,7 @@ internal_getlogin (cygheap_user &user) gsid = cygheap->dom.account_sid (); gsid.append (DOMAIN_GROUP_RID_USERS); if (!pgrp - || (myself->gid != pgrp->gr_gid + || (pwd->pw_gid != pgrp->gr_gid && cygheap->dom.account_sid () != cygheap->dom.primary_sid () && RtlEqualSid (gsid, user.groups.pgsid))) { @@ -209,7 +209,10 @@ internal_getlogin (cygheap_user &user) myself->gid = pwd->pw_gid = pgrp->gr_gid; } else - user.groups.pgsid = gsid; + { + user.groups.pgsid = gsid; + myself->gid = pwd->pw_gid; + } clear_procimptoken (); } }
