Skip to content

Commit 0b53d46

Browse files
author
Gerrit Renker
committed
dccp: fix the adjustments to AWL and SWL
This fixes a problem and a potential loophole with regard to seqno/ackno validity: currently the initial adjustments to AWL/SWL are only performed once 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 it is better to perform that safety check each time SWL/AWL are updated, as implemented by the patch. 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()). Signed-off-by: Gerrit Renker <gerrit@erg.abdn.ac.uk>
1 parent 0ed8ddf commit 0b53d46

3 files changed

Lines changed: 35 additions & 33 deletions

File tree

‎net/dccp/dccp.h‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,23 @@ static inline void dccp_update_gsr(struct sock *sk, u64 seq)
414414
dp->dccps_gsr = seq;
415415
/* Sequence validity window depends on remote Sequence Window (7.5.1) */
416416
dp->dccps_swl = SUB48(ADD48(dp->dccps_gsr, 1), dp->dccps_r_seq_win / 4);
417+
/*
418+
* Adjust SWL so that it is not below ISR. In contrast to RFC 4340,
419+
* 7.5.1 we perform this check beyond the initial handshake: W/W' are
420+
* always > 32, so for the first W/W' packets in the lifetime of a
421+
* connection we always have to adjust SWL.
422+
* A second reason why we are doing this is that the window depends on
423+
* the feature-remote value of Sequence Window: nothing stops the peer
424+
* from updating this value while we are busy adjusting SWL for the
425+
* first W packets (we would have to count from scratch again then).
426+
* Therefore it is safer to always make sure that the Sequence Window
427+
* is not artificially extended by a peer who grows SWL downwards by
428+
* continually updating the feature-remote Sequence-Window.
429+
* If sequence numbers wrap it is bad luck. But that will take a while
430+
* (48 bit), and this measure prevents Sequence-number attacks.
431+
*/
432+
if (before48(dp->dccps_swl, dp->dccps_isr))
433+
dp->dccps_swl = dp->dccps_isr;
417434
dp->dccps_swh = ADD48(dp->dccps_gsr, (3 * dp->dccps_r_seq_win) / 4);
418435
}
419436

@@ -424,6 +441,9 @@ static inline void dccp_update_gss(struct sock *sk, u64 seq)
424441
dp->dccps_gss = seq;
425442
/* Ack validity window depends on local Sequence Window value (7.5.1) */
426443
dp->dccps_awl = SUB48(ADD48(dp->dccps_gss, 1), dp->dccps_l_seq_win);
444+
/* Adjust AWL so that it is not below ISS - see comment above for SWL */
445+
if (before48(dp->dccps_awl, dp->dccps_iss))
446+
dp->dccps_awl = dp->dccps_iss;
427447
dp->dccps_awh = dp->dccps_gss;
428448
}
429449

‎net/dccp/input.c‎

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -441,20 +441,14 @@ static int dccp_rcv_request_sent_state_process(struct sock *sk,
441441
kfree_skb(sk->sk_send_head);
442442
sk->sk_send_head = NULL;
443443

444-
dp->dccps_isr = DCCP_SKB_CB(skb)->dccpd_seq;
445-
dccp_update_gsr(sk, dp->dccps_isr);
446444
/*
447-
* SWL and AWL are initially adjusted so that they are not less than
448-
* the initial Sequence Numbers received and sent, respectively:
449-
* SWL := max(GSR + 1 - floor(W/4), ISR),
450-
* AWL := max(GSS - W' + 1, ISS).
451-
* These adjustments MUST be applied only at the beginning of the
452-
* connection.
453-
*
454-
* AWL was adjusted in dccp_v4_connect -acme
445+
* Set ISR, GSR from packet. ISS was set in dccp_v{4,6}_connect
446+
* and GSS in dccp_transmit_skb(). Setting AWL/AWH and SWL/SWH
447+
* is done as part of activating the feature values below, since
448+
* these settings depend on the local/remote Sequence Window
449+
* features, which were undefined or not confirmed until now.
455450
*/
456-
dccp_set_seqno(&dp->dccps_swl,
457-
max48(dp->dccps_swl, dp->dccps_isr));
451+
dp->dccps_gsr = dp->dccps_isr = DCCP_SKB_CB(skb)->dccpd_seq;
458452

459453
dccp_sync_mss(sk, icsk->icsk_pmtu_cookie);
460454

‎net/dccp/minisocks.c‎

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -121,30 +121,18 @@ struct sock *dccp_create_openreq_child(struct sock *sk,
121121
*
122122
* Choose S.ISS (initial seqno) or set from Init Cookies
123123
* Initialize S.GAR := S.ISS
124-
* Set S.ISR, S.GSR, S.SWL, S.SWH from packet or Init Cookies
125-
*/
126-
newdp->dccps_gar = newdp->dccps_iss = dreq->dreq_iss;
127-
dccp_update_gss(newsk, dreq->dreq_iss);
128-
129-
newdp->dccps_isr = dreq->dreq_isr;
130-
dccp_update_gsr(newsk, dreq->dreq_isr);
131-
132-
/*
133-
* SWL and AWL are initially adjusted so that they are not less than
134-
* the initial Sequence Numbers received and sent, respectively:
135-
* SWL := max(GSR + 1 - floor(W/4), ISR),
136-
* AWL := max(GSS - W' + 1, ISS).
137-
* These adjustments MUST be applied only at the beginning of the
138-
* connection.
124+
* Set S.ISR, S.GSR from packet (or Init Cookies)
125+
*
126+
* Setting AWL/AWH and SWL/SWH happens as part of the feature
127+
* activation below, as these windows all depend on the local
128+
* and remote Sequence Window feature values (7.5.2).
139129
*/
140-
dccp_set_seqno(&newdp->dccps_swl,
141-
max48(newdp->dccps_swl, newdp->dccps_isr));
142-
dccp_set_seqno(&newdp->dccps_awl,
143-
max48(newdp->dccps_awl, newdp->dccps_iss));
130+
newdp->dccps_gss = newdp->dccps_iss = dreq->dreq_iss;
131+
newdp->dccps_gar = newdp->dccps_iss;
132+
newdp->dccps_gsr = newdp->dccps_isr = dreq->dreq_isr;
144133

145134
/*
146-
* Activate features after initialising the sequence numbers,
147-
* since CCID initialisation may depend on GSS, ISR, ISS etc.
135+
* Activate features: initialise CCIDs, sequence windows etc.
148136
*/
149137
if (dccp_feat_activate_values(newsk, &dreq->dreq_featneg)) {
150138
/* It is still raw copy of parent, so invalidate

0 commit comments

Comments
 (0)