bmh10 / rpms / openssh

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