NetBSD Problem Report #14846

Received: (qmail 29084 invoked from network); 5 Dec 2001 14:46:59 -0000
Message-Id: <20011205144705.1DB921110F@www.netbsd.org>
Date: Wed,  5 Dec 2001 06:47:05 -0800 (PST)
From: xs@nitric.net
Sender: nobody@netbsd.org
Reply-To: xs@nitric.net
To: gnats-bugs@gnats.netbsd.org
Subject: openssh appears vulnerable to a DoS attack that resembles the crc32 problem
X-Send-Pr-Version: www-1.0

>Number:         14846
>Category:       security
>Synopsis:       openssh appears vulnerable to a DoS attack that resembles the crc32 problem
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    security-officer
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Dec 05 14:47:00 +0000 2001
>Closed-Date:    Wed Sep 04 06:14:33 +0000 2002
>Last-Modified:  Fri Dec 21 18:33:42 +0000 2012
>Originator:     
>Release:        1.5.2
>Organization:
>Environment:
NetBSD freeze 1.5.2 NetBSD 1.5.2 (PERCEPTION) #15: Sat Oct 27 19:16:05 BST 2001     root@freeze:/usr/src/sys/arch/i386/compile/PERCEPTION i386
>Description:
With a username greater or equal to 3204 bytes, openssh 2.5.1 (protocol 1) sshd as included with NetBSD 1.5.2 causes a bus error.
With a username greater or equal to 2380 bytes, openssh 3.0.2p1 (protocol 1) sshd running under NetBSD 1.5.2 causes a bus error.

The above figures seem to vary between openssh versions and the protocol version that openssh is using, but are stable for the same version/binary and protocol.
A username of 90,000 bytes should work where the specific number is unknown.

http://razor.bindview.com/publish/advisories/adv_ssh1crc.html
This does not seem to be the same flaw, but the way to reproduce it is exactly the same. Disabling protocol 1 does not seem sufficient. I can reproduce it with both protocol 1 and 2.

This system has Kerberos enabled. But sshd.conf disables it. This problem occurs with openssh 3.0.2p1 installed from the source available at ftp.openbsd.org as well as openssh 2.5.1 as packaged with NetBSD 1.5.2.

This seems to be NetBSD specific and/or specific to my set up. A Linux box configured similarly doesn't exhibit the same problems with openssh >= 2.9.9p2 (I haven't tested below 2.9.9p2 on the Linux box.)


>How-To-Repeat:
Server side:
# cat >sshd.conf
Port 222
Protocol 2
HostKey /etc/ssh_host_key
HostKey /etc/ssh_host_dsa_key
#HostKey /etc/ssh_host_rsa_key
ServerKeyBits 768
LoginGraceTime 600
KeyRegenerationInterval 3600
PermitRootLogin no
IgnoreRhosts yes
IgnoreRootRhosts yes
#IgnoreUserKnownHosts yes
StrictModes yes
X11Forwarding no
X11DisplayOffset 10
PrintMotd yes
KeepAlive yes
SyslogFacility AUTH
LogLevel INFO
RhostsAuthentication no
RhostsRSAAuthentication no
RSAAuthentication yes
PasswordAuthentication yes
PermitEmptyPasswords no
#ChallengeResponseAuthentication no
KerberosAuthentication no
KerberosOrLocalPasswd no
#AFSTokenPassing no
#KerberosTicketCleanup no
# Kerberos TGT Passing does only work with the AFS kaserver
#KerberosTgtPassing yes
#CheckMail yes
#UseLogin no
#MaxStartups 10:30:60
#Banner /etc/issue.net
#ReverseMappingCheck yes
#Subsystem      sftp    /usr/libexec/sftp-server

# sshd -d -f sshd.conf
debug1: sshd version OpenSSH_2.5.1 NetBSD_Secure_Shell-20010614
...
Server listening on 0.0.0.0 port 222.
...
Connection from (ip) port 2868
debug1: Client protocol version 2.0; client software version OpenSSH_2.9.9p2
debug1: match: OpenSSH_2.9.9p2 pat ^OpenSSH
Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-1.99-OpenSSH_2.5.1 NetBSD_Secure_Shell-20010614
...
debug1: Wait SSH2_MSG_NEWKEYS.
debug1: GOT SSH2_MSG_NEWKEYS.
debug1: done: KEX2.
debug1: userauth-request for user AAAAAAAAAAAAAAA[lots more A's]
debug1: attempt 0 failures 0
Bus error (core dumped)

# gdb -core sshd.core `which sshd`
...
#0  0x481f7c0a in __log2 ()
(gdb) bt
#0  0x481f7c0a in __log2 ()
#1  0x481f59ba in __call_hash ()
#2  0x481f52eb in __hash_open ()
#3  0x481f518b in __hash_open ()
#4  0x481baec5 in endpwent ()
#5  0x481ba014 in _getsubopt ()
#6  0x481ba911 in _getsubopt ()
#7  0x481ecdda in nsdispatch ()
#8  0x481bac56 in getpwnam ()
#9  0x8053075 in dladdr ()
#10 0x805839f in dladdr ()
#11 0x8052ebb in dladdr ()
#12 0x804d586 in dladdr ()
#13 0x804b9fd in krb_get_pw_in_tkt ()

Client side:

> ssh -l`perl -e '{print "A"x90000;}'` -p 222 -v host
...
Connection closed by (ip).

Details for openssh 3.0.2p1 server side:

# ./sshd -p 222 -d
debug1: Bind to port 222 on 0.0.0.0.
...
debug1: Client protocol version 2.0; client software version OpenSSH_2.9.9p2
debug1: match: OpenSSH_2.9.9p2 pat ^OpenSSH
Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-1.99-OpenSSH_3.0.2p1
...
debug1: SSH2_MSG_NEWKEYS received
debug1: KEX done
debug1: userauth-request for user AAAAAAAAAAAA[lots of A's]
debug1: attempt 0 failures 0
Bus error (core dumped)
# gdb -core /sshd.core ./sshd
...
#0  0x481cfc0a in __log2 ()
(gdb) bt
#0  0x481cfc0a in __log2 ()
#1  0x481cd9ba in __call_hash ()
#2  0x481cd2eb in __hash_open ()
#3  0x481cd18b in __hash_open ()
#4  0x48192ec5 in endpwent ()
#5  0x48192014 in _getsubopt ()
#6  0x48192911 in _getsubopt ()
#7  0x481c4dda in nsdispatch ()
#8  0x48192c56 in getpwnam ()
#9  0x804ec15 in dladdr ()
#10 0x805e3eb in dladdr ()
#11 0x804ea5a in dladdr ()
#12 0x804d3c1 in dladdr ()
#13 0x804b811 in getsockname ()

>Fix:
Unsure.

>Release-Note:
>Audit-Trail:

From: Jun-ichiro itojun Hagino <itojun@iijlab.net>
To: xs@nitric.net
Cc: gnats-bugs@gnats.netbsd.org
Subject: Re: security/14846
Date: Wed, 23 Jan 2002 18:48:21 +0900

 	http://www.NetBSD.org/cgi-bin/query-pr-single.pl?number=14846

 	It looks to me that the issue is with getpwnam(3) in netbsd, not in
 	sshd itself.  run the following program with:
 	% ./a.out `perl -e '{print "A"x90000;}'`
 	and you will see a segmentation fault.

 itojun


 #include <sys/types.h>
 #include <pwd.h>

 main(argc, argv)
 	int argc;
 	char **argv;
 {
 	struct passwd *p;
 	p = getpwnam(argv[1]);
 	printf("%d %d\n", p->pw_uid, p->pw_gid);
 }

From: itojun@iijlab.net
To: xs@nitric.net, gnats-bugs@gnats.netbsd.org
Cc:  
Subject: Re: security/14846 
Date: Wed, 23 Jan 2002 18:54:13 +0900

 >	http://www.NetBSD.org/cgi-bin/query-pr-single.pl?number=14846
 >	It looks to me that the issue is with getpwnam(3) in netbsd, not in
 >	sshd itself.  run the following program with:
 >	% ./a.out `perl -e '{print "A"x90000;}'`
 >	and you will see a segmentation fault.

 	oops, i was wrong.

 itojun

From: itojun@iijlab.net
To: xs@nitric.net, gnats-bugs@gnats.netbsd.org
Cc:  
Subject: Re: security/14846 
Date: Thu, 24 Jan 2002 14:33:52 +0900

 	more detailed backtrace.

 itojun



 % obj.i386/sshd -p 222 -d
 debug1: sshd version OpenSSH_3.0.2 NetBSD_Secure_Shell-20011206
 debug1: private host key: #0 type 0 RSA1
 debug1: read PEM private key done: type RSA
 debug1: private host key: #1 type 1 RSA
 debug1: read PEM private key done: type DSA
 debug1: private host key: #2 type 2 DSA
 debug1: Bind to port 222 on ::.
 Server listening on :: port 222.
 debug1: Bind to port 222 on 0.0.0.0.
 Server listening on 0.0.0.0 port 222.
 Generating 768 bit RSA key.
 RSA key generation complete.
 debug1: Server will not fork when running in debugging mode.
 Connection from ::1 port 49592
 debug1: Client protocol version 2.0; client software version OpenSSH_3.0.2 NetBSD_Secure_Shell-20011206
 debug1: match: OpenSSH_3.0.2 NetBSD_Secure_Shell-20011206 pat OpenSSH*
 Enabling compatibility mode for protocol 2.0
 debug1: Local version string SSH-1.99-OpenSSH_3.0.2 NetBSD_Secure_Shell-20011206
 debug1: Rhosts Authentication disabled, originating port 49592 not trusted.
 debug1: list_hostkey_types: ssh-rsa,ssh-dss
 debug1: SSH2_MSG_KEXINIT sent
 debug1: SSH2_MSG_KEXINIT received
 debug1: kex: client->server aes128-cbc hmac-md5 none
 debug1: kex: server->client aes128-cbc hmac-md5 none
 debug1: SSH2_MSG_KEX_DH_GEX_REQUEST received
 debug1: SSH2_MSG_KEX_DH_GEX_GROUP sent
 debug1: dh_gen_key: priv key bits set: 134/256
 debug1: bits set: 1568/3191
 debug1: expecting SSH2_MSG_KEX_DH_GEX_INIT
 debug1: bits set: 1633/3191
 debug1: SSH2_MSG_KEX_DH_GEX_REPLY sent
 debug1: kex_derive_keys
 debug1: newkeys: mode 1
 debug1: SSH2_MSG_NEWKEYS sent
 debug1: waiting for SSH2_MSG_NEWKEYS
 debug1: newkeys: mode 0
 debug1: SSH2_MSG_NEWKEYS received
 debug1: KEX done
 debug1: userauth-request for user AAAA....
 debug1: attempt 0 failures 0



 (gdb) bt
 #0  0x80c49ae in hash4 (keyarg=0xbfbfcbd8, len=90001)
     at /home/itojun/NetBSD/src/lib/libc/db/hash/hash_func.c:217
 #1  0x80c1c8d in __call_hash (hashp=0x8111400, 
     k=0xbfbfcbd8 "1", 'A' <repeats 16 times>, "(Ik(B\b\b(IXK??(B\221_\001", len=90001)
     at /home/itojun/NetBSD/src/lib/libc/db/hash/hash.c:906
 #2  0x80c12ef in hash_access (hashp=0x8111400, action=HASH_GET, 
     key=0xbfbfcbec, val=0xbfbfcb80)
     at /home/itojun/NetBSD/src/lib/libc/db/hash/hash.c:626
 #3  0x80c1173 in hash_get (dbp=0x810f580, key=0xbfbfcbec, data=0xbfbfcb80, 
     flag=0) at /home/itojun/NetBSD/src/lib/libc/db/hash/hash.c:555
 #4  0x808ec8e in __hashpw (key=0xbfbfcbec)
     at /home/itojun/NetBSD/src/lib/libc/gen/getpwent.c:1176
 #5  0x808dabe in _local_getpw (rv=0x0, cb_data=0x0, 
     ap=0xbfbfccb8 "(IOy(B\006\b(IDa(B\017\b")
     at /home/itojun/NetBSD/src/lib/libc/gen/getpwent.c:441
 #6  0x808e5af in _compat_getpw (rv=0x0, cb_data=0x0, ap=0xbfbfccb0 "1")
     at /home/itojun/NetBSD/src/lib/libc/gen/getpwent.c:897
 #7  0x80bbca7 in _nsdispatch (retval=0x0, disp_tab=0x80f2114, 
     database=0x80f1fda "passwd", method=0x80f2150 "getpwnam", 
     defaults=0x80f1f88)
     at /home/itojun/NetBSD/src/lib/libc/net/nsdispatch.c:299
 #8  0x808e9cc in _getpwnam (name=0x815f000 'A' <repeats 200 times>...)
     at /home/itojun/NetBSD/src/lib/libc/gen/getpwent.c:1058
 #9  0x805fdf1 in input_userauth_request (type=50, plen=90030, ctxt=0x810f200)
     at /usr/home/itojun/NetBSD/src/usr.bin/ssh/sshd/../../../crypto/dist/ssh/auth2.c:197
 #10 0x806dab7 in dispatch_run (mode=0, done=0x810f200, ctxt=0x810f200)
     at /usr/home/itojun/NetBSD/src/usr.bin/ssh/libssh/../../../crypto/dist/ssh/dispatch.c:72
 #11 0x805fb83 in do_authentication2 ()
     at /usr/home/itojun/NetBSD/src/usr.bin/ssh/sshd/../../../crypto/dist/ssh/auth2.c:127
 #12 0x8057a96 in main (ac=4, av=0xbfbfd6a4)
     at /usr/home/itojun/NetBSD/src/usr.bin/ssh/sshd/../../../crypto/dist/ssh/sshd.c:1193
 #13 0x805543c in ___start ()


From: xs@kittenz.org
To: gnats-bugs@gnats.netbsd.org
Cc:  
Subject: Re: security/14846
Date: Sat, 16 Feb 2002 22:50:37 +0000

 itojun was actually correct. This is an overflow in getpwnam(3). key.size is
 set incorrectly if the string length is greater than MAXLOGNAME. Here's a
 fix, it also adds an explicit nul terminator to an strncpy'd string, which
 appeared to have been missing.


 Index: gen/getpwent.c
 ===================================================================
 RCS file: /cvsroot/basesrc/lib/libc/gen/getpwent.c,v
 retrieving revision 1.46.4.2
 diff -c -r1.46.4.2 getpwent.c
 *** getpwent.c	2000/10/11 03:35:18	1.46.4.2
 --- getpwent.c	2002/02/16 16:43:01
 ***************
 *** 379,384 ****
 --- 379,385 ----
   			if (datalen > sizeof(adjunctpw) - 1)
   				datalen = sizeof(adjunctpw) - 1;
   			strncpy(adjunctpw, data, (size_t)datalen);
 + 			adjunctpw[sizeof(adjunctpw)-1] = '\0';

   				/* skip name to get password */
   			if ((bp = strsep(&data, ":")) != NULL &&
 ***************
 *** 425,431 ****
   	case _PW_KEYBYNAME:
   		name = va_arg(ap, const char *);
   		len = strlen(name);
 ! 		memmove(bf + 1, name, (size_t)MIN(len, MAXLOGNAME));
   		key.size = len + 1;
   		break;
   	case _PW_KEYBYUID:
 --- 426,434 ----
   	case _PW_KEYBYNAME:
   		name = va_arg(ap, const char *);
   		len = strlen(name);
 ! 		if (len > MAXLOGNAME)
 ! 			return NS_UNAVAIL;
 ! 		memmove(bf + 1, name, (size_t)len);
   		key.size = len + 1;
   		break;
   	case _PW_KEYBYUID:


From: xs@nitric.net
To: gnats-bugs@gnats.netbsd.org
Cc:  
Subject: Re: security/14846
Date: Sat, 23 Mar 2002 23:04:10 +0000

 I believe this has now been fixed in -current, mycroft@ commited revision
 1.49 of getpwent.c.

State-Changed-From-To: open->closed 
State-Changed-By: itojun 
State-Changed-When: Tue Sep 3 23:13:42 PDT 2002 
State-Changed-Why:  
fixed 

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.