OSDN Git Service

rxrpc: Randomise epoch and starting client conn ID values
authorDavid Howells <dhowells@redhat.com>
Fri, 2 Sep 2016 21:39:45 +0000 (22:39 +0100)
committerDavid Howells <dhowells@redhat.com>
Sun, 4 Sep 2016 20:41:39 +0000 (21:41 +0100)
Create a random epoch value rather than a time-based one on startup and set
the top bit to indicate that this is the case.

Also create a random starting client connection ID value.  This will be
incremented from here as new client connections are created.

Signed-off-by: David Howells <dhowells@redhat.com>
include/rxrpc/packet.h
net/rxrpc/af_rxrpc.c

index b201744..3c6128e 100644 (file)
@@ -24,6 +24,7 @@ typedef __be32        rxrpc_serial_net_t; /* on-the-wire Rx message serial number */
  */
 struct rxrpc_wire_header {
        __be32          epoch;          /* client boot timestamp */
+#define RXRPC_RANDOM_EPOCH     0x80000000      /* Random if set, date-based if not */
 
        __be32          cid;            /* connection and channel ID */
 #define RXRPC_MAXCALLS         4                       /* max active calls per conn */
index 32d5449..b66a9e6 100644 (file)
@@ -16,6 +16,7 @@
 #include <linux/net.h>
 #include <linux/slab.h>
 #include <linux/skbuff.h>
+#include <linux/random.h>
 #include <linux/poll.h>
 #include <linux/proc_fs.h>
 #include <linux/key-type.h>
@@ -700,7 +701,13 @@ static int __init af_rxrpc_init(void)
 
        BUILD_BUG_ON(sizeof(struct rxrpc_skb_priv) > FIELD_SIZEOF(struct sk_buff, cb));
 
-       rxrpc_epoch = get_seconds();
+       get_random_bytes(&rxrpc_epoch, sizeof(rxrpc_epoch));
+       rxrpc_epoch |= RXRPC_RANDOM_EPOCH;
+       get_random_bytes(&rxrpc_client_conn_ids.cur,
+                        sizeof(rxrpc_client_conn_ids.cur));
+       rxrpc_client_conn_ids.cur &= 0x3fffffff;
+       if (rxrpc_client_conn_ids.cur == 0)
+               rxrpc_client_conn_ids.cur = 1;
 
        ret = -ENOMEM;
        rxrpc_call_jar = kmem_cache_create(