aboutsummaryrefslogtreecommitdiff
path: root/share/security/advisories/FreeBSD-SA-98:07.rst.asc
blob: e4dc9cfc7575ed479a66457839906f1bcd87d1a9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
-----BEGIN PGP SIGNED MESSAGE-----

=============================================================================
FreeBSD-SA-98:07                                            Security Advisory
                                                                FreeBSD, Inc.

Topic:          TCP RST denial of sevice

Category:       core
Module:         kernel
Announced:      1998-10-13
Affects:        FreeBSD 2.2.* (before 2.2.8R), FreeBSD-stable and
		FreeBSD-current before the correction date.
Corrected:      FreeBSD-current as of 1998/09/11
		FreeBSD-stable as of 1998/09/16
FreeBSD only:   Yes

Patches:        ftp://ftp.freebsd.org/pub/FreeBSD/CERT/patches/SA-98:07/

Vulnerable:


I.   Background    

TCP/IP connections are controlled through a series of packets that are
receieved by the two computers involved in the connection.  Old, stale
connections are reset with a packet called a RST packet.  The RST
packets have a sequence number in them that must be valid according to
certain rules in the standards.


II.  Problem Description

A denail of service attack can be launched against FreeBSD systems
running without one of the patches supplied later in this message.
Using a flaw in the interpreation of sequence numbers in the RST
packet, malicious users can terminate connections of other users at
will.


III. Impact

Some TCP connections will be broken.  This can range from a minor
inconvenience to a major problem depending on the nature of the
attackers and what they attack.  This attack requires knowledge of the
TCP connection 4-tuple (source IP, source port, destination IP and
destination port).  If even one of these items is unknown, then the
attack will not succeed.  Users without priviledge of the destination
machine, however, can find the source IP and source port numbers with
the netstat command and can effect this attack.  Also, intruders that
are able to capture raw network traffic on the network the target
machine resides will also have enough information to launch this
attack.  It is also possible for an attacker to send a huge flood of
packets, hoping that they will get lucky just once (which is all they
need to attack a specific connection).

This vulnerability has been discussed in the security list called
BUGTRAQ and exploit programs are circulating to take advantage of this
flaw.

This attack has been reported most often as being used against people
connected to irc servers.

IV.  Workaround

None.

V.   Solution

Here is the patch that will apply to 2.2-stable systems from before
September 16, 1998.  -stable systems after that date do not suffer
from this problem. It will also apply to FreeBSD 2.2.6 and 2.2.7.


    Index: tcp_input.c
    ===================================================================
    RCS file: /home/cvsup/freebsd/CVS/src/sys/netinet/tcp_input.c,v
    retrieving revision 1.54.2.10
    retrieving revision 1.54.2.11
    diff -u -r1.54.2.10 -r1.54.2.11
    --- tcp_input.c	1998/05/18 17:12:44	1.54.2.10
    +++ tcp_input.c	1998/09/16 17:35:17	1.54.2.11
    @@ -972,17 +972,99 @@
     
     	/*
     	 * States other than LISTEN or SYN_SENT.
    -	 * First check timestamp, if present.
    +	 * First check the RST flag and sequence number since reset segments
    +	 * are exempt from the timestamp and connection count tests.  This
    +	 * fixes a bug introduced by the Stevens, vol. 2, p. 960 bugfix
    +	 * below which allowed reset segments in half the sequence space
    +	 * to fall though and be processed (which gives forged reset
    +	 * segments with a random sequence number a 50 percent chance of
    +	 * killing a connection).
    +	 * Then check timestamp, if present.
     	 * Then check the connection count, if present.
     	 * Then check that at least some bytes of segment are within
     	 * receive window.  If segment begins before rcv_nxt,
     	 * drop leading data (and SYN); if nothing left, just ack.
     	 *
    +	 *
    +	 * If the RST bit is set, check the sequence number to see
    +	 * if this is a valid reset segment.
    +	 * RFC 793 page 37:
    +	 *   In all states except SYN-SENT, all reset (RST) segments
    +	 *   are validated by checking their SEQ-fields.  A reset is
    +	 *   valid if its sequence number is in the window.
    +	 * Note: this does not take into account delayed ACKs, so
    +	 *   we should test against last_ack_sent instead of rcv_nxt.
    +	 *   Also, it does not make sense to allow reset segments with
    +	 *   sequence numbers greater than last_ack_sent to be processed
    +	 *   since these sequence numbers are just the acknowledgement
    +	 *   numbers in our outgoing packets being echoed back at us,
    +	 *   and these acknowledgement numbers are monotonically
    +	 *   increasing.
    +	 * If we have multiple segments in flight, the intial reset
    +	 * segment sequence numbers will be to the left of last_ack_sent,
    +	 * but they will eventually catch up.
    +	 * In any case, it never made sense to trim reset segments to
    +	 * fit the receive window since RFC 1122 says:
    +	 *   4.2.2.12  RST Segment: RFC-793 Section 3.4
    +	 *
    +	 *    A TCP SHOULD allow a received RST segment to include data.
    +	 *
    +	 *    DISCUSSION
    +	 *         It has been suggested that a RST segment could contain
    +	 *         ASCII text that encoded and explained the cause of the
    +	 *         RST.  No standard has yet been established for such
    +	 *         data.
    +	 *
    +	 * If the reset segment passes the sequence number test examine
    +	 * the state:
    +	 *    SYN_RECEIVED STATE:
    +	 *	If passive open, return to LISTEN state.
    +	 *	If active open, inform user that connection was refused.
    +	 *    ESTABLISHED, FIN_WAIT_1, FIN_WAIT2, CLOSE_WAIT STATES:
    +	 *	Inform user that connection was reset, and close tcb.
    +	 *    CLOSING, LAST_ACK, TIME_WAIT STATES
    +	 *	Close the tcb.
    +	 *    TIME_WAIT state:
    +	 *	Drop the segment - see Stevens, vol. 2, p. 964 and
    +	 *      RFC 1337.
    +	 */
    +	if (tiflags & TH_RST) {
    +		if (tp->last_ack_sent == ti->ti_seq) {
    +			switch (tp->t_state) {
    +
    +			case TCPS_SYN_RECEIVED:
    +				so->so_error = ECONNREFUSED;
    +				goto close;
    +
    +			case TCPS_ESTABLISHED:
    +			case TCPS_FIN_WAIT_1:
    +			case TCPS_FIN_WAIT_2:
    +			case TCPS_CLOSE_WAIT:
    +				so->so_error = ECONNRESET;
    +			close:
    +				tp->t_state = TCPS_CLOSED;
    +				tcpstat.tcps_drops++;
    +				tp = tcp_close(tp);
    +				break;
    +
    +			case TCPS_CLOSING:
    +			case TCPS_LAST_ACK:
    +				tp = tcp_close(tp);
    +				break;
    +
    +			case TCPS_TIME_WAIT:
    +				break;
    +			}
    +		}
    +		goto drop;
    +	}
    +
    +	/*
     	 * RFC 1323 PAWS: If we have a timestamp reply on this segment
     	 * and it's less than ts_recent, drop it.
     	 */
    -	if ((to.to_flag & TOF_TS) != 0 && (tiflags & TH_RST) == 0 &&
    -	    tp->ts_recent && TSTMP_LT(to.to_tsval, tp->ts_recent)) {
    +	if ((to.to_flag & TOF_TS) != 0 && tp->ts_recent &&
    +	    TSTMP_LT(to.to_tsval, tp->ts_recent)) {
     
     		/* Check to see if ts_recent is over 24 days old.  */
     		if ((int)(tcp_now - tp->ts_recent_age) > TCP_PAWS_IDLE) {
    @@ -1013,10 +1095,19 @@
     	 *   RST segments do not have to comply with this.
     	 */
     	if ((tp->t_flags & (TF_REQ_CC|TF_RCVD_CC)) == (TF_REQ_CC|TF_RCVD_CC) &&
    -	    ((to.to_flag & TOF_CC) == 0 || tp->cc_recv != to.to_cc) &&
    -	    (tiflags & TH_RST) == 0)
    +	    ((to.to_flag & TOF_CC) == 0 || tp->cc_recv != to.to_cc))
      		goto dropafterack;
     
    +	/*
    +	 * In the SYN-RECEIVED state, validate that the packet belongs to
    +	 * this connection before trimming the data to fit the receive
    +	 * window.  Check the sequence number versus IRS since we know
    +	 * the sequence numbers haven't wrapped.  This is a partial fix
    +	 * for the "LAND" DoS attack.
    +	 */
    +	if (tp->t_state == TCPS_SYN_RECEIVED && SEQ_LT(ti->ti_seq, tp->irs))
    +		goto dropwithreset;
    +
     	todrop = tp->rcv_nxt - ti->ti_seq;
     	if (todrop > 0) {
     		if (tiflags & TH_SYN) {
    @@ -1128,40 +1219,6 @@
     	}
     
     	/*
    -	 * If the RST bit is set examine the state:
    -	 *    SYN_RECEIVED STATE:
    -	 *	If passive open, return to LISTEN state.
    -	 *	If active open, inform user that connection was refused.
    -	 *    ESTABLISHED, FIN_WAIT_1, FIN_WAIT2, CLOSE_WAIT STATES:
    -	 *	Inform user that connection was reset, and close tcb.
    -	 *    CLOSING, LAST_ACK, TIME_WAIT STATES
    -	 *	Close the tcb.
    -	 */
    -	if (tiflags&TH_RST) switch (tp->t_state) {
    -
    -	case TCPS_SYN_RECEIVED:
    -		so->so_error = ECONNREFUSED;
    -		goto close;
    -
    -	case TCPS_ESTABLISHED:
    -	case TCPS_FIN_WAIT_1:
    -	case TCPS_FIN_WAIT_2:
    -	case TCPS_CLOSE_WAIT:
    -		so->so_error = ECONNRESET;
    -	close:
    -		tp->t_state = TCPS_CLOSED;
    -		tcpstat.tcps_drops++;
    -		tp = tcp_close(tp);
    -		goto drop;
    -
    -	case TCPS_CLOSING:
    -	case TCPS_LAST_ACK:
    -	case TCPS_TIME_WAIT:
    -		tp = tcp_close(tp);
    -		goto drop;
    -	}
    -
    -	/*
     	 * If a SYN is in the window, then this is an
     	 * error and we send an RST and drop the connection.
     	 */
    @@ -1667,9 +1724,22 @@
     	/*
     	 * Generate an ACK dropping incoming segment if it occupies
     	 * sequence space, where the ACK reflects our state.
    -	 */
    -	if (tiflags & TH_RST)
    -		goto drop;
    +	 *
    +	 * We can now skip the test for the RST flag since all
    +	 * paths to this code happen after packets containing
    +	 * RST have been dropped.
    +	 *
    +	 * In the SYN-RECEIVED state, don't send an ACK unless the
    +	 * segment we received passes the SYN-RECEIVED ACK test.
    +	 * If it fails send a RST.  This breaks the loop in the
    +	 * "LAND" DoS attack, and also prevents an ACK storm
    +	 * between two listening ports that have been sent forged
    +	 * SYN segments, each with the source address of the other.
    +	 */
    +	if (tp->t_state == TCPS_SYN_RECEIVED && (tiflags & TH_ACK) &&
    +	    (SEQ_GT(tp->snd_una, ti->ti_ack) ||
    +	     SEQ_GT(ti->ti_ack, tp->snd_max)) )
    +		goto dropwithreset;
     #ifdef TCPDEBUG
     	if (so->so_options & SO_DEBUG)
     		tcp_trace(TA_DROP, ostate, tp, &tcp_saveti, 0);

Here is the patch to apply to 3.0-current systems from before
September 11, 1998.  This patch is known to apply to systems just
before this date, but as you move farther back in the 3.0-current
branch, it may become more difficult for this patch to apply.


    Index: tcp_input.c
    ===================================================================
    RCS file: /home/cvsup/freebsd/CVS/src/sys/netinet/tcp_input.c,v
    retrieving revision 1.80
    retrieving revision 1.81
    diff -u -r1.80 -r1.81
    --- tcp_input.c	1998/08/24 07:47:39	1.80
    +++ tcp_input.c	1998/09/11 16:04:03	1.81
    @@ -979,17 +979,99 @@
     
     	/*
     	 * States other than LISTEN or SYN_SENT.
    -	 * First check timestamp, if present.
    +	 * First check the RST flag and sequence number since reset segments
    +	 * are exempt from the timestamp and connection count tests.  This
    +	 * fixes a bug introduced by the Stevens, vol. 2, p. 960 bugfix
    +	 * below which allowed reset segments in half the sequence space
    +	 * to fall though and be processed (which gives forged reset
    +	 * segments with a random sequence number a 50 percent chance of
    +	 * killing a connection).
    +	 * Then check timestamp, if present.
     	 * Then check the connection count, if present.
     	 * Then check that at least some bytes of segment are within
     	 * receive window.  If segment begins before rcv_nxt,
     	 * drop leading data (and SYN); if nothing left, just ack.
     	 *
    +	 *
    +	 * If the RST bit is set, check the sequence number to see
    +	 * if this is a valid reset segment.
    +	 * RFC 793 page 37:
    +	 *   In all states except SYN-SENT, all reset (RST) segments
    +	 *   are validated by checking their SEQ-fields.  A reset is
    +	 *   valid if its sequence number is in the window.
    +	 * Note: this does not take into account delayed ACKs, so
    +	 *   we should test against last_ack_sent instead of rcv_nxt.
    +	 *   Also, it does not make sense to allow reset segments with
    +	 *   sequence numbers greater than last_ack_sent to be processed
    +	 *   since these sequence numbers are just the acknowledgement
    +	 *   numbers in our outgoing packets being echoed back at us,
    +	 *   and these acknowledgement numbers are monotonically
    +	 *   increasing.
    +	 * If we have multiple segments in flight, the intial reset
    +	 * segment sequence numbers will be to the left of last_ack_sent,
    +	 * but they will eventually catch up.
    +	 * In any case, it never made sense to trim reset segments to
    +	 * fit the receive window since RFC 1122 says:
    +	 *   4.2.2.12  RST Segment: RFC-793 Section 3.4
    +	 *
    +	 *    A TCP SHOULD allow a received RST segment to include data.
    +	 *
    +	 *    DISCUSSION
    +	 *         It has been suggested that a RST segment could contain
    +	 *         ASCII text that encoded and explained the cause of the
    +	 *         RST.  No standard has yet been established for such
    +	 *         data.
    +	 *
    +	 * If the reset segment passes the sequence number test examine
    +	 * the state:
    +	 *    SYN_RECEIVED STATE:
    +	 *	If passive open, return to LISTEN state.
    +	 *	If active open, inform user that connection was refused.
    +	 *    ESTABLISHED, FIN_WAIT_1, FIN_WAIT2, CLOSE_WAIT STATES:
    +	 *	Inform user that connection was reset, and close tcb.
    +	 *    CLOSING, LAST_ACK, TIME_WAIT STATES
    +	 *	Close the tcb.
    +	 *    TIME_WAIT state:
    +	 *	Drop the segment - see Stevens, vol. 2, p. 964 and
    +	 *      RFC 1337.
    +	 */
    +	if (tiflags & TH_RST) {
    +		if (tp->last_ack_sent == ti->ti_seq) {
    +			switch (tp->t_state) {
    +
    +			case TCPS_SYN_RECEIVED:
    +				so->so_error = ECONNREFUSED;
    +				goto close;
    +
    +			case TCPS_ESTABLISHED:
    +			case TCPS_FIN_WAIT_1:
    +			case TCPS_FIN_WAIT_2:
    +			case TCPS_CLOSE_WAIT:
    +				so->so_error = ECONNRESET;
    +			close:
    +				tp->t_state = TCPS_CLOSED;
    +				tcpstat.tcps_drops++;
    +				tp = tcp_close(tp);
    +				break;
    +
    +			case TCPS_CLOSING:
    +			case TCPS_LAST_ACK:
    +				tp = tcp_close(tp);
    +				break;
    +
    +			case TCPS_TIME_WAIT:
    +				break;
    +			}
    +		}
    +		goto drop;
    +	}
    +
    +	/*
     	 * RFC 1323 PAWS: If we have a timestamp reply on this segment
     	 * and it's less than ts_recent, drop it.
     	 */
    -	if ((to.to_flag & TOF_TS) != 0 && (tiflags & TH_RST) == 0 &&
    -	    tp->ts_recent && TSTMP_LT(to.to_tsval, tp->ts_recent)) {
    +	if ((to.to_flag & TOF_TS) != 0 && tp->ts_recent &&
    +	    TSTMP_LT(to.to_tsval, tp->ts_recent)) {
     
     		/* Check to see if ts_recent is over 24 days old.  */
     		if ((int)(tcp_now - tp->ts_recent_age) > TCP_PAWS_IDLE) {
    @@ -1020,10 +1102,19 @@
     	 *   RST segments do not have to comply with this.
     	 */
     	if ((tp->t_flags & (TF_REQ_CC|TF_RCVD_CC)) == (TF_REQ_CC|TF_RCVD_CC) &&
    -	    ((to.to_flag & TOF_CC) == 0 || tp->cc_recv != to.to_cc) &&
    -	    (tiflags & TH_RST) == 0)
    +	    ((to.to_flag & TOF_CC) == 0 || tp->cc_recv != to.to_cc))
      		goto dropafterack;
     
    +	/*
    +	 * In the SYN-RECEIVED state, validate that the packet belongs to
    +	 * this connection before trimming the data to fit the receive
    +	 * window.  Check the sequence number versus IRS since we know
    +	 * the sequence numbers haven't wrapped.  This is a partial fix
    +	 * for the "LAND" DoS attack.
    +	 */
    +	if (tp->t_state == TCPS_SYN_RECEIVED && SEQ_LT(ti->ti_seq, tp->irs))
    +		goto dropwithreset;
    +
     	todrop = tp->rcv_nxt - ti->ti_seq;
     	if (todrop > 0) {
     		if (tiflags & TH_SYN) {
    @@ -1135,40 +1226,6 @@
     	}
     
     	/*
    -	 * If the RST bit is set examine the state:
    -	 *    SYN_RECEIVED STATE:
    -	 *	If passive open, return to LISTEN state.
    -	 *	If active open, inform user that connection was refused.
    -	 *    ESTABLISHED, FIN_WAIT_1, FIN_WAIT2, CLOSE_WAIT STATES:
    -	 *	Inform user that connection was reset, and close tcb.
    -	 *    CLOSING, LAST_ACK, TIME_WAIT STATES
    -	 *	Close the tcb.
    -	 */
    -	if (tiflags&TH_RST) switch (tp->t_state) {
    -
    -	case TCPS_SYN_RECEIVED:
    -		so->so_error = ECONNREFUSED;
    -		goto close;
    -
    -	case TCPS_ESTABLISHED:
    -	case TCPS_FIN_WAIT_1:
    -	case TCPS_FIN_WAIT_2:
    -	case TCPS_CLOSE_WAIT:
    -		so->so_error = ECONNRESET;
    -	close:
    -		tp->t_state = TCPS_CLOSED;
    -		tcpstat.tcps_drops++;
    -		tp = tcp_close(tp);
    -		goto drop;
    -
    -	case TCPS_CLOSING:
    -	case TCPS_LAST_ACK:
    -	case TCPS_TIME_WAIT:
    -		tp = tcp_close(tp);
    -		goto drop;
    -	}
    -
    -	/*
     	 * If a SYN is in the window, then this is an
     	 * error and we send an RST and drop the connection.
     	 */
    @@ -1673,9 +1730,22 @@
     	/*
     	 * Generate an ACK dropping incoming segment if it occupies
     	 * sequence space, where the ACK reflects our state.
    -	 */
    -	if (tiflags & TH_RST)
    -		goto drop;
    +	 *
    +	 * We can now skip the test for the RST flag since all
    +	 * paths to this code happen after packets containing
    +	 * RST have been dropped.
    +	 *
    +	 * In the SYN-RECEIVED state, don't send an ACK unless the
    +	 * segment we received passes the SYN-RECEIVED ACK test.
    +	 * If it fails send a RST.  This breaks the loop in the
    +	 * "LAND" DoS attack, and also prevents an ACK storm
    +	 * between two listening ports that have been sent forged
    +	 * SYN segments, each with the source address of the other.
    +	 */
    +	if (tp->t_state == TCPS_SYN_RECEIVED && (tiflags & TH_ACK) &&
    +	    (SEQ_GT(tp->snd_una, ti->ti_ack) ||
    +	     SEQ_GT(ti->ti_ack, tp->snd_max)) )
    +		goto dropwithreset;
     #ifdef TCPDEBUG
     	if (so->so_options & SO_DEBUG)
     		tcp_trace(TA_DROP, ostate, tp, &tcp_saveti, 0);

=============================================================================
FreeBSD, Inc.

Web Site:                       http://www.freebsd.org/
Confidential contacts:          security-officer@freebsd.org
Security notifications:         security-notifications@freebsd.org
Security public discussion:     freebsd-security@freebsd.org
PGP Key:                ftp://ftp.freebsd.org/pub/FreeBSD/CERT/public_key.asc

Notice: Any patches in this document may not apply cleanly due to
        modifications caused by digital signature or mailer software.
        Please reference the URL listed at the top of this document
        for original copies of all patches if necessary.
=============================================================================


-----BEGIN PGP SIGNATURE-----
Version: 2.6.3ia
Charset: noconv

iQCVAwUBNiOat1UuHi5z0oilAQHd+gP/ejply8nSa1eZ4Fntvs7AI0J4+A00INa6
taew67WuQt2a6vMfjtqjYMjt09BCaxWgrKftWfb/sn9vF3WNIZ313xOf0NBpdLAm
mTctCLssy/1fw1wmeNBrrA2XyhsmiobZ6KPDOzqKR+xHF9gLQh7ygDc8dBsXUQMp
3kejs4imNb4=
=cP5N
-----END PGP SIGNATURE-----