From: NeilBrown <neilb@suse.de>
To: Trond Myklebust <trond.myklebust@fys.uio.no>
Cc: Chuck Lever <chuck.lever@oracle.com>
Cc: linux-nfs@vger.kernel.org
Subject: [PATCH] Add more entropy to selection of port and xid for NFS client.
Date: Tue, 4 Mar 2008 16:35:53 +1100 [thread overview]
Message-ID: <1080304053553.18549@suse.de> (raw)
In-Reply-To: 20080304163343.18442.patches@notabene
Hi Trond/Chunk
I wonder what you think of this patch.
I found we needed it for some customers who had machines with NFS root
who (for reasons I never fully understood) find they reboot their
machines fairly often (maybe it was a test setup or something). The
often got "inode number mismatch" errors because the reply came out of
the server's cache and was left over from before the client's reboot.
Thanks,
NeilBrown
### Comments for Changeset
Diskless clients that use NFS-root have very little chance
to gain much entropy in net_random before the NFS client must
choose a port number and an 'xid' to being talking to the server.
So add as much entropy as possible.
Without this, clients can and do suffer from collisions in the servers
reply cache, and get meaningless replies.
Signed-off-by: Neil Brown <neilb@suse.de>
### Diffstat output
./net/sunrpc/xprt.c | 5 ++++-
./net/sunrpc/xprtsock.c | 7 +++++--
2 files changed, 9 insertions(+), 3 deletions(-)
diff .prev/net/sunrpc/xprt.c ./net/sunrpc/xprt.c
--- .prev/net/sunrpc/xprt.c 2008-03-04 16:33:26.000000000 +1100
+++ ./net/sunrpc/xprt.c 2008-03-04 16:33:36.000000000 +1100
@@ -922,7 +922,10 @@ static inline __be32 xprt_alloc_xid(stru
static inline void xprt_init_xid(struct rpc_xprt *xprt)
{
- xprt->xid = net_random();
+ get_random_bytes(&xprt->xid, sizeof(xprt->xid));
+ /* And just in case random_state isn't initialised yet.. */
+ xprt->xid ^= net_random();
+ xprt->xid += (CURRENT_TIME.tv_sec << 10);
}
static void xprt_request_init(struct rpc_task *task, struct rpc_xprt *xprt)
diff .prev/net/sunrpc/xprtsock.c ./net/sunrpc/xprtsock.c
--- .prev/net/sunrpc/xprtsock.c 2008-03-04 16:33:26.000000000 +1100
+++ ./net/sunrpc/xprtsock.c 2008-03-04 16:28:06.000000000 +1100
@@ -1283,8 +1283,11 @@ static void xs_udp_timer(struct rpc_task
static unsigned short xs_get_random_port(void)
{
unsigned short range = xprt_max_resvport - xprt_min_resvport;
- unsigned short rand = (unsigned short) net_random() % range;
- return rand + xprt_min_resvport;
+ unsigned short rand;
+ get_random_bytes(&rand, sizeof(rand));
+ rand ^= (unsigned short)net_random();
+ rand ^= (CURRENT_TIME.tv_nsec >> 10);
+ return (rand % range) + xprt_min_resvport;
}
/**
next parent reply other threads:[~2008-03-04 5:36 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20080304163343.18442.patches@notabene>
2008-03-04 5:35 ` NeilBrown [this message]
2008-03-04 17:00 ` [PATCH] Add more entropy to selection of port and xid for NFS client Chuck Lever
2008-03-06 2:36 ` Neil Brown
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1080304053553.18549@suse.de \
--to=neilb@suse.de \
--cc=chuck.lever@oracle.com \
--cc=trond.myklebust@fys.uio.no \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.