<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Dec 1, 2016 at 8:14 AM, Theodore Ts'o <span dir="ltr"><<a href="mailto:tytso@mit.edu" target="_blank">tytso@mit.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail-">On Wed, Nov 30, 2016 at 05:59:24AM -0800, Bill Cox wrote:<br>
> I just learned on another thread that Linux provided a fixed API.  The new<br>
> right answer on Linux is to call getrandom:<br>
><br>
> <a href="https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=c6e9d6f3" rel="noreferrer" target="_blank">https://git.kernel.org/cgit/<wbr>linux/kernel/git/torvalds/<wbr>linux.git/commit/?id=c6e9d6f3</a><br>
><br>
> It's in linux 3.17.  My Ubuntu 14.04 laptop upgraded to 3.19, so I had<br>
> it... Then it upgraded to 4.2.0, and now I no longer have it.  Grrr...<br>
<br>
</span>Huh?  It most certainly is in 4.2.0.  What were you saying about noise<br>
on these threads being aggravating?<br>
<br>
% git show v4.2:drivers/char/random.c  | grep getrandom<br>
SYSCALL_DEFINE3(getrandom, char __user *, buf, size_t, count,<br>
<br>
                                               - Ted<br>
</blockquote></div><br></div><div class="gmail_extra">There is still something wrong.  I've tried a more recent 4.4.0-51-generic kernel in Ubuntu 14.04, with no luck.  There is no SYS_getrandom syscall available through the syscall function, nor getrandom in libc.  I'm running x64.  I see this:</div><div class="gmail_extra"><br></div><div class="gmail_extra">/lib/modules/4.4.0-51-generic/build/arch/x86/include/generated/asm/syscalls_64.h:__SYSCALL_COMMON(318, sys_getrandom, sys_getrandom)<br></div><div class="gmail_extra"><br></div><div class="gmail_extra">So, it looks like it is in the kernel.  Here's the latest code I tried to compile with gcc -Wall foo.c:</div><div class="gmail_extra"><br></div><div class="gmail_extra"><div class="gmail_extra">#define _GNU_SOURCE</div><div class="gmail_extra"><br></div><div class="gmail_extra">#include <unistd.h></div><div class="gmail_extra">#include <sys/syscall.h></div><div class="gmail_extra">#include <linux/random.h></div><div class="gmail_extra">#include <stdio.h></div><div class="gmail_extra"><br></div><div class="gmail_extra">int main() {</div><div class="gmail_extra">    unsigned char buffer[32];</div><div class="gmail_extra">    int numBytes = syscall(SYS_getrandom, buffer, 32, 0);</div><div class="gmail_extra">    printf("bytes read = %u\n", numBytes);</div><div class="gmail_extra">    return 0;</div><div class="gmail_extra">}</div><div><br></div><div>This gives:</div><div><br></div><div><div>foo.c: In function ‘main’:</div><div>foo.c:10:28: error: ‘SYS_getrandom’ undeclared (first use in this function)</div><div>     int numBytes = syscall(SYS_getrandom, buffer, 32, 0);</div><div>                            ^</div><div>foo.c:10:28: note: each undeclared identifier is reported only once for each function it appears in</div></div><div><br></div><div>Various combinations of includes also fail.  There is no instance of getrandom under /usr/include.</div></div><div class="gmail_extra"><br></div><div class="gmail_extra">How can I access getrandom?  Is this a Debian/Ubuntu bug?</div><div class="gmail_extra"><br></div><div class="gmail_extra">Bill</div></div>