From 9b79efbe495f83a4f60990c5371a5a6454e99768 Mon Sep 17 00:00:00 2001 From: djm Date: Sun, 26 Sep 2021 14:01:03 +0000 Subject: [PATCH] need initgroups() before setresgid(); reported by anton@, ok deraadt@ --- usr.bin/ssh/misc.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/usr.bin/ssh/misc.c b/usr.bin/ssh/misc.c index 9a1c057f635..b5e52b675bc 100644 --- a/usr.bin/ssh/misc.c +++ b/usr.bin/ssh/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. @@ -2594,6 +2594,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)); -- 2.20.1