random: Add a urandom_read_nowait() for random APIs that don't warn
/dev/random and getrandom() never warn. Split the meat of urandom_read() into urandom_read_nowarn() and leave the warning code in urandom_read(). This has no effect on kernel behavior, but it makes subsequent patches more straightforward. It also makes the fact that getrandom() never warns more obvious. Signed-off-by: Andy Lutomirski <luto@kernel.org> Link: https://lore.kernel.org/r/c87ab200588de746431d9f916501ef11e5242b13.1577088521.git.luto@kernel.org Signed-off-by: Theodore Ts'o <tytso@mit.edu>
This commit is contained in:
Родитель
4c8d062186
Коммит
c6f1deb158
|
@ -2019,12 +2019,23 @@ random_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
|
||||||
return _random_read(file->f_flags & O_NONBLOCK, buf, nbytes);
|
return _random_read(file->f_flags & O_NONBLOCK, buf, nbytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static ssize_t
|
||||||
|
urandom_read_nowarn(struct file *file, char __user *buf, size_t nbytes,
|
||||||
|
loff_t *ppos)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
nbytes = min_t(size_t, nbytes, INT_MAX >> (ENTROPY_SHIFT + 3));
|
||||||
|
ret = extract_crng_user(buf, nbytes);
|
||||||
|
trace_urandom_read(8 * nbytes, 0, ENTROPY_BITS(&input_pool));
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static ssize_t
|
static ssize_t
|
||||||
urandom_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
|
urandom_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
|
||||||
{
|
{
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
static int maxwarn = 10;
|
static int maxwarn = 10;
|
||||||
int ret;
|
|
||||||
|
|
||||||
if (!crng_ready() && maxwarn > 0) {
|
if (!crng_ready() && maxwarn > 0) {
|
||||||
maxwarn--;
|
maxwarn--;
|
||||||
|
@ -2036,10 +2047,8 @@ urandom_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
|
||||||
crng_init_cnt = 0;
|
crng_init_cnt = 0;
|
||||||
spin_unlock_irqrestore(&primary_crng.lock, flags);
|
spin_unlock_irqrestore(&primary_crng.lock, flags);
|
||||||
}
|
}
|
||||||
nbytes = min_t(size_t, nbytes, INT_MAX >> (ENTROPY_SHIFT + 3));
|
|
||||||
ret = extract_crng_user(buf, nbytes);
|
return urandom_read_nowarn(file, buf, nbytes, ppos);
|
||||||
trace_urandom_read(8 * nbytes, 0, ENTROPY_BITS(&input_pool));
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static __poll_t
|
static __poll_t
|
||||||
|
@ -2201,7 +2210,7 @@ SYSCALL_DEFINE3(getrandom, char __user *, buf, size_t, count,
|
||||||
if (unlikely(ret))
|
if (unlikely(ret))
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
return urandom_read(NULL, buf, count, NULL);
|
return urandom_read_nowarn(NULL, buf, count, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/********************************************************************
|
/********************************************************************
|
||||||
|
|
Загрузка…
Ссылка в новой задаче