1 http://bugs.gentoo.org/148228
3 taken from upstream cvs and munged a little to apply against 4.3p2
5 ===================================================================
6 RCS file: /usr/OpenBSD/cvs/src/usr.bin/ssh/deattack.c,v
7 retrieving revision 1.29
8 retrieving revision 1.30
10 --- src/usr.bin/ssh/deattack.c 2006/08/03 03:34:42 1.29
11 +++ src/usr.bin/ssh/deattack.c 2006/09/16 19:53:37 1.30
17 + * CRC attack detection has a worst-case behaviour that is O(N^3) over
18 + * the number of identical blocks in a packet. This behaviour can be
19 + * exploited to create a limited denial of service attack.
21 + * However, because we are dealing with encrypted data, identical
22 + * blocks should only occur every 2^35 maximally-sized packets or so.
23 + * Consequently, we can detect this DoS by looking for identical blocks
26 + * The parameter below determines how many identical blocks we will
27 + * accept in a single packet, trading off between attack detection and
28 + * likelihood of terminating a legitimate connection. A value of 32
29 + * corresponds to an average of 2^40 messages before an attack is
32 +#define MAX_IDENTICAL 32
35 #define SSH_MAXBLOCKS (32 * 1024)
36 #define SSH_BLOCKSIZE (8)
38 static u_int16_t *h = (u_int16_t *) NULL;
39 static u_int32_t n = HASH_MINSIZE / HASH_ENTRYSIZE;
48 h[HASH(IV) & (n - 1)] = HASH_IV;
50 - for (c = buf, j = 0; c < (buf + len); c += SSH_BLOCKSIZE, j++) {
51 + for (c = buf, same = j = 0; c < (buf + len); c += SSH_BLOCKSIZE, j++) {
52 for (i = HASH(c) & (n - 1); h[i] != HASH_UNUSED;
53 i = (i + 1) & (n - 1)) {
54 + if (!CMP(c, buf + h[i] * SSH_BLOCKSIZE) && ++same > MAX_IDENTICAL)
55 + return (DEATTACK_DOS_DETECTED);
56 if (h[i] == HASH_IV) {
58 if (check_crc(c, buf, len, IV))
59 return (DEATTACK_DETECTED);
61 ===================================================================
62 RCS file: /usr/OpenBSD/cvs/src/usr.bin/ssh/packet.c,v
63 retrieving revision 1.143
64 retrieving revision 1.144
65 diff -u -r1.143 -r1.144
66 --- src/usr.bin/ssh/packet.c 2006/08/05 08:34:04 1.143
67 +++ src/usr.bin/ssh/packet.c 2006/09/16 19:53:37 1.144
69 * (C)1998 CORE-SDI, Buenos Aires Argentina
70 * Ariel Futoransky(futo@core-sdi.com)
72 - if (!receive_context.plaintext &&
73 - detect_attack(buffer_ptr(&input), padded_len, NULL) == DEATTACK_DETECTED)
74 - packet_disconnect("crc32 compensation attack: network attack detected");
75 + if (!receive_context.plaintext) {
76 + switch (detect_attack(buffer_ptr(&input), padded_len, NULL)) {
77 + case DEATTACK_DETECTED:
78 + packet_disconnect("crc32 compensation attack: "
79 + "network attack detected");
80 + case DEATTACK_DOS_DETECTED:
81 + packet_disconnect("deattack denial of "
82 + "service detected");
86 /* Decrypt data to incoming_packet. */
87 buffer_clear(&incoming_packet);
88 ===================================================================
89 RCS file: /usr/OpenBSD/cvs/src/usr.bin/ssh/deattack.h,v
90 retrieving revision 1.9
91 retrieving revision 1.10
93 --- src/usr.bin/ssh/deattack.h 2006/03/25 22:22:43 1.9
94 +++ src/usr.bin/ssh/deattack.h 2006/09/16 19:53:37 1.10
98 #define DEATTACK_DETECTED 1
99 +#define DEATTACK_DOS_DETECTED 2
101 int detect_attack(u_char *, u_int32_t);
103 ===================================================================
104 RCS file: /usr/OpenBSD/cvs/src/usr.bin/ssh/packet.c,v
105 retrieving revision 1.144
106 retrieving revision 1.145
107 diff -u -r1.144 -r1.145
108 --- src/usr.bin/ssh/packet.c 2006/09/16 19:53:37 1.144
109 +++ src/usr.bin/ssh/packet.c 2006/09/19 21:14:08 1.145
112 after_authentication = 1;
113 for (mode = 0; mode < MODE_MAX; mode++) {
114 + /* protocol error: USERAUTH_SUCCESS received before NEWKEYS */
115 + if (newkeys[mode] == NULL)
117 comp = &newkeys[mode]->comp;
118 if (comp && !comp->enabled && comp->type == COMP_DELAYED) {
119 packet_init_compression();