vishalmishra434 / rpms / openssh

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