* Introduce support to lazy initialize mostly static keys
@ 2013-09-26 23:16 Hannes Frederic Sowa
2013-09-26 23:30 ` Hannes Frederic Sowa
[not found] ` <1380236199-3726-4-git-send-email-hannes@stressinduktion.org>
0 siblings, 2 replies; 4+ messages in thread
From: Hannes Frederic Sowa @ 2013-09-26 23:16 UTC (permalink / raw)
To: netdev; +Cc: edumazet, davem, fw, ycheng
Hi!
This series implements support for delaying the initialization of secret
keys, e.g. used for hashing, for as long as possible. This functionality
is implemented by a new macro, net_get_random_bytes.
I already used it to protect the socket hashes, the syncookie secret
(most important) and the tcp_fastopen secrets.
This series depends on a patch from Eric Dumazet (already in patchworks):
"net: net_secret should not depend on TCP"
Included patches:
ipv4: split inet_ehashfn to one hash
ipv6: split inet6_ehashfn to one hash
net: introduce new macro net_get_random_once
inet: split syncookie keys for ipv4 and ipv6 and
inet: convert inet_ehash_secret and
tcp: switch tcp_fastopen key generation to
net: switch net_secret key generation to
Diffstat:
include/linux/net.h | 14 ++++++++++++++
include/net/inet6_hashtables.h | 29 +++++++----------------------
include/net/inet_sock.h | 26 ++++++--------------------
include/net/ipv6.h | 4 ++--
include/net/tcp.h | 3 +--
net/core/secure_seq.c | 14 ++------------
net/core/utils.c | 21 +++++++++++++++++++++
net/ipv4/af_inet.c | 27 ---------------------------
net/ipv4/inet_hashtables.c | 25 +++++++++++++++++++++++++
net/ipv4/syncookies.c | 15 +++++----------
net/ipv4/sysctl_net_ipv4.c | 5 +++++
net/ipv4/tcp_fastopen.c | 21 ++++++++++-----------
net/ipv4/udp.c | 22 +++++++++++++++++-----
net/ipv6/af_inet6.c | 5 -----
net/ipv6/inet6_hashtables.c | 40 +++++++++++++++++++++++++++++++++++++---
net/ipv6/syncookies.c | 12 +++++++++---
net/ipv6/udp.c | 37 ++++++++++++++++++++++++++++++-------
net/rds/connection.c | 18 ++++++++++++------
18 files changed, 203 insertions(+), 135 deletions(-)
Greetings,
Hannes
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: Introduce support to lazy initialize mostly static keys
2013-09-26 23:16 Introduce support to lazy initialize mostly static keys Hannes Frederic Sowa
@ 2013-09-26 23:30 ` Hannes Frederic Sowa
[not found] ` <1380236199-3726-4-git-send-email-hannes@stressinduktion.org>
1 sibling, 0 replies; 4+ messages in thread
From: Hannes Frederic Sowa @ 2013-09-26 23:30 UTC (permalink / raw)
To: netdev, edumazet, davem, fw, ycheng
On Fri, Sep 27, 2013 at 01:16:57AM +0200, Hannes Frederic Sowa wrote:
> This series implements support for delaying the initialization of secret
> keys, e.g. used for hashing, for as long as possible. This functionality
> is implemented by a new macro, net_get_random_bytes.
>
> I already used it to protect the socket hashes, the syncookie secret
> (most important) and the tcp_fastopen secrets.
>
> This series depends on a patch from Eric Dumazet (already in patchworks):
> "net: net_secret should not depend on TCP"
Oh, sorry. My tunnel was not working. Mails hit a strange fallback. Will
resend shortly.
^ permalink raw reply [flat|nested] 4+ messages in thread[parent not found: <1380236199-3726-4-git-send-email-hannes@stressinduktion.org>]
* Re: [PATCH net-next 3/7] net: introduce new macro net_get_random_once
[not found] ` <1380236199-3726-4-git-send-email-hannes@stressinduktion.org>
@ 2013-09-30 19:43 ` David Miller
0 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2013-09-30 19:43 UTC (permalink / raw)
To: hannes; +Cc: netdev, edumazet
From: Hannes Frederic Sowa <hannes@stressinduktion.org>
Date: Fri, 27 Sep 2013 00:56:35 +0200
> +/* BE CAREFUL: this function is not interrupt safe */
> +#define net_get_random_once(buf, nbytes) \
> + ({ \
> + static bool ___done = false; \
> + bool ___ret = false; \
> + if (unlikely(!___done)) \
> + ___ret = __net_get_random_once(buf, \
> + nbytes, \
> + &___done); \
> + ___ret; \
> + })
I don't want to see this happening in every fast path, it's silly to test
this every time after the first iteration.
Maybe... _maybe_ I can be convinced if you use a static branch for this so
that it _really_ costs next to nothing.
But as-is I am not going to apply this series, sorry.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Introduce support to lazy initialize mostly static keys
@ 2013-09-26 23:32 Hannes Frederic Sowa
2013-09-26 23:32 ` [PATCH net-next 3/7] net: introduce new macro net_get_random_once Hannes Frederic Sowa
0 siblings, 1 reply; 4+ messages in thread
From: Hannes Frederic Sowa @ 2013-09-26 23:32 UTC (permalink / raw)
To: netdev
Hi!
This series implements support for delaying the initialization of secret
keys, e.g. used for hashing, for as long as possible. This functionality
is implemented by a new macro, net_get_random_bytes.
I already used it to protect the socket hashes, the syncookie secret
(most important) and the tcp_fastopen secrets.
This series depends on a patch from Eric Dumazet (already in patchworks):
"net: net_secret should not depend on TCP"
Included patches:
ipv4: split inet_ehashfn to one hash
ipv6: split inet6_ehashfn to one hash
net: introduce new macro net_get_random_once
inet: split syncookie keys for ipv4 and ipv6 and
inet: convert inet_ehash_secret and
tcp: switch tcp_fastopen key generation to
net: switch net_secret key generation to
Diffstat:
include/linux/net.h | 14 ++++++++++++++
include/net/inet6_hashtables.h | 29 +++++++----------------------
include/net/inet_sock.h | 26 ++++++--------------------
include/net/ipv6.h | 4 ++--
include/net/tcp.h | 3 +--
net/core/secure_seq.c | 14 ++------------
net/core/utils.c | 21 +++++++++++++++++++++
net/ipv4/af_inet.c | 27 ---------------------------
net/ipv4/inet_hashtables.c | 25 +++++++++++++++++++++++++
net/ipv4/syncookies.c | 15 +++++----------
net/ipv4/sysctl_net_ipv4.c | 5 +++++
net/ipv4/tcp_fastopen.c | 21 ++++++++++-----------
net/ipv4/udp.c | 22 +++++++++++++++++-----
net/ipv6/af_inet6.c | 5 -----
net/ipv6/inet6_hashtables.c | 40 +++++++++++++++++++++++++++++++++++++---
net/ipv6/syncookies.c | 12 +++++++++---
net/ipv6/udp.c | 37 ++++++++++++++++++++++++++++++-------
net/rds/connection.c | 18 ++++++++++++------
18 files changed, 203 insertions(+), 135 deletions(-)
Greetings,
Hannes
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH net-next 3/7] net: introduce new macro net_get_random_once
2013-09-26 23:32 Introduce support to lazy initialize mostly static keys Hannes Frederic Sowa
@ 2013-09-26 23:32 ` Hannes Frederic Sowa
0 siblings, 0 replies; 4+ messages in thread
From: Hannes Frederic Sowa @ 2013-09-26 23:32 UTC (permalink / raw)
To: netdev; +Cc: Hannes Frederic Sowa, Eric Dumazet, David S. Miller
net_get_random_once is a new macro which handles the initialization
of secret keys. It is possible to call it in the fast path. Only the
initialization depends on the spinlock and is rather slow. Otherwise
it should get used just before the key is used to delay the entropy
extration as late as possible to get better randomness. It returns true
if the key got initialized.
Cc: Eric Dumazet <edumazet@google.com>
Cc: "David S. Miller" <davem@davemloft.net>
Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
---
include/linux/net.h | 14 ++++++++++++++
net/core/utils.c | 21 +++++++++++++++++++++
2 files changed, 35 insertions(+)
diff --git a/include/linux/net.h b/include/linux/net.h
index 4f27575..d14fad5 100644
--- a/include/linux/net.h
+++ b/include/linux/net.h
@@ -243,6 +243,20 @@ do { \
#define net_random() prandom_u32()
#define net_srandom(seed) prandom_seed((__force u32)(seed))
+bool __net_get_random_once(void *buf, int nbytes, bool *done);
+
+/* BE CAREFUL: this function is not interrupt safe */
+#define net_get_random_once(buf, nbytes) \
+ ({ \
+ static bool ___done = false; \
+ bool ___ret = false; \
+ if (unlikely(!___done)) \
+ ___ret = __net_get_random_once(buf, \
+ nbytes, \
+ &___done); \
+ ___ret; \
+ })
+
extern int kernel_sendmsg(struct socket *sock, struct msghdr *msg,
struct kvec *vec, size_t num, size_t len);
extern int kernel_recvmsg(struct socket *sock, struct msghdr *msg,
diff --git a/net/core/utils.c b/net/core/utils.c
index aa88e23..b420547 100644
--- a/net/core/utils.c
+++ b/net/core/utils.c
@@ -338,3 +338,24 @@ void inet_proto_csum_replace16(__sum16 *sum, struct sk_buff *skb,
csum_unfold(*sum)));
}
EXPORT_SYMBOL(inet_proto_csum_replace16);
+
+bool __net_get_random_once(void *buf, int nbytes, bool *done)
+{
+ static DEFINE_SPINLOCK(lock);
+
+ spin_lock_bh(&lock);
+ if (*done) {
+ spin_unlock_bh(&lock);
+ return false;
+ }
+
+ get_random_bytes(buf, nbytes);
+ /* Make sure random data is published before toggeling done.
+ * There is no corresponding rmb.
+ */
+ smp_wmb();
+ *done = true;
+ spin_unlock_bh(&lock);
+ return true;
+}
+EXPORT_SYMBOL(__net_get_random_once);
--
1.8.3.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-09-30 19:43 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-26 23:16 Introduce support to lazy initialize mostly static keys Hannes Frederic Sowa
2013-09-26 23:30 ` Hannes Frederic Sowa
[not found] ` <1380236199-3726-4-git-send-email-hannes@stressinduktion.org>
2013-09-30 19:43 ` [PATCH net-next 3/7] net: introduce new macro net_get_random_once David Miller
-- strict thread matches above, loose matches on Subject: below --
2013-09-26 23:32 Introduce support to lazy initialize mostly static keys Hannes Frederic Sowa
2013-09-26 23:32 ` [PATCH net-next 3/7] net: introduce new macro net_get_random_once Hannes Frederic Sowa
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).