aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHannes Frederic Sowa <hannes@stressinduktion.org>2013-10-19 15:48:56 -0400
committerDavid S. Miller <davem@davemloft.net>2013-10-19 19:45:35 -0400
commitb23a002fc6f0c19846ee0382f019429af54a27e9 (patch)
tree9cb494a707c4145a8a42f0cf6eb6853e487f06a5
parenta48e42920ff38bc90bbf75143fff4555723d4540 (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.h1
-rw-r--r--net/ipv4/syncookies.c15
-rw-r--r--net/ipv6/syncookies.c12
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);
475void inet_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb); 475void inet_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb);
476 476
477/* From syncookies.c */ 477/* From syncookies.c */
478extern __u32 syncookie_secret[2][16-4+SHA_DIGEST_WORDS];
479int __cookie_v4_check(const struct iphdr *iph, const struct tcphdr *th, 478int __cookie_v4_check(const struct iphdr *iph, const struct tcphdr *th,
480 u32 cookie); 479 u32 cookie);
481struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb, 480struct 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
26extern int sysctl_tcp_syncookies; 26extern int sysctl_tcp_syncookies;
27 27
28__u32 syncookie_secret[2][16-4+SHA_DIGEST_WORDS]; 28static u32 syncookie_secret[2][16-4+SHA_DIGEST_WORDS];
29EXPORT_SYMBOL(syncookie_secret);
30
31static __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],
44static u32 cookie_hash(__be32 saddr, __be32 daddr, __be16 sport, __be16 dport, 36static 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
27static 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],
61static u32 cookie_hash(const struct in6_addr *saddr, const struct in6_addr *daddr, 63static 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;