]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-3.18/netns-provide-pure-entropy-for-net_hash_mix.patch
Fixes for 4.19
[thirdparty/kernel/stable-queue.git] / queue-3.18 / netns-provide-pure-entropy-for-net_hash_mix.patch
1 From foo@baz Mon Apr 15 07:47:06 CEST 2019
2 From: Eric Dumazet <edumazet@google.com>
3 Date: Wed, 27 Mar 2019 08:21:30 -0700
4 Subject: netns: provide pure entropy for net_hash_mix()
5
6 From: Eric Dumazet <edumazet@google.com>
7
8 [ Upstream commit 355b98553789b646ed97ad801a619ff898471b92 ]
9
10 net_hash_mix() currently uses kernel address of a struct net,
11 and is used in many places that could be used to reveal this
12 address to a patient attacker, thus defeating KASLR, for
13 the typical case (initial net namespace, &init_net is
14 not dynamically allocated)
15
16 I believe the original implementation tried to avoid spending
17 too many cycles in this function, but security comes first.
18
19 Also provide entropy regardless of CONFIG_NET_NS.
20
21 Fixes: 0b4419162aa6 ("netns: introduce the net_hash_mix "salt" for hashes")
22 Signed-off-by: Eric Dumazet <edumazet@google.com>
23 Reported-by: Amit Klein <aksecurity@gmail.com>
24 Reported-by: Benny Pinkas <benny@pinkas.net>
25 Cc: Pavel Emelyanov <xemul@openvz.org>
26 Signed-off-by: David S. Miller <davem@davemloft.net>
27 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
28 ---
29 include/net/net_namespace.h | 2 ++
30 include/net/netns/hash.h | 15 ++-------------
31 net/core/net_namespace.c | 1 +
32 3 files changed, 5 insertions(+), 13 deletions(-)
33
34 --- a/include/net/net_namespace.h
35 +++ b/include/net/net_namespace.h
36 @@ -54,6 +54,8 @@ struct net {
37 #endif
38 spinlock_t rules_mod_lock;
39
40 + u32 hash_mix;
41 +
42 struct list_head list; /* list of network namespaces */
43 struct list_head cleanup_list; /* namespaces on death row */
44 struct list_head exit_list; /* Use only net_mutex */
45 --- a/include/net/netns/hash.h
46 +++ b/include/net/netns/hash.h
47 @@ -1,21 +1,10 @@
48 #ifndef __NET_NS_HASH_H__
49 #define __NET_NS_HASH_H__
50
51 -#include <asm/cache.h>
52 -
53 -struct net;
54 +#include <net/net_namespace.h>
55
56 static inline unsigned int net_hash_mix(struct net *net)
57 {
58 -#ifdef CONFIG_NET_NS
59 - /*
60 - * shift this right to eliminate bits, that are
61 - * always zeroed
62 - */
63 -
64 - return (unsigned)(((unsigned long)net) >> L1_CACHE_SHIFT);
65 -#else
66 - return 0;
67 -#endif
68 + return net->hash_mix;
69 }
70 #endif
71 --- a/net/core/net_namespace.c
72 +++ b/net/core/net_namespace.c
73 @@ -156,6 +156,7 @@ static __net_init int setup_net(struct n
74
75 atomic_set(&net->count, 1);
76 atomic_set(&net->passive, 1);
77 + get_random_bytes(&net->hash_mix, sizeof(u32));
78 net->dev_base_seq = 1;
79 net->user_ns = user_ns;
80