]> git.pld-linux.org Git - packages/openssh.git/blob - openssh-identical-simple-dos-2.patch
22c8beab38a36cf9c658509af1924322f624a565
[packages/openssh.git] / openssh-identical-simple-dos-2.patch
1 http://bugs.gentoo.org/148228
2
3 taken from upstream cvs and munged a little to apply against 4.3p2
4
5 ===================================================================
6 RCS file: /usr/OpenBSD/cvs/src/usr.bin/ssh/deattack.c,v
7 retrieving revision 1.29
8 retrieving revision 1.30
9 diff -u -r1.29 -r1.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
12 @@ -30,6 +30,24 @@
13  #include "crc32.h"
14  #include "misc.h"
15  
16 +/*
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. 
20 + * 
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
24 + * in a packet.
25 + *
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
30 + * misdetected
31 + */
32 +#define MAX_IDENTICAL  32
33 +
34  /* SSH Constants */
35  #define SSH_MAXBLOCKS  (32 * 1024)
36  #define SSH_BLOCKSIZE  (8)
37 @@ -85,7 +103,7 @@
38         static u_int16_t *h = (u_int16_t *) NULL;
39         static u_int32_t n = HASH_MINSIZE / HASH_ENTRYSIZE;
40         u_int32_t i, j;
41 -       u_int32_t l;
42 +       u_int32_t l, same;
43         u_char *c;
44         u_char *d;
45  
46 @@ -122,11 +140,13 @@
47         if (IV)
48                 h[HASH(IV) & (n - 1)] = HASH_IV;
49  
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) {
57                                 if (!CMP(c, IV)) {
58                                         if (check_crc(c, buf, len, IV))
59                                                 return (DEATTACK_DETECTED);
60                                         else
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
68 @@ -991,9 +991,16 @@
69          * (C)1998 CORE-SDI, Buenos Aires Argentina
70          * Ariel Futoransky(futo@core-sdi.com)
71          */
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");
83 +               }
84 +       }
85  
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
92 diff -u -r1.9 -r1.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
95 @@ -25,6 +25,7 @@
96  /* Return codes */
97  #define DEATTACK_OK            0
98  #define DEATTACK_DETECTED      1
99 +#define DEATTACK_DOS_DETECTED  2
100  
101  int     detect_attack(u_char *, u_int32_t);
102  #endif
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
110 @@ -682,6 +682,9 @@
111          */
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)
116 +                       continue;
117                 comp = &newkeys[mode]->comp;
118                 if (comp && !comp->enabled && comp->type == COMP_DELAYED) {
119                         packet_init_compression();
This page took 0.024981 seconds and 2 git commands to generate.