0

I am attempting to create a Kernel Module, and I am looking to use getrandom to access a secure random from /dev/urandom. I am having problems getting the make to allow the function. Make will not complete and is returning the following error:

implicit declaration of function 'getrandom' [-Werror=implicit-function-declaration]

What would I need to do to fix this?


I've already followed this guide on how to update my glibc library from the sid repositories. Running ldd --version in the terminal will return the following info:

ldd (Debian GLIBC 2.27-3) 2.27


hello-2.c

#define MODULE 
#define LINUX 
#define __KERNEL__

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/random.h>

static int hello_2_init(void)
{
 printk("Hello, world 2\n");
 int rnd = 0;
 void *buf;
 getrandom(rnd, 256, 0);
 printk("Number is %d ", rnd);
 return 0;
}

The expected result would be getrandom to not prevent my program from compiling into a kernel mod and return a random int, but the current result is the fatal compilation error.

Projava
  • 21
  • 6
  • Could be a duplicate of [this](https://stackoverflow.com/questions/30800331/getrandom-syscall-in-c-not-found) – Jabberwocky Jun 20 '18 at 15:06
  • 1
    Since you are writing a *kernel module*, you can rely only on a small subset of the C standard library and on functions the kernel itself provides to you. In fact "subset of the C standard library" is misleading -- you can rely on several specific headers, but these define only macros and types, not any callable functions. – John Bollinger Jun 20 '18 at 15:08
  • The kernel does seem to provide some functions for random number generation, however. You are already including `linux/random.h` -- look into the functions it declares for you. – John Bollinger Jun 20 '18 at 15:11
  • John your comment helped me rephrase my question and I found the answer I was looking for [here](https://stackoverflow.com/questions/40961482/how-to-use-get-random-bytes-in-linux-kernel-module). Thank you for the help, I'll amend the main post – Projava Jun 20 '18 at 15:54

0 Answers0