Re: [PATCH, RFC] random: introduce getrandom(2) system call
From: Zach Brown <hidden>
Date: 2014-07-17 19:48:14
Also in:
lkml
SYNOPSIS #include <linux/random.h> int getrandom(void *buf, size_t buflen, unsigned int flags);
I certainly like the idea of getting entropy without having to worry about fds.
If the GRND_RANDOM flags bit is not set, then the /dev/raundom
(raundom typo)
RETURN VALUE
On success, the number of bytes that was returned is returned.The description talks about filling the buffer, maybe say 'the number of bytes filled is returned'?
+DECLARE_COMPLETION(urandom_initialized);
static?
+SYSCALL_DEFINE3(getrandom, char __user *, buf, size_t, count,
+ unsigned int, flags)
+{
+ int r;
+Michael Kerrisk wants you to return -EINVAL on unknown flags :) http://lwn.net/Articles/588444/
+ if (count > 256) + return -EINVAL;
I'd vote for not having the limit. It seems easy enough to iterate over the buffer. We'd need to clamp the count to ssize_t, though.
+ if (flags & GRND_RANDOM) {
+ return _random_read(!(flags & GRND_BLOCK), buf, count);
+ }Do we want it to block by default and have the flag be _NONBLOCK? Feels more.. familiar.
+ if (flags & GRND_BLOCK) {
+ r = wait_for_completion_interruptible(&urandom_initialized);
+ if (r)
+ return r;I can *never* remember the rules for -ERESTARTSYS. The syscall callers take care of this?
+ return urandom_read(NULL, buf, count, NULL);
I wonder if we want to refactor the entry points a bit more instead of directly calling the device read functions. get_random_bytes() and urandom_read() both have their own uninitialied use warning message and tracing. Does the syscall want its own little extraction function as well? - z