cb4f466
diff --git a/misc.c b/misc.c
cb4f466
index b8d1040d..0134d694 100644
cb4f466
--- a/misc.c
cb4f466
+++ b/misc.c
cb4f466
@@ -1,4 +1,4 @@
cb4f466
-/* $OpenBSD: misc.c,v 1.169 2021/08/09 23:47:44 djm Exp $ */
cb4f466
+/* $OpenBSD: misc.c,v 1.170 2021/09/26 14:01:03 djm Exp $ */
cb4f466
 /*
cb4f466
  * Copyright (c) 2000 Markus Friedl.  All rights reserved.
cb4f466
  * Copyright (c) 2005-2020 Damien Miller.  All rights reserved.
cb4f466
@@ -56,6 +56,7 @@
cb4f466
 #ifdef HAVE_PATHS_H
cb4f466
 # include <paths.h>
cb4f466
 #include <pwd.h>
cb4f466
+#include <grp.h>
cb4f466
 #endif
cb4f466
 #ifdef SSH_TUN_OPENBSD
cb4f466
 #include <net/if.h>
cb4f466
@@ -2695,6 +2696,12 @@ subprocess(const char *tag, const char *command,
cb4f466
 		}
cb4f466
 		closefrom(STDERR_FILENO + 1);
cb4f466
 
cb4f466
+		if (geteuid() == 0 &&
cb4f466
+		    initgroups(pw->pw_name, pw->pw_gid) == -1) {
cb4f466
+			error("%s: initgroups(%s, %u): %s", tag,
cb4f466
+			    pw->pw_name, (u_int)pw->pw_gid, strerror(errno));
cb4f466
+			_exit(1);
cb4f466
+		}
cb4f466
 		if (setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) == -1) {
cb4f466
 			error("%s: setresgid %u: %s", tag, (u_int)pw->pw_gid,
cb4f466
 			    strerror(errno));