aboutsummaryrefslogtreecommitdiffstats
path: root/net/dccp
diff options
context:
space:
mode:
authorGerrit Renker <gerrit@erg.abdn.ac.uk>2008-09-04 01:30:19 -0400
committerGerrit Renker <gerrit@erg.abdn.ac.uk>2008-09-04 01:45:35 -0400
commitbfbddd085a5bced6efb9e1bc4d029438f9639784 (patch)
tree2187b8a4a2d4864419bd5897ccfdff57a6bc3b48 /net/dccp
parent2975abd251d795810932b20354729ba236d95bf9 (diff)
dccp: Fix the adjustments to AWL and SWL
This fixes a problem and a potential loophole with regard to seqno/ackno validity: the problem is that the initial adjustments to AWL/SWL were only performed at the begin of the connection, during the handshake. Since the Sequence Window feature is always greater than Wmin=32 (7.5.2), it is however necessary to perform these adjustments at least for the first W/W' (variables as per 7.5.1) packets in the lifetime of a connection. This requirement is complicated by the fact that W/W' can change at any time during the lifetime of a connection. Therefore the consequence is to perform this safety check each time SWL/AWL are updated. A second problem solved by this patch is that the remote/local Sequence Window feature values (which set the bounds for AWL/SWL/SWH) are undefined until the feature negotiation has completed. During the initial handshake we have more stringent sequence number protection, the changes added by this patch effect that {A,S}W{L,H} are within the correct bounds at the instant that feature negotiation completes (since the SeqWin feature activation handlers call dccp_update_gsr/gss()). A detailed rationale is below -- can be removed from the commit message. 1. Server sequence number checks during initial handshake --------------------------------------------------------- The server can not use the fields of the listening socket for seqno/ackno checks and thus needs to store all relevant information on a per-connection basis on the dccp_request socket. This is a size-constrained structure and has currently only ISS (dreq_iss) and ISR (dreq_isr) defined. Adding further fields (SW{L,H}, AW{L,H}) would increase the size of the struct and it is questionable whether this will have any practical gain. The currently implemented solution is as follows. * receiving first Request: dccp_v{4,6}_conn_request sets ISR := P.seqno, ISS := dccp_v{4,6}_init_sequence() * sending first Response: dccp_v{4,6}_send_response via dccp_make_response() sets P.seqno := ISS, sets P.ackno := ISR * receiving retransmitted Request: dccp_check_req() overrides ISR := P.seqno * answering retransmitted Request: dccp_make_response() sets ISS += 1, otherwise as per first Response * completing the handshake: succeeds in dccp_check_req() for the first Ack where P.ackno == ISS (P.seqno is not tested) * creating child socket: ISS, ISR are copied from the request_sock This solution will succeed whenever the server can receive the Request and the subsequent Ack in succession, without retransmissions. If there is packet loss, the client needs to retransmit until this condition succeeds; it will otherwise eventually give up. Adding further fields to the request_sock could increase the robustness a bit, in that it would make possible to let a reordered Ack (from a retransmitted Response) pass. The argument against such a solution is that if the packet loss is not persistent and an Ack gets through, why not wait for the one answering the original response: if the loss is persistent, it is probably better to not start the connection in the first place. Long story short: the present design (by Arnaldo) is simple and will likely work just as well as a more complicated solution. As a consequence, {A,S}W{L,H} are not needed until the moment the request_sock is cloned into the accept queue. At that stage feature negotiation has completed, so that the values for the local and remote Sequence Window feature (7.5.2) are known, i.e. we are now in a better position to compute {A,S}W{L,H}. 2. Client sequence number checks during initial handshake --------------------------------------------------------- Until entering PARTOPEN the client does not need the adjustments, since it constrains the Ack window to the packet it sent. * sending first Request: dccp_v{4,6}_connect() choose ISS, dccp_connect() then sets GAR := ISS (as per 8.5), dccp_transmit_skb() (with the previous bug fix) sets GSS := ISS, AWL := ISS, AWH := GSS * n-th retransmitted Request (with previous patch): dccp_retransmit_skb() via timer calls dccp_transmit_skb(), which sets GSS := ISS+n and then AWL := ISS, AWH := ISS+n * receiving any Response: dccp_rcv_request_sent_state_process() -- accepts packet if AWL <= P.ackno <= AWH; -- sets GSR = ISR = P.seqno * sending the Ack completing the handshake: dccp_send_ack() calls dccp_transmit_skb(), which sets GSS += 1 and AWL := ISS, AWH := GSS Signed-off-by: Gerrit Renker <gerrit@erg.abdn.ac.uk>
Diffstat (limited to 'net/dccp')
-rw-r--r--net/dccp/dccp.h20
-rw-r--r--net/dccp/input.c18
-rw-r--r--net/dccp/minisocks.c30
3 files changed, 35 insertions, 33 deletions
diff --git a/net/dccp/dccp.h b/net/dccp/dccp.h
index f9ed0cbd1bf3..e4d6e76ced41 100644
--- a/net/dccp/dccp.h
+++ b/net/dccp/dccp.h
@@ -415,6 +415,23 @@ static inline void dccp_update_gsr(struct sock *sk, u64 seq)
415 dp->dccps_gsr = seq; 415 dp->dccps_gsr = seq;
416 /* Sequence validity window depends on remote Sequence Window (7.5.1) */ 416 /* Sequence validity window depends on remote Sequence Window (7.5.1) */
417 dp->dccps_swl = SUB48(ADD48(dp->dccps_gsr, 1), dp->dccps_r_seq_win / 4); 417 dp->dccps_swl = SUB48(ADD48(dp->dccps_gsr, 1), dp->dccps_r_seq_win / 4);
418 /*
419 * Adjust SWL so that it is not below ISR. In contrast to RFC 4340,
420 * 7.5.1 we perform this check beyond the initial handshake: W/W' are
421 * always > 32, so for the first W/W' packets in the lifetime of a
422 * connection we always have to adjust SWL.
423 * A second reason why we are doing this is that the window depends on
424 * the feature-remote value of Sequence Window: nothing stops the peer
425 * from updating this value while we are busy adjusting SWL for the
426 * first W packets (we would have to count from scratch again then).
427 * Therefore it is safer to always make sure that the Sequence Window
428 * is not artificially extended by a peer who grows SWL downwards by
429 * continually updating the feature-remote Sequence-Window.
430 * If sequence numbers wrap it is bad luck. But that will take a while
431 * (48 bit), and this measure prevents Sequence-number attacks.
432 */
433 if (before48(dp->dccps_swl, dp->dccps_isr))
434 dp->dccps_swl = dp->dccps_isr;
418 dp->dccps_swh = ADD48(dp->dccps_gsr, (3 * dp->dccps_r_seq_win) / 4); 435 dp->dccps_swh = ADD48(dp->dccps_gsr, (3 * dp->dccps_r_seq_win) / 4);
419} 436}
420 437
@@ -425,6 +442,9 @@ static inline void dccp_update_gss(struct sock *sk, u64 seq)
425 dp->dccps_gss = seq; 442 dp->dccps_gss = seq;
426 /* Ack validity window depends on local Sequence Window value (7.5.1) */ 443 /* Ack validity window depends on local Sequence Window value (7.5.1) */
427 dp->dccps_awl = SUB48(ADD48(dp->dccps_gss, 1), dp->dccps_l_seq_win); 444 dp->dccps_awl = SUB48(ADD48(dp->dccps_gss, 1), dp->dccps_l_seq_win);
445 /* Adjust AWL so that it is not below ISS - see comment above for SWL */
446 if (before48(dp->dccps_awl, dp->dccps_iss))
447 dp->dccps_awl = dp->dccps_iss;
428 dp->dccps_awh = dp->dccps_gss; 448 dp->dccps_awh = dp->dccps_gss;
429} 449}
430 450
diff --git a/net/dccp/input.c b/net/dccp/input.c
index 5eb443f656c1..e3f43d55e3ce 100644
--- a/net/dccp/input.c
+++ b/net/dccp/input.c
@@ -440,20 +440,14 @@ static int dccp_rcv_request_sent_state_process(struct sock *sk,
440 kfree_skb(sk->sk_send_head); 440 kfree_skb(sk->sk_send_head);
441 sk->sk_send_head = NULL; 441 sk->sk_send_head = NULL;
442 442
443 dp->dccps_isr = DCCP_SKB_CB(skb)->dccpd_seq;
444 dccp_update_gsr(sk, dp->dccps_isr);
445 /* 443 /*
446 * SWL and AWL are initially adjusted so that they are not less than 444 * Set ISR, GSR from packet. ISS was set in dccp_v{4,6}_connect
447 * the initial Sequence Numbers received and sent, respectively: 445 * and GSS in dccp_transmit_skb(). Setting AWL/AWH and SWL/SWH
448 * SWL := max(GSR + 1 - floor(W/4), ISR), 446 * is done as part of activating the feature values below, since
449 * AWL := max(GSS - W' + 1, ISS). 447 * these settings depend on the local/remote Sequence Window
450 * These adjustments MUST be applied only at the beginning of the 448 * features, which were undefined or not confirmed until now.
451 * connection.
452 *
453 * AWL was adjusted in dccp_v4_connect -acme
454 */ 449 */
455 dccp_set_seqno(&dp->dccps_swl, 450 dp->dccps_gsr = dp->dccps_isr = DCCP_SKB_CB(skb)->dccpd_seq;
456 max48(dp->dccps_swl, dp->dccps_isr));
457 451
458 dccp_sync_mss(sk, icsk->icsk_pmtu_cookie); 452 dccp_sync_mss(sk, icsk->icsk_pmtu_cookie);
459 453
diff --git a/net/dccp/minisocks.c b/net/dccp/minisocks.c
index 0ecb19c5e8ce..f4d9c8f60ede 100644
--- a/net/dccp/minisocks.c
+++ b/net/dccp/minisocks.c
@@ -120,30 +120,18 @@ struct sock *dccp_create_openreq_child(struct sock *sk,
120 * 120 *
121 * Choose S.ISS (initial seqno) or set from Init Cookies 121 * Choose S.ISS (initial seqno) or set from Init Cookies
122 * Initialize S.GAR := S.ISS 122 * Initialize S.GAR := S.ISS
123 * Set S.ISR, S.GSR, S.SWL, S.SWH from packet or Init Cookies 123 * Set S.ISR, S.GSR from packet (or Init Cookies)
124 */ 124 *
125 newdp->dccps_gar = newdp->dccps_iss = dreq->dreq_iss; 125 * Setting AWL/AWH and SWL/SWH happens as part of the feature
126 dccp_update_gss(newsk, dreq->dreq_iss); 126 * activation below, as these windows all depend on the local
127 127 * and remote Sequence Window feature values (7.5.2).
128 newdp->dccps_isr = dreq->dreq_isr;
129 dccp_update_gsr(newsk, dreq->dreq_isr);
130
131 /*
132 * SWL and AWL are initially adjusted so that they are not less than
133 * the initial Sequence Numbers received and sent, respectively:
134 * SWL := max(GSR + 1 - floor(W/4), ISR),
135 * AWL := max(GSS - W' + 1, ISS).
136 * These adjustments MUST be applied only at the beginning of the
137 * connection.
138 */ 128 */
139 dccp_set_seqno(&newdp->dccps_swl, 129 newdp->dccps_gss = newdp->dccps_iss = dreq->dreq_iss;
140 max48(newdp->dccps_swl, newdp->dccps_isr)); 130 newdp->dccps_gar = newdp->dccps_iss;
141 dccp_set_seqno(&newdp->dccps_awl, 131 newdp->dccps_gsr = newdp->dccps_isr = dreq->dreq_isr;
142 max48(newdp->dccps_awl, newdp->dccps_iss));
143 132
144 /* 133 /*
145 * Activate features after initialising the sequence numbers, 134 * Activate features: initialise CCIDs, sequence windows etc.
146 * since CCID initialisation may depend on GSS, ISR, ISS etc.
147 */ 135 */
148 if (dccp_feat_activate_values(newsk, &dreq->dreq_featneg)) { 136 if (dccp_feat_activate_values(newsk, &dreq->dreq_featneg)) {
149 /* It is still raw copy of parent, so invalidate 137 /* It is still raw copy of parent, so invalidate