bmh10 / rpms / openssh

Forked from rpms/openssh 10 days ago
Clone
b58e57
From 26f96ca10ad0ec5da9b05b99de1e1ccea15a11be Mon Sep 17 00:00:00 2001
b58e57
From: "djm@openbsd.org" <djm@openbsd.org>
b58e57
Date: Fri, 15 Jun 2018 07:01:11 +0000
b58e57
Subject: [PATCH] upstream: invalidate supplemental group cache used by
b58e57
b58e57
temporarily_use_uid() when the target uid differs; could cause failure to
b58e57
read authorized_keys under some configurations. patch by Jakub Jelen via
b58e57
bz2873; ok dtucker, markus
b58e57
b58e57
OpenBSD-Commit-ID: 48a345f0ee90f6c465a078eb5e89566b23abd8a1
b58e57
---
b58e57
 uidswap.c | 8 ++++++--
b58e57
 1 file changed, 6 insertions(+), 2 deletions(-)
b58e57
b58e57
diff --git a/uidswap.c b/uidswap.c
b58e57
index 8bf6b244e..1430b822a 100644
b58e57
--- a/uidswap.c
b58e57
+++ b/uidswap.c
b58e57
@@ -49,6 +49,7 @@ static gid_t	saved_egid = 0;
b58e57
 /* Saved effective uid. */
b58e57
 static int	privileged = 0;
b58e57
 static int	temporarily_use_uid_effective = 0;
b58e57
+static uid_t	user_groups_uid;
b58e57
 static gid_t	*saved_egroups = NULL, *user_groups = NULL;
b58e57
 static int	saved_egroupslen = -1, user_groupslen = -1;
b58e57
 
b58e57
@@ -92,10 +93,11 @@ temporarily_use_uid(struct passwd *pw)
b58e57
 			fatal("getgroups: %.100s", strerror(errno));
b58e57
 	} else { /* saved_egroupslen == 0 */
b58e57
 		free(saved_egroups);
b58e57
+		saved_egroups = NULL;
b58e57
 	}
b58e57
 
b58e57
 	/* set and save the user's groups */
b58e57
-	if (user_groupslen == -1) {
b58e57
+	if (user_groupslen == -1 || user_groups_uid != pw->pw_uid) {
b58e57
 		if (initgroups(pw->pw_name, pw->pw_gid) < 0)
b58e57
 			fatal("initgroups: %s: %.100s", pw->pw_name,
b58e57
 			    strerror(errno));
b58e57
@@ -110,7 +112,9 @@ temporarily_use_uid(struct passwd *pw)
b58e57
 				fatal("getgroups: %.100s", strerror(errno));
b58e57
 		} else { /* user_groupslen == 0 */
b58e57
 			free(user_groups);
b58e57
+			user_groups = NULL;
b58e57
 		}
b58e57
+		user_groups_uid = pw->pw_uid;
b58e57
 	}
b58e57
 	/* Set the effective uid to the given (unprivileged) uid. */
b58e57
 	if (setgroups(user_groupslen, user_groups) < 0)
b58e57