git: 5e6d12734846 - stable/12 - OpenSSH: cherry-pick "need initgroups() before setresgid()"
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 12 Oct 2021 16:32:04 UTC
The branch stable/12 has been updated by emaste:
URL: https://cgit.FreeBSD.org/src/commit/?id=5e6d12734846ae20bd31ec514d3a56672202f1b4
commit 5e6d12734846ae20bd31ec514d3a56672202f1b4
Author: Ed Maste <emaste@FreeBSD.org>
AuthorDate: 2021-10-12 00:47:39 +0000
Commit: Ed Maste <emaste@FreeBSD.org>
CommitDate: 2021-10-12 16:31:49 +0000
OpenSSH: cherry-pick "need initgroups() before setresgid()"
From openssh-portable commits f3cbe43e28fe and bf944e3794ef, backported
to OpenSSH 7.9p1 on stable/13 [and stable/12].
Reviewed by: delphij
Security: CVE-2021-41617
Differential Revision: https://reviews.freebsd.org/D32460
(cherry picked from commit 172fa4aa7577915bf5ace5783251821d3774dc05)
(cherry picked from commit be74669a2f62915f84b844bb00dd2767c60539fe)
---
crypto/openssh/auth.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/crypto/openssh/auth.c b/crypto/openssh/auth.c
index a2e1fa10ce45..65183d456490 100644
--- a/crypto/openssh/auth.c
+++ b/crypto/openssh/auth.c
@@ -39,6 +39,7 @@ __RCSID("$FreeBSD$");
# include <paths.h>
#endif
#include <pwd.h>
+#include <grp.h>
#ifdef HAVE_LOGIN_H
#include <login.h>
#endif
@@ -983,6 +984,13 @@ subprocess(const char *tag, struct passwd *pw, 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);
+ }
+
/* Don't use permanently_set_uid() here to avoid fatal() */
if (setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) != 0) {
error("%s: setresgid %u: %s", tag, (u_int)pw->pw_gid,