aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGerrit Renker <gerrit@erg.abdn.ac.uk>2007-09-26 10:31:49 -0400
committerDavid S. Miller <davem@sunset.davemloft.net>2007-10-10 19:52:43 -0400
commita94f0f970549e63e54c80c4509db299c514d8c11 (patch)
tree3b9421fc70e00c16ed57ef4330b24504b04ae309
parentee1a15922d356aff0e31bf9bb9088ab346b8033a (diff)
[DCCP]: Rate-limit DCCP-Syncs
This implements a SHOULD from RFC 4340, 7.5.4: "To protect against denial-of-service attacks, DCCP implementations SHOULD impose a rate limit on DCCP-Syncs sent in response to sequence-invalid packets, such as not more than eight DCCP-Syncs per second." The rate-limit is maintained on a per-socket basis. This is a more stringent policy than enforcing the rate-limit on a per-source-address basis and protects against attacks with forged source addresses. Moreover, the mechanism is deliberately kept simple. In contrast to xrlim_allow(), bursts of Sync packets in reply to sequence-invalid packets are not supported. This foils such attacks where the receipt of a Sync triggers further sequence-invalid packets. (I have tested this mechanism against xrlim_allow algorithm for Syncs, permitting bursts just increases the problems.) In order to keep flexibility, the timeout parameter can be set via sysctl; and the whole mechanism can even be disabled (which is however not recommended). The algorithm in this patch has been improved with regard to wrapping issues thanks to a suggestion by Arnaldo. Commiter note: Rate limited the step 6 DCCP_WARN too, as it says we're sending a sync. Signed-off-by: Gerrit Renker <gerrit@erg.abdn.ac.uk> Signed-off-by: Ian McDonald <ian.mcdonald@jandi.co.nz> Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
-rw-r--r--Documentation/networking/dccp.txt5
-rw-r--r--include/linux/dccp.h2
-rw-r--r--net/dccp/dccp.h1
-rw-r--r--net/dccp/input.c29
-rw-r--r--net/dccp/proto.c1
-rw-r--r--net/dccp/sysctl.c10
6 files changed, 39 insertions, 9 deletions
diff --git a/Documentation/networking/dccp.txt b/Documentation/networking/dccp.txt
index 4504cc59e405..477026ae0ffb 100644
--- a/Documentation/networking/dccp.txt
+++ b/Documentation/networking/dccp.txt
@@ -112,6 +112,11 @@ tx_qlen = 5
112 The size of the transmit buffer in packets. A value of 0 corresponds 112 The size of the transmit buffer in packets. A value of 0 corresponds
113 to an unbounded transmit buffer. 113 to an unbounded transmit buffer.
114 114
115sync_ratelimit = 125 ms
116 The timeout between subsequent DCCP-Sync packets sent in response to
117 sequence-invalid packets on the same socket (RFC 4340, 7.5.4). The unit
118 of this parameter is milliseconds; a value of 0 disables rate-limiting.
119
115Notes 120Notes
116===== 121=====
117 122
diff --git a/include/linux/dccp.h b/include/linux/dccp.h
index 20e0717aa8e1..4ed82e2c9f65 100644
--- a/include/linux/dccp.h
+++ b/include/linux/dccp.h
@@ -470,6 +470,7 @@ struct dccp_ackvec;
470 * @dccps_pcrlen - receiver partial checksum coverage (via sockopt) 470 * @dccps_pcrlen - receiver partial checksum coverage (via sockopt)
471 * @dccps_ndp_count - number of Non Data Packets since last data packet 471 * @dccps_ndp_count - number of Non Data Packets since last data packet
472 * @dccps_mss_cache - current value of MSS (path MTU minus header sizes) 472 * @dccps_mss_cache - current value of MSS (path MTU minus header sizes)
473 * @dccps_rate_last - timestamp for rate-limiting DCCP-Sync (RFC 4340, 7.5.4)
473 * @dccps_minisock - associated minisock (accessed via dccp_msk) 474 * @dccps_minisock - associated minisock (accessed via dccp_msk)
474 * @dccps_hc_rx_ackvec - rx half connection ack vector 475 * @dccps_hc_rx_ackvec - rx half connection ack vector
475 * @dccps_hc_rx_ccid - CCID used for the receiver (or receiving half-connection) 476 * @dccps_hc_rx_ccid - CCID used for the receiver (or receiving half-connection)
@@ -505,6 +506,7 @@ struct dccp_sock {
505 __u16 dccps_pcrlen; 506 __u16 dccps_pcrlen;
506 unsigned long dccps_ndp_count; 507 unsigned long dccps_ndp_count;
507 __u32 dccps_mss_cache; 508 __u32 dccps_mss_cache;
509 unsigned long dccps_rate_last;
508 struct dccp_minisock dccps_minisock; 510 struct dccp_minisock dccps_minisock;
509 struct dccp_ackvec *dccps_hc_rx_ackvec; 511 struct dccp_ackvec *dccps_hc_rx_ackvec;
510 struct ccid *dccps_hc_rx_ccid; 512 struct ccid *dccps_hc_rx_ccid;
diff --git a/net/dccp/dccp.h b/net/dccp/dccp.h
index e28220183208..a602d9212c64 100644
--- a/net/dccp/dccp.h
+++ b/net/dccp/dccp.h
@@ -92,6 +92,7 @@ extern int sysctl_dccp_feat_ack_ratio;
92extern int sysctl_dccp_feat_send_ack_vector; 92extern int sysctl_dccp_feat_send_ack_vector;
93extern int sysctl_dccp_feat_send_ndp_count; 93extern int sysctl_dccp_feat_send_ndp_count;
94extern int sysctl_dccp_tx_qlen; 94extern int sysctl_dccp_tx_qlen;
95extern int sysctl_dccp_sync_ratelimit;
95 96
96/* 97/*
97 * 48-bit sequence number arithmetic (signed and unsigned) 98 * 48-bit sequence number arithmetic (signed and unsigned)
diff --git a/net/dccp/input.c b/net/dccp/input.c
index 86ad3ba0649a..19d7e1dbd87e 100644
--- a/net/dccp/input.c
+++ b/net/dccp/input.c
@@ -122,6 +122,23 @@ static int dccp_check_seqno(struct sock *sk, struct sk_buff *skb)
122 (ackno != DCCP_PKT_WITHOUT_ACK_SEQ)) 122 (ackno != DCCP_PKT_WITHOUT_ACK_SEQ))
123 dp->dccps_gar = ackno; 123 dp->dccps_gar = ackno;
124 } else { 124 } else {
125 unsigned long now = jiffies;
126 /*
127 * Step 6: Check sequence numbers
128 * Otherwise,
129 * If P.type == Reset,
130 * Send Sync packet acknowledging S.GSR
131 * Otherwise,
132 * Send Sync packet acknowledging P.seqno
133 * Drop packet and return
134 *
135 * These Syncs are rate-limited as per RFC 4340, 7.5.4:
136 * at most 1 / (dccp_sync_rate_limit * HZ) Syncs per second.
137 */
138 if (time_before(now, (dp->dccps_rate_last +
139 sysctl_dccp_sync_ratelimit)))
140 return 0;
141
125 DCCP_WARN("DCCP: Step 6 failed for %s packet, " 142 DCCP_WARN("DCCP: Step 6 failed for %s packet, "
126 "(LSWL(%llu) <= P.seqno(%llu) <= S.SWH(%llu)) and " 143 "(LSWL(%llu) <= P.seqno(%llu) <= S.SWH(%llu)) and "
127 "(P.ackno %s or LAWL(%llu) <= P.ackno(%llu) <= S.AWH(%llu), " 144 "(P.ackno %s or LAWL(%llu) <= P.ackno(%llu) <= S.AWH(%llu), "
@@ -132,15 +149,9 @@ static int dccp_check_seqno(struct sock *sk, struct sk_buff *skb)
132 : "exists", 149 : "exists",
133 (unsigned long long) lawl, (unsigned long long) ackno, 150 (unsigned long long) lawl, (unsigned long long) ackno,
134 (unsigned long long) dp->dccps_awh); 151 (unsigned long long) dp->dccps_awh);
135 /* 152
136 * Step 6: Check sequence numbers 153 dp->dccps_rate_last = now;
137 * Otherwise, 154
138 * If P.type == Reset,
139 * Send Sync packet acknowledging S.GSR
140 * Otherwise,
141 * Send Sync packet acknowledging P.seqno
142 * Drop packet and return
143 */
144 if (dh->dccph_type == DCCP_PKT_RESET) 155 if (dh->dccph_type == DCCP_PKT_RESET)
145 seqno = dp->dccps_gsr; 156 seqno = dp->dccps_gsr;
146 dccp_send_sync(sk, seqno, DCCP_PKT_SYNC); 157 dccp_send_sync(sk, seqno, DCCP_PKT_SYNC);
diff --git a/net/dccp/proto.c b/net/dccp/proto.c
index 14ec1d21452c..604de8bfa068 100644
--- a/net/dccp/proto.c
+++ b/net/dccp/proto.c
@@ -219,6 +219,7 @@ int dccp_init_sock(struct sock *sk, const __u8 ctl_sock_initialized)
219 sk->sk_write_space = dccp_write_space; 219 sk->sk_write_space = dccp_write_space;
220 icsk->icsk_sync_mss = dccp_sync_mss; 220 icsk->icsk_sync_mss = dccp_sync_mss;
221 dp->dccps_mss_cache = 536; 221 dp->dccps_mss_cache = 536;
222 dp->dccps_rate_last = jiffies;
222 dp->dccps_role = DCCP_ROLE_UNDEFINED; 223 dp->dccps_role = DCCP_ROLE_UNDEFINED;
223 dp->dccps_service = DCCP_SERVICE_CODE_IS_ABSENT; 224 dp->dccps_service = DCCP_SERVICE_CODE_IS_ABSENT;
224 dp->dccps_l_ack_ratio = dp->dccps_r_ack_ratio = 1; 225 dp->dccps_l_ack_ratio = dp->dccps_r_ack_ratio = 1;
diff --git a/net/dccp/sysctl.c b/net/dccp/sysctl.c
index 1260aabac5e1..9364b2fb4dbd 100644
--- a/net/dccp/sysctl.c
+++ b/net/dccp/sysctl.c
@@ -18,6 +18,9 @@
18#error This file should not be compiled without CONFIG_SYSCTL defined 18#error This file should not be compiled without CONFIG_SYSCTL defined
19#endif 19#endif
20 20
21/* rate-limit for syncs in reply to sequence-invalid packets; RFC 4340, 7.5.4 */
22int sysctl_dccp_sync_ratelimit __read_mostly = HZ / 8;
23
21static struct ctl_table dccp_default_table[] = { 24static struct ctl_table dccp_default_table[] = {
22 { 25 {
23 .procname = "seq_window", 26 .procname = "seq_window",
@@ -89,6 +92,13 @@ static struct ctl_table dccp_default_table[] = {
89 .mode = 0644, 92 .mode = 0644,
90 .proc_handler = proc_dointvec, 93 .proc_handler = proc_dointvec,
91 }, 94 },
95 {
96 .procname = "sync_ratelimit",
97 .data = &sysctl_dccp_sync_ratelimit,
98 .maxlen = sizeof(sysctl_dccp_sync_ratelimit),
99 .mode = 0644,
100 .proc_handler = proc_dointvec_ms_jiffies,
101 },
92 102
93 { .ctl_name = 0, } 103 { .ctl_name = 0, }
94}; 104};