diff options
| author | jp161948 <none@none> | 2006-11-13 09:43:40 -0800 | 
|---|---|---|
| committer | jp161948 <none@none> | 2006-11-13 09:43:40 -0800 | 
| commit | 60779adb24bbd974e68a9993a8eafd79a30ad887 (patch) | |
| tree | 46745cb8248ea0c916f22d1053ef6e7a5c0d8906 | |
| parent | 84d68d8e929eb898bba40f17b9966212f1a66de8 (diff) | |
| download | illumos-joyent-60779adb24bbd974e68a9993a8eafd79a30ad887.tar.gz | |
6477720 possible DoS in CRC compensation attack detector for SSH protocol 1
6481229 potential race in fatal_cleanup() in ssh
| -rw-r--r-- | usr/src/cmd/ssh/include/deattack.h | 1 | ||||
| -rw-r--r-- | usr/src/cmd/ssh/libssh/common/deattack.c | 24 | ||||
| -rw-r--r-- | usr/src/cmd/ssh/libssh/common/log.c | 10 | ||||
| -rw-r--r-- | usr/src/cmd/ssh/libssh/common/packet.c | 17 | 
4 files changed, 41 insertions, 11 deletions
| diff --git a/usr/src/cmd/ssh/include/deattack.h b/usr/src/cmd/ssh/include/deattack.h index 22c088e603..fa7fc82312 100644 --- a/usr/src/cmd/ssh/include/deattack.h +++ b/usr/src/cmd/ssh/include/deattack.h @@ -32,6 +32,7 @@ extern "C" {  /* Return codes */  #define DEATTACK_OK		0  #define DEATTACK_DETECTED	1 +#define DEATTACK_DOS_DETECTED	2  int	 detect_attack(u_char *, u_int32_t, u_char[8]); diff --git a/usr/src/cmd/ssh/libssh/common/deattack.c b/usr/src/cmd/ssh/libssh/common/deattack.c index a5e5fde167..82afd4f16b 100644 --- a/usr/src/cmd/ssh/libssh/common/deattack.c +++ b/usr/src/cmd/ssh/libssh/common/deattack.c @@ -29,6 +29,24 @@ RCSID("$OpenBSD: deattack.c,v 1.18 2002/03/04 17:27:39 stevesk Exp $");  #include "xmalloc.h"  #include "deattack.h" +/* + * CRC attack detection has a worst-case behaviour that is O(N^2) over + * the number of identical blocks in a packet. This behaviour can be  + * exploited to create a limited denial of service attack.  + *  + * However, because we are dealing with encrypted data, identical + * blocks should only occur every 2^35 maximally-sized packets or so.  + * Consequently, we can detect this DoS by looking for identical blocks + * in a packet. + * + * The parameter below determines how many identical blocks we will + * accept in a single packet, trading off between attack detection and + * likelihood of terminating a legitimate connection. A value of 32  + * corresponds to an average of 2^40 messages before an attack is + * misdetected + */ +#define MAX_IDENTICAL	32 +  /* SSH Constants */  #define SSH_MAXBLOCKS	(32 * 1024)  #define SSH_BLOCKSIZE	(8) @@ -89,7 +107,7 @@ detect_attack(u_char *buf, u_int32_t len, u_char *IV)  	static u_int16_t *h = (u_int16_t *) NULL;  	static u_int32_t n = HASH_MINSIZE / HASH_ENTRYSIZE;  	u_int32_t i, j; -	u_int32_t l; +	u_int32_t l, same;  	u_char *c;  	u_char *d; @@ -135,7 +153,7 @@ detect_attack(u_char *buf, u_int32_t len, u_char *IV)  	if (IV)  		h[HASH(IV) & (n - 1)] = HASH_IV; -	for (c = buf, j = 0; c < (buf + len); c += SSH_BLOCKSIZE, j++) { +	for (c = buf, same = j = 0; c < (buf + len); c += SSH_BLOCKSIZE, j++) {  		for (i = HASH(c) & (n - 1); h[i] != HASH_UNUSED;  		    i = (i + 1) & (n - 1)) {  			if (h[i] == HASH_IV) { @@ -146,6 +164,8 @@ detect_attack(u_char *buf, u_int32_t len, u_char *IV)  						break;  				}  			} else if (!CMP(c, buf + h[i] * SSH_BLOCKSIZE)) { +				if (++same > MAX_IDENTICAL) +					return (DEATTACK_DOS_DETECTED);  				if (check_crc(c, buf, len, IV))  					return (DEATTACK_DETECTED);  				else diff --git a/usr/src/cmd/ssh/libssh/common/log.c b/usr/src/cmd/ssh/libssh/common/log.c index 4042d2ffd9..296c52a3f1 100644 --- a/usr/src/cmd/ssh/libssh/common/log.c +++ b/usr/src/cmd/ssh/libssh/common/log.c @@ -33,7 +33,7 @@   * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.   */  /* - * Copyright 2004 Sun Microsystems, Inc.  All rights reserved. + * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.   * Use is subject to license terms.   */ @@ -45,6 +45,7 @@ RCSID("$OpenBSD: log.c,v 1.24 2002/07/19 15:43:33 markus Exp $");  #include "log.h"  #include "xmalloc.h" +#include <atomic.h>  #include <syslog.h>  static LogLevel log_level = SYSLOG_LEVEL_INFO; @@ -262,16 +263,15 @@ fatal_remove_all_cleanups(void)  	fatal_cleanups = NULL;  } -/* Cleanup and exit */ +/* Cleanup and exit. Make sure each cleanup is called only once. */  void  fatal_cleanup(void)  {  	struct fatal_cleanup *cu, *next_cu; -	static int called = 0; +	static volatile u_int called = 0; -	if (called) +	if (atomic_cas_uint(&called, 0, 1) == 1)  		exit(255); -	called = 1;  	/* Call cleanup functions. */  	for (cu = fatal_cleanups; cu; cu = next_cu) {  		next_cu = cu->next; diff --git a/usr/src/cmd/ssh/libssh/common/packet.c b/usr/src/cmd/ssh/libssh/common/packet.c index 10cf9bdc1b..10fbdd0895 100644 --- a/usr/src/cmd/ssh/libssh/common/packet.c +++ b/usr/src/cmd/ssh/libssh/common/packet.c @@ -36,7 +36,7 @@   * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.   */  /* - * Copyright 2004 Sun Microsystems, Inc.  All rights reserved. + * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.   * Use is subject to license terms.   */ @@ -913,9 +913,18 @@ packet_read_poll1(void)  	 * (C)1998 CORE-SDI, Buenos Aires Argentina  	 * Ariel Futoransky(futo@core-sdi.com)  	 */ -	if (!receive_context.plaintext && -	    detect_attack(buffer_ptr(&input), padded_len, NULL) == DEATTACK_DETECTED) -		packet_disconnect("crc32 compensation attack: network attack detected"); +	if (!receive_context.plaintext) { +		switch (detect_attack(buffer_ptr(&input), padded_len, NULL)) { +		case DEATTACK_DETECTED: +			packet_disconnect("crc32 compensation attack: " +			    "network attack detected"); +			break; +		case DEATTACK_DOS_DETECTED: +			packet_disconnect("deattack denial of " +			    "service detected"); +			break; +		} +	}  	/* Decrypt data to incoming_packet. */  	buffer_clear(&incoming_packet); | 
