jonathancammack / rpms / openssh

Forked from rpms/openssh 8 months ago
Clone
8f2528
diff -up openssh-7.4p1/pam_ssh_agent_auth-0.10.3/iterate_ssh_agent_keys.c.psaa-seteuid openssh-7.4p1/pam_ssh_agent_auth-0.10.3/iterate_ssh_agent_keys.c
8f2528
--- openssh-7.4p1/pam_ssh_agent_auth-0.10.3/iterate_ssh_agent_keys.c.psaa-seteuid	2017-02-13 17:51:29.790005199 +0100
8f2528
+++ openssh-7.4p1/pam_ssh_agent_auth-0.10.3/iterate_ssh_agent_keys.c	2017-02-13 17:52:53.640919947 +0100
8f2528
@@ -238,17 +238,25 @@ ssh_get_authentication_socket_for_uid(ui
8f2528
 	}
8f2528
 
8f2528
 	errno = 0; 
8f2528
-	seteuid(uid); /* To ensure a race condition is not used to circumvent the stat
8f2528
-	             above, we will temporarily drop UID to the caller */
8f2528
-	if (connect(sock, (struct sockaddr *)&sunaddr, sizeof sunaddr) < 0) {
8f2528
+	/* To ensure a race condition is not used to circumvent the stat
8f2528
+	   above, we will temporarily drop UID to the caller */
8f2528
+	if (seteuid(uid) == -1) {
8f2528
 		close(sock);
8f2528
-        if(errno == EACCES)
8f2528
-		fatal("MAJOR SECURITY WARNING: uid %lu made a deliberate and malicious attempt to open an agent socket owned by another user", (unsigned long) uid);
8f2528
+		error("seteuid(%lu) failed with error: %s", (unsigned long) uid, strerror(errno));
8f2528
 		return -1;
8f2528
 	}
8f2528
+	if (connect(sock, (struct sockaddr *)&sunaddr, sizeof sunaddr) < 0) {
8f2528
+		close(sock);
8f2528
+		sock = -1;
8f2528
+		if(errno == EACCES)
8f2528
+			fatal("MAJOR SECURITY WARNING: uid %lu made a deliberate and malicious attempt to open an agent socket owned by another user", (unsigned long) uid);
8f2528
+	}
8f2528
 
8f2528
-	seteuid(0); /* we now continue the regularly scheduled programming */
8f2528
-
8f2528
+	/* we now continue the regularly scheduled programming */
8f2528
+	if (0 != seteuid(0)) {
8f2528
+	fatal("setuid(0) failed with error: %s", strerror(errno));
8f2528
+	return -1;
8f2528
+	}
8f2528
 	return sock;
8f2528
 }
8f2528