mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-07-23 07:12:09 +00:00
tcp: syncookies: reduce cookie lifetime to 128 seconds
We currently accept cookies that were created less than 4 minutes ago (ie, cookies with counter delta 0-3). Combined with the 8 mss table values, this yields 32 possible values (out of 2**32) that will be valid. Reducing the lifetime to < 2 minutes halves the guessing chance while still providing a large enough period. While at it, get rid of jiffies value -- they overflow too quickly on 32 bit platforms. getnstimeofday is used to create a counter that increments every 64s. perf shows getnstimeofday cost is negible compared to sha_transform; normal tcp initial sequence number generation uses getnstimeofday, too. Reported-by: Jakob Lell <jakob@jakoblell.com> Signed-off-by: Florian Westphal <fw@strlen.de> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
61f860c356
commit
8c27bd75f0
3 changed files with 35 additions and 38 deletions
|
@ -481,6 +481,24 @@ int __cookie_v4_check(const struct iphdr *iph, const struct tcphdr *th,
|
|||
struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb,
|
||||
struct ip_options *opt);
|
||||
#ifdef CONFIG_SYN_COOKIES
|
||||
#include <linux/ktime.h>
|
||||
|
||||
/* Syncookies use a monotonic timer which increments every 64 seconds.
|
||||
* This counter is used both as a hash input and partially encoded into
|
||||
* the cookie value. A cookie is only validated further if the delta
|
||||
* between the current counter value and the encoded one is less than this,
|
||||
* i.e. a sent cookie is valid only at most for 128 seconds (or less if
|
||||
* the counter advances immediately after a cookie is generated).
|
||||
*/
|
||||
#define MAX_SYNCOOKIE_AGE 2
|
||||
|
||||
static inline u32 tcp_cookie_time(void)
|
||||
{
|
||||
struct timespec now;
|
||||
getnstimeofday(&now);
|
||||
return now.tv_sec >> 6; /* 64 seconds granularity */
|
||||
}
|
||||
|
||||
u32 __cookie_v4_init_sequence(const struct iphdr *iph, const struct tcphdr *th,
|
||||
u16 *mssp);
|
||||
__u32 cookie_v4_init_sequence(struct sock *sk, struct sk_buff *skb, __u16 *mss);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue