Hi Samuel
Please see the attached patches. I am not entirely sure how 
detailed/descriptive the commit messages should be. Feel free to adjust as you 
see fit.
Thanks a lot,
Y.
Sep 30, 2026, 15:07 by [email protected]:

>
>
>> Do you want the MACH_MSG_TYPE_COPY_SEND and signature change as separate 
>> patches?
>>
>
> Yes, please.
>
>
>> Do you want separate patches for seteuids and setgroups (the change and 
>> reason is basically identical)
>>
>
> Better keep them together in one patch.
>
>> Is there something else I need to consider for patches to glibc?
>>
>
> Nothing really particular. Since it's completely specific to the Hurd
> port, we don't have constraints.
>
> Thanks,
> Samuel
>

>From 074bee3786445aa7207d800ba0d74fa79c34627f Mon Sep 17 00:00:00 2001
From: Yelninei <[email protected]>
Date: Fri, 9 Oct 2026 17:48:26 +0000
Subject: [PATCH 1/3] hurd: seteuids: Specify MACH_MSG_TYPE_COPY_SEND.

This prevents a EMIG_BAD_ARGUMENTS error.
---
 hurd/seteuids.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hurd/seteuids.c b/hurd/seteuids.c
index 0a1e533bb3..f446847189 100644
--- a/hurd/seteuids.c
+++ b/hurd/seteuids.c
@@ -39,8 +39,8 @@ retry:
     {
       /* Get a new auth port using those IDs.  */
       err = __USEPORT (AUTH,
-		       __auth_makeauth (port, NULL, 0, 0,
 					new, n,
+		       __auth_makeauth (port, NULL, MACH_MSG_TYPE_COPY_SEND, 0,
 					_hurd_id.aux.uids, _hurd_id.aux.nuids,
 					_hurd_id.gen.gids, _hurd_id.gen.ngids,
 					_hurd_id.aux.gids, _hurd_id.aux.ngids,
-- 
2.54.0

>From 82e8427863c53b498bb213910edf4a126acb4fec Mon Sep 17 00:00:00 2001
From: Yelninei <[email protected]>
Date: Fri, 9 Oct 2026 17:48:33 +0000
Subject: [PATCH 2/3] hurd: seteuids: Change size argument to size_t.

setuids is analogous to setgroups so make it match signatures.
---
 hurd/hurd.h     | 2 +-
 hurd/seteuids.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/hurd/hurd.h b/hurd/hurd.h
index 05674a93bb..3f1865c57b 100644
--- a/hurd/hurd.h
+++ b/hurd/hurd.h
@@ -177,7 +177,7 @@ extern int _hurd_change_directory_port_from_fd (struct hurd_port *portcell,
 
 /* Get and set the effective UID set.  */
 extern int geteuids (int __n, uid_t *__uidset);
-extern int seteuids (int __n, const uid_t *__uidset);
+extern int seteuids (size_t __n, const uid_t *__uidset);
 
 
 /* Split FILE into a directory and a name within the directory.  The
diff --git a/hurd/seteuids.c b/hurd/seteuids.c
index f446847189..ea60021d63 100644
--- a/hurd/seteuids.c
+++ b/hurd/seteuids.c
@@ -20,7 +20,7 @@
 
 /* Set the uid set for the current user to UIDS (N of them).  */
 int
-seteuids (int n, const uid_t *uids)
+seteuids (size_t n, const uid_t *uids)
 {
   error_t err;
   auth_t newauth;
-- 
2.54.0

>From d29e26e5795a028882a18025f1cddd5623107dcd Mon Sep 17 00:00:00 2001
From: Yelninei <[email protected]>
Date: Fri, 9 Oct 2026 17:48:38 +0000
Subject: [PATCH 3/3] hurd: Preserve the euid/egid in seteuids/setgroups.

By convention the first uid/gid is the euid/egid. Ensure that the
first uid/gid in the array passed to auth_makeauth is the egid/egid to
not unexpectedly overwrite it.
---
 hurd/seteuids.c               | 17 +++++++++++++----
 sysdeps/mach/hurd/setgroups.c | 17 +++++++++++++----
 2 files changed, 26 insertions(+), 8 deletions(-)

diff --git a/hurd/seteuids.c b/hurd/seteuids.c
index ea60021d63..8c4f5f2c20 100644
--- a/hurd/seteuids.c
+++ b/hurd/seteuids.c
@@ -15,6 +15,7 @@
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
+#include <unistd.h>
 #include <hurd.h>
 #include <hurd/id.h>
 
@@ -24,12 +25,20 @@ seteuids (size_t n, const uid_t *uids)
 {
   error_t err;
   auth_t newauth;
-  int i;
-  gid_t new[n];
+  size_t i, start;
+  uid_t euid;
+  uid_t new[n + 1];
 
+  start = 0;
+  euid = geteuid ();
+  if (euid != (uid_t) -1 && (n == 0 || (n > 0 && euid != uids[0])))
+    {
+      new[0] = euid;
+      start = 1;
+    }
   /* Fault before taking locks.  */
   for (i = 0; i < n; ++i)
-    new[i] = uids[i];
+    new[i + start] = uids[i];
 
 retry:
   HURD_CRITICAL_BEGIN;
@@ -39,8 +48,8 @@ retry:
     {
       /* Get a new auth port using those IDs.  */
       err = __USEPORT (AUTH,
-					new, n,
 		       __auth_makeauth (port, NULL, MACH_MSG_TYPE_COPY_SEND, 0,
+					new, n + start,
 					_hurd_id.aux.uids, _hurd_id.aux.nuids,
 					_hurd_id.gen.gids, _hurd_id.gen.ngids,
 					_hurd_id.aux.gids, _hurd_id.aux.ngids,
diff --git a/sysdeps/mach/hurd/setgroups.c b/sysdeps/mach/hurd/setgroups.c
index 5d71d89011..ddfed7cac5 100644
--- a/sysdeps/mach/hurd/setgroups.c
+++ b/sysdeps/mach/hurd/setgroups.c
@@ -17,6 +17,7 @@
 
 #include <errno.h>
 #include <sys/types.h>
+#include <unistd.h>
 #include <grp.h>
 #include <hurd.h>
 #include <hurd/id.h>
@@ -27,12 +28,20 @@ setgroups (size_t n, const gid_t *groups)
 {
   error_t err;
   auth_t newauth;
-  size_t i;
-  gid_t new[n];
+  size_t i, start;
+  gid_t egid;
+  gid_t new[n + 1];
 
+  start = 0;
+  egid = getegid ();
+  if (egid != (gid_t) -1 && (n == 0 || (n > 0 && egid != groups[0])))
+    {
+      new[0] = egid;
+      start = 1;
+    }
   /* Fault before taking locks.  */
   for (i = 0; i < n; ++i)
-    new[i] = groups[i];
+    new[i + start] = groups[i];
 
 retry:
   HURD_CRITICAL_BEGIN;
@@ -45,7 +54,7 @@ retry:
 		       __auth_makeauth (port, NULL, MACH_MSG_TYPE_COPY_SEND, 0,
 					_hurd_id.gen.uids, _hurd_id.gen.nuids,
 					_hurd_id.aux.uids, _hurd_id.aux.nuids,
-					new, n,
+					new, n + start,
 					_hurd_id.aux.gids, _hurd_id.aux.ngids,
 					&newauth));
     }
-- 
2.54.0

Reply via email to