diff options
| author | Hannes Frederic Sowa <hannes@stressinduktion.org> | 2013-10-19 15:48:56 -0400 |
|---|---|---|
| committer | David S. Miller <davem@davemloft.net> | 2013-10-19 19:45:35 -0400 |
| commit | b23a002fc6f0c19846ee0382f019429af54a27e9 (patch) | |
| tree | 9cb494a707c4145a8a42f0cf6eb6853e487f06a5 | |
| parent | a48e42920ff38bc90bbf75143fff4555723d4540 (diff) | |
inet: split syncookie keys for ipv4 and ipv6 and initialize with net_get_random_once
This patch splits the secret key for syncookies for ipv4 and ipv6 and
initializes them with net_get_random_once. This change was the reason I
did this series. I think the initialization of the syncookie_secret is
way to early.
Cc: Florian Westphal <fw@strlen.de>
Cc: Eric Dumazet <edumazet@google.com>
Cc: "David S. Miller" <davem@davemloft.net>
Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
| -rw-r--r-- | include/net/tcp.h | 1 | ||||
| -rw-r--r-- | net/ipv4/syncookies.c | 15 | ||||
| -rw-r--r-- | net/ipv6/syncookies.c | 12 |
3 files changed, 14 insertions, 14 deletions
diff --git a/include/net/tcp.h b/include/net/tcp.h index 372dcccfeed0..f30326f1c92b 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h | |||
| @@ -475,7 +475,6 @@ int tcp_send_rcvq(struct sock *sk, struct msghdr *msg, size_t size); | |||
| 475 | void inet_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb); | 475 | void inet_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb); |
| 476 | 476 | ||
| 477 | /* From syncookies.c */ | 477 | /* From syncookies.c */ |
| 478 | extern __u32 syncookie_secret[2][16-4+SHA_DIGEST_WORDS]; | ||
| 479 | int __cookie_v4_check(const struct iphdr *iph, const struct tcphdr *th, | 478 | int __cookie_v4_check(const struct iphdr *iph, const struct tcphdr *th, |
| 480 | u32 cookie); | 479 | u32 cookie); |
| 481 | struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb, | 480 | struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb, |
diff --git a/net/ipv4/syncookies.c b/net/ipv4/syncookies.c index 3b64c59b4109..b95331e6c077 100644 --- a/net/ipv4/syncookies.c +++ b/net/ipv4/syncookies.c | |||
| @@ -25,15 +25,7 @@ | |||
| 25 | 25 | ||
| 26 | extern int sysctl_tcp_syncookies; | 26 | extern int sysctl_tcp_syncookies; |
| 27 | 27 | ||
| 28 | __u32 syncookie_secret[2][16-4+SHA_DIGEST_WORDS]; | 28 | static u32 syncookie_secret[2][16-4+SHA_DIGEST_WORDS]; |
| 29 | EXPORT_SYMBOL(syncookie_secret); | ||
| 30 | |||
| 31 | static __init int init_syncookies(void) | ||
| 32 | { | ||
| 33 | get_random_bytes(syncookie_secret, sizeof(syncookie_secret)); | ||
| 34 | return 0; | ||
| 35 | } | ||
| 36 | __initcall(init_syncookies); | ||
| 37 | 29 | ||
| 38 | #define COOKIEBITS 24 /* Upper bits store count */ | 30 | #define COOKIEBITS 24 /* Upper bits store count */ |
| 39 | #define COOKIEMASK (((__u32)1 << COOKIEBITS) - 1) | 31 | #define COOKIEMASK (((__u32)1 << COOKIEBITS) - 1) |
| @@ -44,8 +36,11 @@ static DEFINE_PER_CPU(__u32 [16 + 5 + SHA_WORKSPACE_WORDS], | |||
| 44 | static u32 cookie_hash(__be32 saddr, __be32 daddr, __be16 sport, __be16 dport, | 36 | static u32 cookie_hash(__be32 saddr, __be32 daddr, __be16 sport, __be16 dport, |
| 45 | u32 count, int c) | 37 | u32 count, int c) |
| 46 | { | 38 | { |
| 47 | __u32 *tmp = __get_cpu_var(ipv4_cookie_scratch); | 39 | __u32 *tmp; |
| 40 | |||
| 41 | net_get_random_once(syncookie_secret, sizeof(syncookie_secret)); | ||
| 48 | 42 | ||
| 43 | tmp = __get_cpu_var(ipv4_cookie_scratch); | ||
| 49 | memcpy(tmp + 4, syncookie_secret[c], sizeof(syncookie_secret[c])); | 44 | memcpy(tmp + 4, syncookie_secret[c], sizeof(syncookie_secret[c])); |
| 50 | tmp[0] = (__force u32)saddr; | 45 | tmp[0] = (__force u32)saddr; |
| 51 | tmp[1] = (__force u32)daddr; | 46 | tmp[1] = (__force u32)daddr; |
diff --git a/net/ipv6/syncookies.c b/net/ipv6/syncookies.c index d04d3f1dd9b7..535a3ad262f1 100644 --- a/net/ipv6/syncookies.c +++ b/net/ipv6/syncookies.c | |||
| @@ -24,6 +24,8 @@ | |||
| 24 | #define COOKIEBITS 24 /* Upper bits store count */ | 24 | #define COOKIEBITS 24 /* Upper bits store count */ |
| 25 | #define COOKIEMASK (((__u32)1 << COOKIEBITS) - 1) | 25 | #define COOKIEMASK (((__u32)1 << COOKIEBITS) - 1) |
| 26 | 26 | ||
| 27 | static u32 syncookie6_secret[2][16-4+SHA_DIGEST_WORDS]; | ||
| 28 | |||
| 27 | /* RFC 2460, Section 8.3: | 29 | /* RFC 2460, Section 8.3: |
| 28 | * [ipv6 tcp] MSS must be computed as the maximum packet size minus 60 [..] | 30 | * [ipv6 tcp] MSS must be computed as the maximum packet size minus 60 [..] |
| 29 | * | 31 | * |
| @@ -61,14 +63,18 @@ static DEFINE_PER_CPU(__u32 [16 + 5 + SHA_WORKSPACE_WORDS], | |||
| 61 | static u32 cookie_hash(const struct in6_addr *saddr, const struct in6_addr *daddr, | 63 | static u32 cookie_hash(const struct in6_addr *saddr, const struct in6_addr *daddr, |
| 62 | __be16 sport, __be16 dport, u32 count, int c) | 64 | __be16 sport, __be16 dport, u32 count, int c) |
| 63 | { | 65 | { |
| 64 | __u32 *tmp = __get_cpu_var(ipv6_cookie_scratch); | 66 | __u32 *tmp; |
| 67 | |||
| 68 | net_get_random_once(syncookie6_secret, sizeof(syncookie6_secret)); | ||
| 69 | |||
| 70 | tmp = __get_cpu_var(ipv6_cookie_scratch); | ||
| 65 | 71 | ||
| 66 | /* | 72 | /* |
| 67 | * we have 320 bits of information to hash, copy in the remaining | 73 | * we have 320 bits of information to hash, copy in the remaining |
| 68 | * 192 bits required for sha_transform, from the syncookie_secret | 74 | * 192 bits required for sha_transform, from the syncookie6_secret |
| 69 | * and overwrite the digest with the secret | 75 | * and overwrite the digest with the secret |
| 70 | */ | 76 | */ |
| 71 | memcpy(tmp + 10, syncookie_secret[c], 44); | 77 | memcpy(tmp + 10, syncookie6_secret[c], 44); |
| 72 | memcpy(tmp, saddr, 16); | 78 | memcpy(tmp, saddr, 16); |
| 73 | memcpy(tmp + 4, daddr, 16); | 79 | memcpy(tmp + 4, daddr, 16); |
| 74 | tmp[8] = ((__force u32)sport << 16) + (__force u32)dport; | 80 | tmp[8] = ((__force u32)sport << 16) + (__force u32)dport; |
