From nobody Tue Oct 12 15:39:11 2021 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 6E79617F3744; Tue, 12 Oct 2021 15:39:11 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4HTKb32Ymbz3qQx; Tue, 12 Oct 2021 15:39:11 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 388BE16CD5; Tue, 12 Oct 2021 15:39:11 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 19CFdBCb037153; Tue, 12 Oct 2021 15:39:11 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 19CFdBVW037152; Tue, 12 Oct 2021 15:39:11 GMT (envelope-from git) Date: Tue, 12 Oct 2021 15:39:11 GMT Message-Id: <202110121539.19CFdBVW037152@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Ed Maste Subject: git: be74669a2f62 - stable/13 - OpenSSH: cherry-pick "need initgroups() before setresgid()" List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: emaste X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: be74669a2f62915f84b844bb00dd2767c60539fe Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=be74669a2f62915f84b844bb00dd2767c60539fe commit be74669a2f62915f84b844bb00dd2767c60539fe Author: Ed Maste AuthorDate: 2021-10-12 00:47:39 +0000 Commit: Ed Maste CommitDate: 2021-10-12 15:37:55 +0000 OpenSSH: cherry-pick "need initgroups() before setresgid()" From openssh-portable commits f3cbe43e28fe and bf944e3794ef, backported to OpenSSH 7.9p1 on stable/13. Reviewed by: delphij Security: CVE-2021-41617 Differential Revision: https://reviews.freebsd.org/D32460 (cherry picked from commit 172fa4aa7577915bf5ace5783251821d3774dc05) --- 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 #endif #include +#include #ifdef HAVE_LOGIN_H #include #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,