aboutsummaryrefslogtreecommitdiff
path: root/crypto
diff options
context:
space:
mode:
authorEd Maste <emaste@FreeBSD.org>2021-10-09 01:28:53 +0000
committerEd Maste <emaste@FreeBSD.org>2021-10-09 01:29:25 +0000
commit172fa4aa7577915bf5ace5783251821d3774dc05 (patch)
treef365886c0952fa82b66951f28cf764ece4d6049c /crypto
parent1c64959bff1772da4c9cc7d86c56f3729189b88e (diff)
downloadsrc-172fa4aa7577915bf5ace5783251821d3774dc05.tar.gz
src-172fa4aa7577915bf5ace5783251821d3774dc05.zip
OpenSSH: cherry-pick "need initgroups() before setresgid()"
From openssh-portable commits f3cbe43e28fe and bf944e3794ef.
Diffstat (limited to 'crypto')
-rw-r--r--crypto/openssh/misc.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/crypto/openssh/misc.c b/crypto/openssh/misc.c
index b8d1040d1e3c..0134d69492e4 100644
--- a/crypto/openssh/misc.c
+++ b/crypto/openssh/misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.c,v 1.169 2021/08/09 23:47:44 djm Exp $ */
+/* $OpenBSD: misc.c,v 1.170 2021/09/26 14:01:03 djm Exp $ */
/*
* Copyright (c) 2000 Markus Friedl. All rights reserved.
* Copyright (c) 2005-2020 Damien Miller. All rights reserved.
@@ -56,6 +56,7 @@
#ifdef HAVE_PATHS_H
# include <paths.h>
#include <pwd.h>
+#include <grp.h>
#endif
#ifdef SSH_TUN_OPENBSD
#include <net/if.h>
@@ -2695,6 +2696,12 @@ subprocess(const char *tag, const char *command,
}
closefrom(STDERR_FILENO + 1);
+ if (geteuid() == 0 &&
+ initgroups(pw->pw_name, pw->pw_gid) == -1) {
+ error("%s: initgroups(%s, %u): %s", tag,
+ pw->pw_name, (u_int)pw->pw_gid, strerror(errno));
+ _exit(1);
+ }
if (setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) == -1) {
error("%s: setresgid %u: %s", tag, (u_int)pw->pw_gid,
strerror(errno));