From: Greg Price <price@MIT.EDU>
To: "Theodore Ts'o" <tytso@MIT.EDU>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH 06/14] random: separate quantity of bytes extracted and entropy to credit
Date: Sat, 14 Dec 2013 21:01:17 -0500 [thread overview]
Message-ID: <20131215020117.GF27191@athena.dialup.mit.edu> (raw)
In-Reply-To: <cover.1387067223.git.price@mit.edu>
The account() function serves two purposes: it decides how many
bytes of data we allow ourselves to extract from a pool (and as a
corollary how much to debit that pool's entropy estimate), and
when the extraction is for the purpose of transferring to another
pool it also decides how many bits of estimated entropy we should
credit to the other pool.
Introduce an output parameter to tell the caller the one value
separately from the other. The number of bits to credit is not
used in most callers, so do nothing with it there.
In isolation this would be useless abstraction as the values are
interchangeable, but the next commit will make them differ.
Signed-off-by: Greg Price <price@mit.edu>
---
drivers/char/random.c | 24 ++++++++++++++----------
1 file changed, 14 insertions(+), 10 deletions(-)
diff --git a/drivers/char/random.c b/drivers/char/random.c
index a624262e8..c11281551 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -896,7 +896,8 @@ void add_disk_randomness(struct gendisk *disk)
*********************************************************************/
static ssize_t extract_entropy(struct entropy_store *r, void *buf,
- size_t nbytes, struct entropy_store *dest);
+ size_t nbytes, struct entropy_store *dest,
+ int *credit_bits);
/*
* This utility inline function is responsible for transferring entropy
@@ -944,14 +945,14 @@ static void account_xfer(struct entropy_store *dest, int nbytes,
static void _xfer_secondary_pool(struct entropy_store *r, size_t nbytes)
{
__u32 tmp[OUTPUT_POOL_WORDS];
- int bytes;
+ int bytes, credit_bits;
bytes = min_t(int, nbytes, sizeof(tmp));
trace_xfer_secondary_pool(r->name, bytes * 8, nbytes * 8,
ENTROPY_BITS(r), ENTROPY_BITS(r->pull));
- bytes = extract_entropy(r->pull, tmp, bytes, r);
+ bytes = extract_entropy(r->pull, tmp, bytes, r, &credit_bits);
mix_pool_bytes(r, tmp, bytes, NULL);
- credit_entropy_bits(r, bytes*8);
+ credit_entropy_bits(r, credit_bits);
}
/*
@@ -975,7 +976,7 @@ static void push_to_pool(struct work_struct *work)
* given pool, and also debits the entropy count accordingly.
*/
static size_t account(struct entropy_store *r, size_t nbytes,
- struct entropy_store *dest)
+ struct entropy_store *dest, int *credit_bits)
{
int have_bytes, min, reserved;
int entropy_count, orig;
@@ -998,6 +999,8 @@ retry:
max(0, have_bytes - reserved));
if (ibytes < min)
ibytes = 0;
+ if (credit_bits != NULL)
+ *credit_bits = ibytes * 8;
entropy_count = max_t(int, 0,
entropy_count - (ibytes << (ENTROPY_SHIFT + 3)));
if (cmpxchg(&r->entropy_count, orig, entropy_count) != orig)
@@ -1088,7 +1091,8 @@ static void extract_buf(struct entropy_store *r, __u8 *out)
* or is NULL if it's not to be used in another pool.
*/
static ssize_t extract_entropy(struct entropy_store *r, void *buf,
- size_t nbytes, struct entropy_store *dest)
+ size_t nbytes, struct entropy_store *dest,
+ int *credit_bits)
{
ssize_t ret = 0, i;
__u8 tmp[EXTRACT_SIZE];
@@ -1112,7 +1116,7 @@ static ssize_t extract_entropy(struct entropy_store *r, void *buf,
trace_extract_entropy(r->name, nbytes, ENTROPY_BITS(r), _RET_IP_);
xfer_secondary_pool(r, nbytes);
- nbytes = account(r, nbytes, dest);
+ nbytes = account(r, nbytes, dest, credit_bits);
while (nbytes) {
extract_buf(r, tmp);
@@ -1149,7 +1153,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
trace_extract_entropy_user(r->name, nbytes, ENTROPY_BITS(r), _RET_IP_);
xfer_secondary_pool(r, nbytes);
- nbytes = account(r, nbytes, NULL);
+ nbytes = account(r, nbytes, NULL, NULL);
while (nbytes) {
if (need_resched()) {
@@ -1196,7 +1200,7 @@ void get_random_bytes(void *buf, int nbytes)
nonblocking_pool.entropy_total);
#endif
trace_get_random_bytes(nbytes, _RET_IP_);
- extract_entropy(&nonblocking_pool, buf, nbytes, NULL);
+ extract_entropy(&nonblocking_pool, buf, nbytes, NULL, NULL);
}
EXPORT_SYMBOL(get_random_bytes);
@@ -1228,7 +1232,7 @@ void get_random_bytes_arch(void *buf, int nbytes)
}
if (nbytes)
- extract_entropy(&nonblocking_pool, p, nbytes, NULL);
+ extract_entropy(&nonblocking_pool, p, nbytes, NULL, NULL);
}
EXPORT_SYMBOL(get_random_bytes_arch);
--
1.8.3.2
next prev parent reply other threads:[~2013-12-15 2:01 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-15 2:00 [PATCH 00/14] random: rework reseeding Greg Price
2013-12-15 2:00 ` [PATCH 01/14] random: fix signedness bug Greg Price
2013-12-15 2:00 ` [PATCH 02/14] random: fix a (harmless) overflow Greg Price
2013-12-15 2:01 ` [PATCH 03/14] random: reserve for /dev/random only once /dev/urandom seeded Greg Price
2013-12-15 2:01 ` [PATCH 04/14] random: accept small seeds early on Greg Price
2013-12-15 2:01 ` [PATCH 05/14] random: move transfer accounting into account() helper Greg Price
2013-12-15 2:01 ` Greg Price [this message]
2013-12-15 2:01 ` [PATCH 07/14] random: exploit any extra entropy too when reseeding Greg Price
2013-12-15 2:01 ` [PATCH 08/14] random: rate-limit reseeding only after properly seeded Greg Price
2013-12-15 2:01 ` [PATCH 09/14] random: reserve entropy for nonblocking pool early on Greg Price
2013-12-15 2:01 ` [PATCH 10/14] random: direct all routine input via input pool Greg Price
2013-12-15 2:01 ` [PATCH 11/14] random: separate entropy since auto-push from entropy_total Greg Price
2013-12-15 2:01 ` [PATCH 12/14] random: separate minimum reseed size from minimum /dev/random read Greg Price
2013-12-15 2:01 ` [PATCH 13/14] random: count only catastrophic reseeds for initialization Greg Price
2013-12-15 2:02 ` [PATCH 14/14] random: target giant reseeds, to be conservative Greg Price
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=20131215020117.GF27191@athena.dialup.mit.edu \
--to=price@mit.edu \
--cc=linux-kernel@vger.kernel.org \
--cc=tytso@MIT.EDU \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome