From sanewo@ba2.so-net.ne.jp  Fri Aug 10 09:57:22 2001
Return-Path: <sanewo@ba2.so-net.ne.jp>
Received: from mgate03.so-net.ne.jp (mgate03.so-net.ne.jp [210.139.254.150])
	by hub.freebsd.org (Postfix) with ESMTP id 271E037B406
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 10 Aug 2001 09:57:21 -0700 (PDT)
	(envelope-from sanewo@ba2.so-net.ne.jp)
Received: from mail.ba2.so-net.ne.jp (mail.ba2.so-net.ne.jp [210.139.254.21])
	by mgate03.so-net.ne.jp (8.8.8+3.0Wbeta9/3.6W01060506) with ESMTP id BAA07177
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 11 Aug 2001 01:57:19 +0900 (JST)
Received: from ba2.so-net.ne.jp (pd301e9.tkyoea00.ap.so-net.ne.jp [61.211.1.233])
	by mail.ba2.so-net.ne.jp  with ESMTP id f7AGvIs26972
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 11 Aug 2001 01:57:19 +0900 (JST)
Received: (from sanewo@localhost)
	by ba2.so-net.ne.jp (8.11.5/8.11.5) id f7AGvHX21567;
	Sat, 11 Aug 2001 01:57:17 +0900 (JST)
	(envelope-from sanewo)
Message-Id: <200108101657.f7AGvHX21567@ba2.so-net.ne.jp>
Date: Sat, 11 Aug 2001 01:57:17 +0900 (JST)
From: Takanori Saneto <sanewo@ba2.so-net.ne.jp>
To: FreeBSD-gnats-submit@freebsd.org
Subject: yet another core dump caused by pam_ssh
X-Send-Pr-Version: 3.113

>Number:         29609
>Category:       bin
>Synopsis:       yet another core dump caused by pam_ssh
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    markm
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Aug 10 10:00:00 PDT 2001
>Closed-Date:    Sat Aug 11 05:38:58 PDT 2001
>Last-Modified:  Sat Aug 11 05:39:50 PDT 2001
>Originator:     Takanori Saneto
>Release:        FreeBSD 5.0-CURRENT i386
>Organization:
an individual
>Environment:
System: FreeBSD muse.sanewo 5.0-CURRENT FreeBSD 5.0-CURRENT #3: Fri Aug 10 08:39:44 JST 2001 root@:/export/usr.obj/usr/src/sys/MUSE i386

-CURRENT as of 2001/08/10, with following lines in /etc/pam.conf:

xdm	auth	requisite	pam_cleartext_pass_ok.so
xdm	auth	required	pam_nologin.so
xdm	auth	sufficient	pam_ssh.so		try_first_pass
xdm	auth	required	pam_unix.so
xdm	account	required	pam_unix.so
xdm	session	optional	pam_ssh.so
xdm	session	required	pam_deny.so
xdm	password required	pam_deny.so


>Description:

/usr/src/lib/libpam/modules/pam_ssh/pam_ssh.c has couple of bugs which cause:

1) xdm dumps core
2) ssh1 private key is not passed to ssh-agent
3) ssh2 RSA key seems not handled properly (just a guess from source)
4) ssh_get_authentication_connectionen() fails to get connection because of
   SSH_AUTH_SOCK not defined.

>How-To-Repeat:

With pam.conf shown above, invoke xdm and try to login.

>Fix:

In my environment, following patch seems to fix above problems.

But I'm not sure this is the right way to do, especially for problem
#4. (modifying ssh_get_authentication_connection() so that it takes an
argument for the name of socket file could be better?)

Summary of fix:

1) treatment of environment string was incorrect. does it right as in ports/security/pam_ssh.
2) key type of ssh1 key should be KEY_RSA1, not KEY_RSA.
3) typo fixed (one of KEY_DSA should be KEY_RSA)
4) use putenv() to put SSH_AUTH_SOCK to the environment

Index: pam_ssh.c
===================================================================
RCS file: /export/cvsup/cvs/src/lib/libpam/modules/pam_ssh/pam_ssh.c,v
retrieving revision 1.14
diff -u -u -r1.14 pam_ssh.c
--- pam_ssh.c	2001/08/04 21:51:14	1.14
+++ pam_ssh.c	2001/08/07 14:02:37
@@ -199,7 +199,7 @@
 	}
 	pam_auth_dsa = auth_via_key(pamh, KEY_DSA, SSH_CLIENT_ID_DSA, dotdir,
 	    pwd, pass);
-	pam_auth_rsa = auth_via_key(pamh, KEY_RSA, SSH_CLIENT_IDENTITY, dotdir,
+	pam_auth_rsa = auth_via_key(pamh, KEY_RSA1, SSH_CLIENT_IDENTITY, dotdir,
 	    pwd, pass);
 	authenticated = 0;
 	if (pam_auth_dsa == PAM_SUCCESS)
@@ -234,7 +234,7 @@
 		/* RSA keys */
 		else if (strncmp(dotdir_ent->d_name, SSH2_RSA_PREFIX,
 		    strlen(SSH2_RSA_PREFIX)) == 0)
-			retval = auth_via_key(pamh, KEY_DSA,
+			retval = auth_via_key(pamh, KEY_RSA,
 			    dotdir_ent->d_name, dotdir, pwd, pass);
 		/* skip other files */
 		else
@@ -374,11 +374,11 @@
 		if (env_fp)
 			fputs(env_string, env_fp);
 		env_value = strchr(env_string, '=');
-		if (env_value == NULL) {
-			env_end = strchr(env_value, ';');
-			if (env_end != NULL)
-				continue;
-		}
+		if (env_value == NULL)
+			continue;
+		env_end = strchr(env_value, ';');
+		if (env_end == NULL)
+			continue;
 		*env_end = '\0';
 		/* pass to the application ... */
 		retval = pam_putenv(pamh, env_string);
@@ -388,6 +388,7 @@
 				fclose(env_fp);
 			PAM_RETURN(PAM_SERVICE_ERR);
 		}
+		(void)putenv(env_string);
 		*env_value++ = '\0';
 		if (strcmp(&env_string[strlen(env_string) -
 		    strlen(ENV_SOCKET_SUFFIX)], ENV_SOCKET_SUFFIX) == 0) {
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->markm 
Responsible-Changed-By: kris 
Responsible-Changed-When: Fri Aug 10 14:59:38 PDT 2001 
Responsible-Changed-Why:  
Over to Mark 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=29609 
State-Changed-From-To: open->closed 
State-Changed-By: markm 
State-Changed-When: Sat Aug 11 05:38:58 PDT 2001 
State-Changed-Why:  
Committed, thanks! (Domo Arrigato!) 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=29609 
>Unformatted:
