]> git.karo-electronics.de Git - mv-sheeva.git/commitdiff
syncookies: check decoded options against sysctl settings
authorFlorian Westphal <fw@strlen.de>
Wed, 16 Jun 2010 21:42:15 +0000 (14:42 -0700)
committerDavid S. Miller <davem@davemloft.net>
Wed, 16 Jun 2010 21:42:15 +0000 (14:42 -0700)
Discard the ACK if we find options that do not match current sysctl
settings.

Previously it was possible to create a connection with sack, wscale,
etc. enabled even if the feature was disabled via sysctl.

Also remove an unneeded call to tcp_sack_reset() in
cookie_check_timestamp: Both call sites (cookie_v4_check,
cookie_v6_check) zero "struct tcp_options_received", hand it to
tcp_parse_options() (which does not change tcp_opt->num_sacks/dsack)
and then call cookie_check_timestamp().

Even if num_sacks/dsacks were changed, the structure is allocated on
the stack and after cookie_check_timestamp returns only a few selected
members are copied to the inet_request_sock.

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/tcp.h
net/ipv4/syncookies.c
net/ipv6/syncookies.c

index 9e68e25c8b822d8715b95f047362d6fef5795ad0..18c246c9b009c49096e0ad2827ae1e0458c6d5ec 100644 (file)
@@ -464,7 +464,7 @@ extern __u32 cookie_v4_init_sequence(struct sock *sk, struct sk_buff *skb,
                                     __u16 *mss);
 
 extern __u32 cookie_init_timestamp(struct request_sock *req);
-extern void cookie_check_timestamp(struct tcp_options_received *tcp_opt);
+extern bool cookie_check_timestamp(struct tcp_options_received *tcp_opt);
 
 /* From net/ipv6/syncookies.c */
 extern struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb);
index 02bef6aa8b3045b1f7d2be96649d2e07feeb7224..51b5662545d6fc3392993145746fa7f6a0507107 100644 (file)
@@ -230,23 +230,36 @@ static inline struct sock *get_cookie_sock(struct sock *sk, struct sk_buff *skb,
  * The lowest 4 bits are for snd_wscale
  * The next 4 lsb are for rcv_wscale
  * The next lsb is for sack_ok
+ *
+ * return false if we decode an option that should not be.
  */
-void cookie_check_timestamp(struct tcp_options_received *tcp_opt)
+bool cookie_check_timestamp(struct tcp_options_received *tcp_opt)
 {
        /* echoed timestamp, 9 lowest bits contain options */
        u32 options = tcp_opt->rcv_tsecr & TSMASK;
 
+       if (!tcp_opt->saw_tstamp)  {
+               tcp_clear_options(tcp_opt);
+               return true;
+       }
+
+       if (!sysctl_tcp_timestamps)
+               return false;
+
        tcp_opt->snd_wscale = options & 0xf;
        options >>= 4;
        tcp_opt->rcv_wscale = options & 0xf;
 
        tcp_opt->sack_ok = (options >> 4) & 0x1;
 
-       if (tcp_opt->sack_ok)
-               tcp_sack_reset(tcp_opt);
+       if (tcp_opt->sack_ok && !sysctl_tcp_sack)
+               return false;
 
-       if (tcp_opt->snd_wscale || tcp_opt->rcv_wscale)
+       if (tcp_opt->snd_wscale || tcp_opt->rcv_wscale) {
                tcp_opt->wscale_ok = 1;
+               return sysctl_tcp_window_scaling != 0;
+       }
+       return true;
 }
 EXPORT_SYMBOL(cookie_check_timestamp);
 
@@ -281,8 +294,8 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb,
        memset(&tcp_opt, 0, sizeof(tcp_opt));
        tcp_parse_options(skb, &tcp_opt, &hash_location, 0);
 
-       if (tcp_opt.saw_tstamp)
-               cookie_check_timestamp(&tcp_opt);
+       if (!cookie_check_timestamp(&tcp_opt))
+               goto out;
 
        ret = NULL;
        req = inet_reqsk_alloc(&tcp_request_sock_ops); /* for safety */
index 70d330f8c990f4beba0d4c2be02e9f72342bcdcb..c7ee57421eced5209c185e7b57bb3a6c3356531d 100644 (file)
@@ -180,8 +180,8 @@ struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb)
        memset(&tcp_opt, 0, sizeof(tcp_opt));
        tcp_parse_options(skb, &tcp_opt, &hash_location, 0);
 
-       if (tcp_opt.saw_tstamp)
-               cookie_check_timestamp(&tcp_opt);
+       if (!cookie_check_timestamp(&tcp_opt))
+               goto out;
 
        ret = NULL;
        req = inet6_reqsk_alloc(&tcp6_request_sock_ops);