All of lore.kernel.org
 help / color / mirror / Atom feed
* Regarding getrandom syscall
@ 2016-06-18 12:02 Avantika Rawat
  2016-06-18 13:30 ` Anoop
  0 siblings, 1 reply; 10+ messages in thread
From: Avantika Rawat @ 2016-06-18 12:02 UTC (permalink / raw)
  To: kernelnewbies

Hi ALL,

I am trying to use getrandom syscall in kernel 3.10.20 by following this
link

https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=c6e9d6f38894798696f23c8084ca7edbf16ee895

i have compiled the kernel and now want to call the getrandom syscall from
userspace to generate random numbers. But i am getting following error
while calling the getrandom () from userspace.

(.text.startup+0x18): undefined reference to `getrandom'
(.text.startup+0x1c): undefined reference to `getrandom'


-- 
Regards,
Avantika Rawat
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20160618/6c77b282/attachment.html 

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Regarding getrandom syscall
  2016-06-18 12:02 Regarding getrandom syscall Avantika Rawat
@ 2016-06-18 13:30 ` Anoop
  2016-06-18 13:42   ` Sayutin Dmitry
  0 siblings, 1 reply; 10+ messages in thread
From: Anoop @ 2016-06-18 13:30 UTC (permalink / raw)
  To: kernelnewbies

Hi Avantika,

On Sat, Jun 18, 2016 at 5:32 PM, Avantika Rawat <avani.rawat@gmail.com> wrote:
> Hi ALL,
>
> I am trying to use getrandom syscall in kernel 3.10.20 by following this
> link
>
> https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=c6e9d6f38894798696f23c8084ca7edbf16ee895
>
> i have compiled the kernel and now want to call the getrandom syscall from
> userspace to generate random numbers. But i am getting following error while
> calling the getrandom () from userspace.
>
> (.text.startup+0x18): undefined reference to `getrandom'
> (.text.startup+0x1c): undefined reference to `getrandom'
Your user space program will not know where 'getrandom' is defined
unless it's in the C library. You need to research more on how to call
custom system calls.

-Anoop

>
>
> --
> Regards,
> Avantika Rawat
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Regarding getrandom syscall
  2016-06-18 13:30 ` Anoop
@ 2016-06-18 13:42   ` Sayutin Dmitry
  2016-06-21 13:41     ` Avantika Rawat
  0 siblings, 1 reply; 10+ messages in thread
From: Sayutin Dmitry @ 2016-06-18 13:42 UTC (permalink / raw)
  To: kernelnewbies

Well, in fact it is not hard.

Just use syscall(2) provided by libc.

You need to provide to this function syscall id and syscall args.
Syscall id can be retrieved from macro constant
Should look something like:

#define _GNU_SOURCE
#include <unistd.h>
#include <sys/syscall.h>

syscall(SYS_getrandom, -- your - args - here --);

It returns long value - the result of syscall.
If it is between [-4095; -1] then it is negated errno, otherways it is return value.


18.06.2016, 16:32, "Anoop" <anoop.chargotra@gmail.com>:
> Hi Avantika,
>
> On Sat, Jun 18, 2016 at 5:32 PM, Avantika Rawat <avani.rawat@gmail.com> wrote:
>> ?Hi ALL,
>>
>> ?I am trying to use getrandom syscall in kernel 3.10.20 by following this
>> ?link
>>
>> ?https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=c6e9d6f38894798696f23c8084ca7edbf16ee895
>>
>> ?i have compiled the kernel and now want to call the getrandom syscall from
>> ?userspace to generate random numbers. But i am getting following error while
>> ?calling the getrandom () from userspace.
>>
>> ?(.text.startup+0x18): undefined reference to `getrandom'
>> ?(.text.startup+0x1c): undefined reference to `getrandom'
>
> Your user space program will not know where 'getrandom' is defined
> unless it's in the C library. You need to research more on how to call
> custom system calls.
>
> -Anoop
>
>> ?--
>> ?Regards,
>> ?Avantika Rawat
>>
>> ?_______________________________________________
>> ?Kernelnewbies mailing list
>> ?Kernelnewbies at kernelnewbies.org
>> ?http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

-----
Sayutin Dmitry <cdkrot@yandex.com>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Regarding getrandom syscall
  2016-06-18 13:42   ` Sayutin Dmitry
@ 2016-06-21 13:41     ` Avantika Rawat
  2016-06-21 19:10       ` Manuel Pégourié-Gonnard
  0 siblings, 1 reply; 10+ messages in thread
From: Avantika Rawat @ 2016-06-21 13:41 UTC (permalink / raw)
  To: kernelnewbies

Hi,

Thanks for the suggestion but i am getting following error

 error: 'SYS_getrandom' undeclared (first use in this function)

then i have replaced the SYS_getrandom by 275 in syscall(275, -- args--);
as 275 is the  __NR_getrandom defines in unistd.h file,  but it is
returning -1.
Can somebody tell me what i am missing here??

 . Also in /proc/kallsyms it is showing two syscalls added for getrandom

ffffffff80417a38 T SyS_getrandom
ffffffff80417a38 T sys_getrandom

On Sat, Jun 18, 2016 at 7:12 PM, Sayutin Dmitry <cdkrot@yandex.ru> wrote:
> Well, in fact it is not hard.
>
> Just use syscall(2) provided by libc.
>
> You need to provide to this function syscall id and syscall args.
> Syscall id can be retrieved from macro constant
> Should look something like:
>
> #define _GNU_SOURCE
> #include <unistd.h>
> #include <sys/syscall.h>
>
> syscall(SYS_getrandom, -- your - args - here --);
>
> It returns long value - the result of syscall.
> If it is between [-4095; -1] then it is negated errno, otherways it is return value.
>
>
> 18.06.2016, 16:32, "Anoop" <anoop.chargotra@gmail.com>:
>> Hi Avantika,
>>
>> On Sat, Jun 18, 2016 at 5:32 PM, Avantika Rawat <avani.rawat@gmail.com> wrote:
>>>  Hi ALL,
>>>
>>>  I am trying to use getrandom syscall in kernel 3.10.20 by following this
>>>  link
>>>
>>>  https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=c6e9d6f38894798696f23c8084ca7edbf16ee895
>>>
>>>  i have compiled the kernel and now want to call the getrandom syscall from
>>>  userspace to generate random numbers. But i am getting following error while
>>>  calling the getrandom () from userspace.
>>>
>>>  (.text.startup+0x18): undefined reference to `getrandom'
>>>  (.text.startup+0x1c): undefined reference to `getrandom'
>>
>> Your user space program will not know where 'getrandom' is defined
>> unless it's in the C library. You need to research more on how to call
>> custom system calls.
>>
>> -Anoop
>>
>>>  --
>>>  Regards,
>>>  Avantika Rawat
>>>
>>>  _______________________________________________
>>>  Kernelnewbies mailing list
>>>  Kernelnewbies at kernelnewbies.org
>>>  http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>
>> _______________________________________________
>> Kernelnewbies mailing list
>> Kernelnewbies at kernelnewbies.org
>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
> -----
> Sayutin Dmitry <cdkrot@yandex.com>



-- 
Regards,
Avantika Rawat

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Regarding getrandom syscall
  2016-06-21 13:41     ` Avantika Rawat
@ 2016-06-21 19:10       ` Manuel Pégourié-Gonnard
  2016-06-22 14:58         ` Avantika Rawat
  0 siblings, 1 reply; 10+ messages in thread
From: Manuel Pégourié-Gonnard @ 2016-06-21 19:10 UTC (permalink / raw)
  To: kernelnewbies

Hi,

Maybe your unistd.h comes from an older kernel? That would explain why
it doesn't define that symbol.

Here [1] is some code using that syscall successfully, you can see it
looks a lot like Sayutin's code, except it does a few more compile-time
and runtime checks to fallback on using /dev/urandom if necessary.

[1]:
https://github.com/ARMmbed/mbedtls/blob/dd9895d8101f17ce804830472cbb140eba1c46a0/library/entropy_poll.c#L85

Manuel.


On 21/06/2016 15:41, Avantika Rawat wrote:
> Hi,
> 
> Thanks for the suggestion but i am getting following error
> 
>  error: 'SYS_getrandom' undeclared (first use in this function)
> 
> then i have replaced the SYS_getrandom by 275 in syscall(275, -- args--);
> as 275 is the  __NR_getrandom defines in unistd.h file,  but it is
> returning -1.
> Can somebody tell me what i am missing here??
> 
>  . Also in /proc/kallsyms it is showing two syscalls added for getrandom
> 
> ffffffff80417a38 T SyS_getrandom
> ffffffff80417a38 T sys_getrandom
> 
> On Sat, Jun 18, 2016 at 7:12 PM, Sayutin Dmitry <cdkrot@yandex.ru> wrote:
>> Well, in fact it is not hard.
>>
>> Just use syscall(2) provided by libc.
>>
>> You need to provide to this function syscall id and syscall args.
>> Syscall id can be retrieved from macro constant
>> Should look something like:
>>
>> #define _GNU_SOURCE
>> #include <unistd.h>
>> #include <sys/syscall.h>
>>
>> syscall(SYS_getrandom, -- your - args - here --);
>>
>> It returns long value - the result of syscall.
>> If it is between [-4095; -1] then it is negated errno, otherways it is return value.
>>
>>
>> 18.06.2016, 16:32, "Anoop" <anoop.chargotra@gmail.com>:
>>> Hi Avantika,
>>>
>>> On Sat, Jun 18, 2016 at 5:32 PM, Avantika Rawat <avani.rawat@gmail.com> wrote:
>>>>  Hi ALL,
>>>>
>>>>  I am trying to use getrandom syscall in kernel 3.10.20 by following this
>>>>  link
>>>>
>>>>  https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=c6e9d6f38894798696f23c8084ca7edbf16ee895
>>>>
>>>>  i have compiled the kernel and now want to call the getrandom syscall from
>>>>  userspace to generate random numbers. But i am getting following error while
>>>>  calling the getrandom () from userspace.
>>>>
>>>>  (.text.startup+0x18): undefined reference to `getrandom'
>>>>  (.text.startup+0x1c): undefined reference to `getrandom'
>>>
>>> Your user space program will not know where 'getrandom' is defined
>>> unless it's in the C library. You need to research more on how to call
>>> custom system calls.
>>>
>>> -Anoop
>>>
>>>>  --
>>>>  Regards,
>>>>  Avantika Rawat
>>>>
>>>>  _______________________________________________
>>>>  Kernelnewbies mailing list
>>>>  Kernelnewbies at kernelnewbies.org
>>>>  http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>>
>>> _______________________________________________
>>> Kernelnewbies mailing list
>>> Kernelnewbies at kernelnewbies.org
>>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>
>> -----
>> Sayutin Dmitry <cdkrot@yandex.com>
> 
> 
> 

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Regarding getrandom syscall
  2016-06-21 19:10       ` Manuel Pégourié-Gonnard
@ 2016-06-22 14:58         ` Avantika Rawat
  2016-06-22 16:15           ` Navin P.S
  2016-06-22 17:11           ` Markus Böhme
  0 siblings, 2 replies; 10+ messages in thread
From: Avantika Rawat @ 2016-06-22 14:58 UTC (permalink / raw)
  To: kernelnewbies

Hi ,

Thanks for the link but i am getting "Function not implemented" error.
I have added a custom syscall in kernel for testing, getting similar
error for that also. I am working on  3.10.20 Kernel and MIPS
architecture. Pasting the kernel changes done to spport getrandom
syscall in 3.10.20 kernel. Can someone please help me here that what
needs to be done.

--- linux-3.10.20/arch/x86/syscalls/syscall_32.tbl 2016-06-15
11:51:27.950025308 +0530
+++ linux-3.10.20_mod/arch/x86/syscalls/syscall_32.tbl 2016-06-15
11:48:02.222020102 +0530
@@ -358,3 +358,4 @@
 349 i386 kcmp sys_kcmp
 350 i386 finit_module sys_finit_module
 351 i386 msa sys_msa
+352 i386    getrandom           sys_getrandom
--- linux-3.10.20/arch/x86/syscalls/syscall_64.tbl 2016-06-15
11:51:27.950025308 +0530
+++ linux-3.10.20_mod/arch/x86/syscalls/syscall_64.tbl 2016-06-15
11:48:16.118020453 +0530
@@ -321,6 +321,7 @@
 312 common kcmp sys_kcmp
 313 common finit_module sys_finit_module
 314 common msa sys_msa
+315 common getrandom sys_getrandom

 #
 # x32-specific system call numbers start at 512 to avoid cache impact
--- linux-3.10.20/drivers/char/random.c 2016-06-15 11:51:27.998025309 +0530
+++ linux-3.10.20_mod/drivers/char/random.c 2016-06-15 11:48:34.774020925 +0530
@@ -265,6 +265,8 @@
 #include <asm/irq.h>
 #include <asm/irq_regs.h>
 #include <asm/io.h>
+#include <linux/syscalls.h>
+#include <linux/completion.h>

 #define CREATE_TRACE_POINTS
 #include <trace/events/random.h>
@@ -397,6 +399,7 @@ static struct poolinfo {
  */
 static DECLARE_WAIT_QUEUE_HEAD(random_read_wait);
 static DECLARE_WAIT_QUEUE_HEAD(random_write_wait);
+static DECLARE_WAIT_QUEUE_HEAD(urandom_init_wait);
 static struct fasync_struct *fasync;

 static bool debug;
@@ -1018,13 +1021,14 @@ static ssize_t extract_entropy_user(stru
 {
  ssize_t ret = 0, i;
  __u8 tmp[EXTRACT_SIZE];
+    int large_request = (nbytes > 256);

  trace_extract_entropy_user(r->name, nbytes, r->entropy_count, _RET_IP_);
  xfer_secondary_pool(r, nbytes);
  nbytes = account(r, nbytes, 0, 0);

  while (nbytes) {
- if (need_resched()) {
+        if (large_request && need_resched()) {
  if (signal_pending(current)) {
  if (ret == 0)
  ret = -ERESTARTSYS;
@@ -1158,7 +1162,7 @@ void rand_initialize_disk(struct gendisk
 #endif

 static ssize_t
-random_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
+_random_read(int nonblock, char __user *buf, size_t nbytes)
 {
  ssize_t n, retval = 0, count = 0;

@@ -1183,7 +1187,7 @@ random_read(struct file *file, char __us
   n*8, (nbytes-n)*8);

  if (n == 0) {
- if (file->f_flags & O_NONBLOCK) {
+ if (nonblock) {
  retval = -EAGAIN;
  break;
  }
@@ -1215,6 +1219,13 @@ random_read(struct file *file, char __us
 }

 static ssize_t
+random_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
+    {
+    return _random_read(file->f_flags & O_NONBLOCK, buf, nbytes);
+    }
+
+
+static ssize_t
 urandom_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
 {
  return extract_entropy_user(&nonblocking_pool, buf, nbytes);
@@ -1340,6 +1351,29 @@ const struct file_operations urandom_fop
  .llseek = noop_llseek,
 };

+SYSCALL_DEFINE3 (getrandom, char __user *, buf, size_t, count,
+ unsigned int, flags)
+    {
+    if (flags & ~(GRND_NONBLOCK|GRND_RANDOM))
+        return -EINVAL;
+
+    if (count > INT_MAX)
+        count = INT_MAX;
+
+    if (flags & GRND_RANDOM)
+        return _random_read(flags & GRND_NONBLOCK, buf, count);
+
+    if (unlikely(nonblocking_pool.initialized == 0)) {
+        if (flags & GRND_NONBLOCK)
+            return -EAGAIN;
+        wait_event_interruptible(urandom_init_wait,
+                                 nonblocking_pool.initialized);
+        if (signal_pending(current))
+            return -ERESTARTSYS;
+    }
+    return urandom_read(NULL, buf, count, NULL);
+    }
+
 /***************************************************************
  * Random UUID interface
  *
--- linux-3.10.20/include/linux/syscalls.h 2016-06-15 11:51:28.246025315 +0530
+++ linux-3.10.20_mod/include/linux/syscalls.h 2016-06-15
11:49:11.918021865 +0530
@@ -852,4 +852,6 @@ asmlinkage long sys_process_vm_writev(pi
 asmlinkage long sys_kcmp(pid_t pid1, pid_t pid2, int type,
  unsigned long idx1, unsigned long idx2);
 asmlinkage long sys_finit_module(int fd, const char __user *uargs, int flags);
+asmlinkage long sys_getrandom(char __user *buf, size_t count,
+      unsigned int flags);
 #endif
--- linux-3.10.20/include/uapi/asm-generic/unistd.h 2016-06-15
11:51:28.258025315 +0530
+++ linux-3.10.20_mod/include/uapi/asm-generic/unistd.h 2016-06-15
11:49:32.558022388 +0530
@@ -694,9 +694,11 @@ __SYSCALL(__NR_kcmp, sys_kcmp)
 __SYSCALL(__NR_finit_module, sys_finit_module)
 #define __NR_msa 274
 __SYSCALL(__NR_msa, sys_msa)
+#define __NR_getrandom 275
+__SYSCALL(__NR_getrandom, sys_getrandom)

 #undef __NR_syscalls
-#define __NR_syscalls 275
+#define __NR_syscalls 276

 /*
  * All syscalls below here should go away really,
--- linux-3.10.20/include/uapi/linux/random.h 2013-11-21
01:58:01.000000000 +0530
+++ linux-3.10.20_mod/include/uapi/linux/random.h 2016-06-15
11:50:06.350023243 +0530
@@ -40,6 +40,15 @@ struct rand_pool_info {
  __u32 buf[0];
 };

+/*
+ * Flags for getrandom(2)
+ *
+ * GRND_NONBLOCK Don't block and return EAGAIN instead
+ * GRND_RANDOM Use the /dev/random pool instead of /dev/urandom
+ */
+#define GRND_NONBLOCK 0x0001
+#define GRND_RANDOM 0x0002
+
 struct rnd_state {
  __u32 s1, s2, s3;
 };


On Wed, Jun 22, 2016 at 12:40 AM, Manuel P?gouri?-Gonnard
<mpg@elzevir.fr> wrote:
> Hi,
>
> Maybe your unistd.h comes from an older kernel? That would explain why
> it doesn't define that symbol.
>
> Here [1] is some code using that syscall successfully, you can see it
> looks a lot like Sayutin's code, except it does a few more compile-time
> and runtime checks to fallback on using /dev/urandom if necessary.
>
> [1]:
> https://github.com/ARMmbed/mbedtls/blob/dd9895d8101f17ce804830472cbb140eba1c46a0/library/entropy_poll.c#L85
>
> Manuel.
>
>
> On 21/06/2016 15:41, Avantika Rawat wrote:
>> Hi,
>>
>> Thanks for the suggestion but i am getting following error
>>
>>  error: 'SYS_getrandom' undeclared (first use in this function)
>>
>> then i have replaced the SYS_getrandom by 275 in syscall(275, -- args--);
>> as 275 is the  __NR_getrandom defines in unistd.h file,  but it is
>> returning -1.
>> Can somebody tell me what i am missing here??
>>
>>  . Also in /proc/kallsyms it is showing two syscalls added for getrandom
>>
>> ffffffff80417a38 T SyS_getrandom
>> ffffffff80417a38 T sys_getrandom
>>
>> On Sat, Jun 18, 2016 at 7:12 PM, Sayutin Dmitry <cdkrot@yandex.ru> wrote:
>>> Well, in fact it is not hard.
>>>
>>> Just use syscall(2) provided by libc.
>>>
>>> You need to provide to this function syscall id and syscall args.
>>> Syscall id can be retrieved from macro constant
>>> Should look something like:
>>>
>>> #define _GNU_SOURCE
>>> #include <unistd.h>
>>> #include <sys/syscall.h>
>>>
>>> syscall(SYS_getrandom, -- your - args - here --);
>>>
>>> It returns long value - the result of syscall.
>>> If it is between [-4095; -1] then it is negated errno, otherways it is return value.
>>>
>>>
>>> 18.06.2016, 16:32, "Anoop" <anoop.chargotra@gmail.com>:
>>>> Hi Avantika,
>>>>
>>>> On Sat, Jun 18, 2016 at 5:32 PM, Avantika Rawat <avani.rawat@gmail.com> wrote:
>>>>>  Hi ALL,
>>>>>
>>>>>  I am trying to use getrandom syscall in kernel 3.10.20 by following this
>>>>>  link
>>>>>
>>>>>  https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=c6e9d6f38894798696f23c8084ca7edbf16ee895
>>>>>
>>>>>  i have compiled the kernel and now want to call the getrandom syscall from
>>>>>  userspace to generate random numbers. But i am getting following error while
>>>>>  calling the getrandom () from userspace.
>>>>>
>>>>>  (.text.startup+0x18): undefined reference to `getrandom'
>>>>>  (.text.startup+0x1c): undefined reference to `getrandom'
>>>>
>>>> Your user space program will not know where 'getrandom' is defined
>>>> unless it's in the C library. You need to research more on how to call
>>>> custom system calls.
>>>>
>>>> -Anoop
>>>>
>>>>>  --
>>>>>  Regards,
>>>>>  Avantika Rawat
>>>>>
>>>>>  _______________________________________________
>>>>>  Kernelnewbies mailing list
>>>>>  Kernelnewbies at kernelnewbies.org
>>>>>  http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>>>
>>>> _______________________________________________
>>>> Kernelnewbies mailing list
>>>> Kernelnewbies at kernelnewbies.org
>>>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>>
>>> -----
>>> Sayutin Dmitry <cdkrot@yandex.com>
>>
>>
>>



-- 
Regards,
Avantika Rawat

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Regarding getrandom syscall
  2016-06-22 14:58         ` Avantika Rawat
@ 2016-06-22 16:15           ` Navin P.S
  2016-06-22 16:40             ` Avantika Rawat
  2016-06-22 17:11           ` Markus Böhme
  1 sibling, 1 reply; 10+ messages in thread
From: Navin P.S @ 2016-06-22 16:15 UTC (permalink / raw)
  To: kernelnewbies

On Wed, Jun 22, 2016 at 8:28 PM, Avantika Rawat <avani.rawat@gmail.com> wrote:
> Hi ,
>
> Thanks for the link but i am getting "Function not implemented" error.
> I have added a custom syscall in kernel for testing, getting similar
> error for that also. I am working on  3.10.20 Kernel and MIPS
> architecture. Pasting the kernel changes done to spport getrandom
> syscall in 3.10.20 kernel. Can someone please help me here that what
> needs to be done.
>
> --- linux-3.10.20/arch/x86/syscalls/syscall_32.tbl 2016-06-15
> 11:51:27.950025308 +0530
> +++ linux-3.10.20_mod/arch/x86/syscalls/syscall_32.tbl 2016-06-15
> 11:48:02.222020102 +0530
> @@ -358,3 +358,4 @@
>  349 i386 kcmp sys_kcmp
>  350 i386 finit_module sys_finit_module
>  351 i386 msa sys_msa
> +352 i386    getrandom           sys_getrandom
> --- linux-3.10.20/arch/x86/syscalls/syscall_64.tbl 2016-06-15
> 11:51:27.950025308 +0530
> +++ linux-3.10.20_mod/arch/x86/syscalls/syscall_64.tbl 2016-06-15
> 11:48:16.118020453 +0530
> @@ -321,6 +321,7 @@
>  312 common kcmp sys_kcmp
>  313 common finit_module sys_finit_module
>  314 common msa sys_msa
> +315 common getrandom sys_getrandom
>
>  #
>  # x32-specific system call numbers start at 512 to avoid cache impact
> --- linux-3.10.20/drivers/char/random.c 2016-06-15 11:51:27.998025309 +0530
> +++ linux-3.10.20_mod/drivers/char/random.c 2016-06-15 11:48:34.774020925 +0530
> @@ -265,6 +265,8 @@
>  #include <asm/irq.h>
>  #include <asm/irq_regs.h>
>  #include <asm/io.h>
> +#include <linux/syscalls.h>
> +#include <linux/completion.h>
>
>  #define CREATE_TRACE_POINTS
>  #include <trace/events/random.h>
> @@ -397,6 +399,7 @@ static struct poolinfo {
>   */
>  static DECLARE_WAIT_QUEUE_HEAD(random_read_wait);
>  static DECLARE_WAIT_QUEUE_HEAD(random_write_wait);
> +static DECLARE_WAIT_QUEUE_HEAD(urandom_init_wait);
>  static struct fasync_struct *fasync;
>
>  static bool debug;
> @@ -1018,13 +1021,14 @@ static ssize_t extract_entropy_user(stru
>  {
>   ssize_t ret = 0, i;
>   __u8 tmp[EXTRACT_SIZE];
> +    int large_request = (nbytes > 256);
>
>   trace_extract_entropy_user(r->name, nbytes, r->entropy_count, _RET_IP_);
>   xfer_secondary_pool(r, nbytes);
>   nbytes = account(r, nbytes, 0, 0);
>
>   while (nbytes) {
> - if (need_resched()) {
> +        if (large_request && need_resched()) {
>   if (signal_pending(current)) {
>   if (ret == 0)
>   ret = -ERESTARTSYS;
> @@ -1158,7 +1162,7 @@ void rand_initialize_disk(struct gendisk
>  #endif
>
>  static ssize_t
> -random_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
> +_random_read(int nonblock, char __user *buf, size_t nbytes)
>  {
>   ssize_t n, retval = 0, count = 0;
>
> @@ -1183,7 +1187,7 @@ random_read(struct file *file, char __us
>    n*8, (nbytes-n)*8);
>
>   if (n == 0) {
> - if (file->f_flags & O_NONBLOCK) {
> + if (nonblock) {
>   retval = -EAGAIN;
>   break;
>   }
> @@ -1215,6 +1219,13 @@ random_read(struct file *file, char __us
>  }
>
>  static ssize_t
> +random_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
> +    {
> +    return _random_read(file->f_flags & O_NONBLOCK, buf, nbytes);
> +    }
> +
> +
> +static ssize_t
>  urandom_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
>  {
>   return extract_entropy_user(&nonblocking_pool, buf, nbytes);
> @@ -1340,6 +1351,29 @@ const struct file_operations urandom_fop
>   .llseek = noop_llseek,
>  };
>
> +SYSCALL_DEFINE3 (getrandom, char __user *, buf, size_t, count,
> + unsigned int, flags)
> +    {
> +    if (flags & ~(GRND_NONBLOCK|GRND_RANDOM))
> +        return -EINVAL;
> +
> +    if (count > INT_MAX)
> +        count = INT_MAX;
> +
> +    if (flags & GRND_RANDOM)
> +        return _random_read(flags & GRND_NONBLOCK, buf, count);
> +
> +    if (unlikely(nonblocking_pool.initialized == 0)) {
> +        if (flags & GRND_NONBLOCK)
> +            return -EAGAIN;
> +        wait_event_interruptible(urandom_init_wait,
> +                                 nonblocking_pool.initialized);
> +        if (signal_pending(current))
> +            return -ERESTARTSYS;
> +    }
> +    return urandom_read(NULL, buf, count, NULL);
> +    }
> +
>  /***************************************************************
>   * Random UUID interface
>   *
> --- linux-3.10.20/include/linux/syscalls.h 2016-06-15 11:51:28.246025315 +0530
> +++ linux-3.10.20_mod/include/linux/syscalls.h 2016-06-15
> 11:49:11.918021865 +0530
> @@ -852,4 +852,6 @@ asmlinkage long sys_process_vm_writev(pi
>  asmlinkage long sys_kcmp(pid_t pid1, pid_t pid2, int type,
>   unsigned long idx1, unsigned long idx2);
>  asmlinkage long sys_finit_module(int fd, const char __user *uargs, int flags);
> +asmlinkage long sys_getrandom(char __user *buf, size_t count,
> +      unsigned int flags);
>  #endif
> --- linux-3.10.20/include/uapi/asm-generic/unistd.h 2016-06-15
> 11:51:28.258025315 +0530
> +++ linux-3.10.20_mod/include/uapi/asm-generic/unistd.h 2016-06-15
> 11:49:32.558022388 +0530
> @@ -694,9 +694,11 @@ __SYSCALL(__NR_kcmp, sys_kcmp)
>  __SYSCALL(__NR_finit_module, sys_finit_module)
>  #define __NR_msa 274
>  __SYSCALL(__NR_msa, sys_msa)
> +#define __NR_getrandom 275
> +__SYSCALL(__NR_getrandom, sys_getrandom)
>
>  #undef __NR_syscalls
> -#define __NR_syscalls 275
> +#define __NR_syscalls 276
>
>  /*
>   * All syscalls below here should go away really,
> --- linux-3.10.20/include/uapi/linux/random.h 2013-11-21
> 01:58:01.000000000 +0530
> +++ linux-3.10.20_mod/include/uapi/linux/random.h 2016-06-15
> 11:50:06.350023243 +0530
> @@ -40,6 +40,15 @@ struct rand_pool_info {
>   __u32 buf[0];
>  };
>
> +/*
> + * Flags for getrandom(2)
> + *
> + * GRND_NONBLOCK Don't block and return EAGAIN instead
> + * GRND_RANDOM Use the /dev/random pool instead of /dev/urandom
> + */
> +#define GRND_NONBLOCK 0x0001
> +#define GRND_RANDOM 0x0002
> +
>  struct rnd_state {
>   __u32 s1, s2, s3;
>  };
>
>
> On Wed, Jun 22, 2016 at 12:40 AM, Manuel P?gouri?-Gonnard
> <mpg@elzevir.fr> wrote:
>> Hi,
>>
>> Maybe your unistd.h comes from an older kernel? That would explain why
>> it doesn't define that symbol.
>>
>> Here [1] is some code using that syscall successfully, you can see it
>> looks a lot like Sayutin's code, except it does a few more compile-time
>> and runtime checks to fallback on using /dev/urandom if necessary.
>>
>> [1]:
>> https://github.com/ARMmbed/mbedtls/blob/dd9895d8101f17ce804830472cbb140eba1c46a0/library/entropy_poll.c#L85
>>
>> Manuel.
>>
>>
>> On 21/06/2016 15:41, Avantika Rawat wrote:
>>> Hi,
>>>
>>> Thanks for the suggestion but i am getting following error
>>>
>>>  error: 'SYS_getrandom' undeclared (first use in this function)
>>>
>>> then i have replaced the SYS_getrandom by 275 in syscall(275, -- args--);
>>> as 275 is the  __NR_getrandom defines in unistd.h file,  but it is
>>> returning -1.
>>> Can somebody tell me what i am missing here??
>>>
>>>  . Also in /proc/kallsyms it is showing two syscalls added for getrandom
>>>
>>> ffffffff80417a38 T SyS_getrandom
>>> ffffffff80417a38 T sys_getrandom
>>>
>>> On Sat, Jun 18, 2016 at 7:12 PM, Sayutin Dmitry <cdkrot@yandex.ru> wrote:
>>>> Well, in fact it is not hard.
>>>>
>>>> Just use syscall(2) provided by libc.
>>>>
>>>> You need to provide to this function syscall id and syscall args.
>>>> Syscall id can be retrieved from macro constant
>>>> Should look something like:
>>>>
>>>> #define _GNU_SOURCE
>>>> #include <unistd.h>
>>>> #include <sys/syscall.h>
>>>>
>>>> syscall(SYS_getrandom, -- your - args - here --);
>>>>
>>>> It returns long value - the result of syscall.
>>>> If it is between [-4095; -1] then it is negated errno, otherways it is return value.
>>>>
>>>>
>>>> 18.06.2016, 16:32, "Anoop" <anoop.chargotra@gmail.com>:
>>>>> Hi Avantika,
>>>>>
>>>>> On Sat, Jun 18, 2016 at 5:32 PM, Avantika Rawat <avani.rawat@gmail.com> wrote:
>>>>>>  Hi ALL,
>>>>>>
>>>>>>  I am trying to use getrandom syscall in kernel 3.10.20 by following this
>>>>>>  link
>>>>>>
>>>>>>  https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=c6e9d6f38894798696f23c8084ca7edbf16ee895
>>>>>>
>>>>>>  i have compiled the kernel and now want to call the getrandom syscall from
>>>>>>  userspace to generate random numbers. But i am getting following error while
>>>>>>  calling the getrandom () from userspace.
>>>>>>
>>>>>>  (.text.startup+0x18): undefined reference to `getrandom'
>>>>>>  (.text.startup+0x1c): undefined reference to `getrandom'
>>>>>
>>>>> Your user space program will not know where 'getrandom' is defined
>>>>> unless it's in the C library. You need to research more on how to call
>>>>> custom system calls.
>>>>>
>>>>> -Anoop
>>>>>
>>>>>>  --
>>>>>>  Regards,
>>>>>>  Avantika Rawat
>>>>>>
>>>>>>  _______________________________________________
>>>>>>  Kernelnewbies mailing list
>>>>>>  Kernelnewbies at kernelnewbies.org
>>>>>>  http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>>>>
>>>>> _______________________________________________
>>>>> Kernelnewbies mailing list
>>>>> Kernelnewbies at kernelnewbies.org
>>>>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>>>
>>>> -----
>>>> Sayutin Dmitry <cdkrot@yandex.com>
>>>
>>>
>>>
>
>
>
> --
> Regards,
> Avantika Rawat
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

I think you need to 352 or 315 ie the values from .tbl (so 315 if you
are calling on a x64 kernel or 352 if you are calling x86 kernel). The
275 is for the uapi but syscall accepts the 315 value on a x64.

 Please try with 315 and 352 after running your modified kernel and
report back. Atleast that is the way it worked for me on a 4.x kernel.
Ideally uapi is for userspace like glibc and they come man 3 where as
the syscall is (man 2) ie system call.

-- 
-- Navin

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Regarding getrandom syscall
  2016-06-22 16:15           ` Navin P.S
@ 2016-06-22 16:40             ` Avantika Rawat
  0 siblings, 0 replies; 10+ messages in thread
From: Avantika Rawat @ 2016-06-22 16:40 UTC (permalink / raw)
  To: kernelnewbies

Hi

I have already tried that value by checking in forums but got the same
error.
On Jun 22, 2016 9:46 PM, "Navin P.S" <navinp1912@gmail.com> wrote:

> On Wed, Jun 22, 2016 at 8:28 PM, Avantika Rawat <avani.rawat@gmail.com>
> wrote:
> > Hi ,
> >
> > Thanks for the link but i am getting "Function not implemented" error.
> > I have added a custom syscall in kernel for testing, getting similar
> > error for that also. I am working on  3.10.20 Kernel and MIPS
> > architecture. Pasting the kernel changes done to spport getrandom
> > syscall in 3.10.20 kernel. Can someone please help me here that what
> > needs to be done.
> >
> > --- linux-3.10.20/arch/x86/syscalls/syscall_32.tbl 2016-06-15
> > 11:51:27.950025308 +0530
> > +++ linux-3.10.20_mod/arch/x86/syscalls/syscall_32.tbl 2016-06-15
> > 11:48:02.222020102 +0530
> > @@ -358,3 +358,4 @@
> >  349 i386 kcmp sys_kcmp
> >  350 i386 finit_module sys_finit_module
> >  351 i386 msa sys_msa
> > +352 i386    getrandom           sys_getrandom
> > --- linux-3.10.20/arch/x86/syscalls/syscall_64.tbl 2016-06-15
> > 11:51:27.950025308 +0530
> > +++ linux-3.10.20_mod/arch/x86/syscalls/syscall_64.tbl 2016-06-15
> > 11:48:16.118020453 +0530
> > @@ -321,6 +321,7 @@
> >  312 common kcmp sys_kcmp
> >  313 common finit_module sys_finit_module
> >  314 common msa sys_msa
> > +315 common getrandom sys_getrandom
> >
> >  #
> >  # x32-specific system call numbers start at 512 to avoid cache impact
> > --- linux-3.10.20/drivers/char/random.c 2016-06-15 11:51:27.998025309
> +0530
> > +++ linux-3.10.20_mod/drivers/char/random.c 2016-06-15
> 11:48:34.774020925 +0530
> > @@ -265,6 +265,8 @@
> >  #include <asm/irq.h>
> >  #include <asm/irq_regs.h>
> >  #include <asm/io.h>
> > +#include <linux/syscalls.h>
> > +#include <linux/completion.h>
> >
> >  #define CREATE_TRACE_POINTS
> >  #include <trace/events/random.h>
> > @@ -397,6 +399,7 @@ static struct poolinfo {
> >   */
> >  static DECLARE_WAIT_QUEUE_HEAD(random_read_wait);
> >  static DECLARE_WAIT_QUEUE_HEAD(random_write_wait);
> > +static DECLARE_WAIT_QUEUE_HEAD(urandom_init_wait);
> >  static struct fasync_struct *fasync;
> >
> >  static bool debug;
> > @@ -1018,13 +1021,14 @@ static ssize_t extract_entropy_user(stru
> >  {
> >   ssize_t ret = 0, i;
> >   __u8 tmp[EXTRACT_SIZE];
> > +    int large_request = (nbytes > 256);
> >
> >   trace_extract_entropy_user(r->name, nbytes, r->entropy_count,
> _RET_IP_);
> >   xfer_secondary_pool(r, nbytes);
> >   nbytes = account(r, nbytes, 0, 0);
> >
> >   while (nbytes) {
> > - if (need_resched()) {
> > +        if (large_request && need_resched()) {
> >   if (signal_pending(current)) {
> >   if (ret == 0)
> >   ret = -ERESTARTSYS;
> > @@ -1158,7 +1162,7 @@ void rand_initialize_disk(struct gendisk
> >  #endif
> >
> >  static ssize_t
> > -random_read(struct file *file, char __user *buf, size_t nbytes, loff_t
> *ppos)
> > +_random_read(int nonblock, char __user *buf, size_t nbytes)
> >  {
> >   ssize_t n, retval = 0, count = 0;
> >
> > @@ -1183,7 +1187,7 @@ random_read(struct file *file, char __us
> >    n*8, (nbytes-n)*8);
> >
> >   if (n == 0) {
> > - if (file->f_flags & O_NONBLOCK) {
> > + if (nonblock) {
> >   retval = -EAGAIN;
> >   break;
> >   }
> > @@ -1215,6 +1219,13 @@ random_read(struct file *file, char __us
> >  }
> >
> >  static ssize_t
> > +random_read(struct file *file, char __user *buf, size_t nbytes, loff_t
> *ppos)
> > +    {
> > +    return _random_read(file->f_flags & O_NONBLOCK, buf, nbytes);
> > +    }
> > +
> > +
> > +static ssize_t
> >  urandom_read(struct file *file, char __user *buf, size_t nbytes, loff_t
> *ppos)
> >  {
> >   return extract_entropy_user(&nonblocking_pool, buf, nbytes);
> > @@ -1340,6 +1351,29 @@ const struct file_operations urandom_fop
> >   .llseek = noop_llseek,
> >  };
> >
> > +SYSCALL_DEFINE3 (getrandom, char __user *, buf, size_t, count,
> > + unsigned int, flags)
> > +    {
> > +    if (flags & ~(GRND_NONBLOCK|GRND_RANDOM))
> > +        return -EINVAL;
> > +
> > +    if (count > INT_MAX)
> > +        count = INT_MAX;
> > +
> > +    if (flags & GRND_RANDOM)
> > +        return _random_read(flags & GRND_NONBLOCK, buf, count);
> > +
> > +    if (unlikely(nonblocking_pool.initialized == 0)) {
> > +        if (flags & GRND_NONBLOCK)
> > +            return -EAGAIN;
> > +        wait_event_interruptible(urandom_init_wait,
> > +                                 nonblocking_pool.initialized);
> > +        if (signal_pending(current))
> > +            return -ERESTARTSYS;
> > +    }
> > +    return urandom_read(NULL, buf, count, NULL);
> > +    }
> > +
> >  /***************************************************************
> >   * Random UUID interface
> >   *
> > --- linux-3.10.20/include/linux/syscalls.h 2016-06-15 11:51:28.246025315
> +0530
> > +++ linux-3.10.20_mod/include/linux/syscalls.h 2016-06-15
> > 11:49:11.918021865 +0530
> > @@ -852,4 +852,6 @@ asmlinkage long sys_process_vm_writev(pi
> >  asmlinkage long sys_kcmp(pid_t pid1, pid_t pid2, int type,
> >   unsigned long idx1, unsigned long idx2);
> >  asmlinkage long sys_finit_module(int fd, const char __user *uargs, int
> flags);
> > +asmlinkage long sys_getrandom(char __user *buf, size_t count,
> > +      unsigned int flags);
> >  #endif
> > --- linux-3.10.20/include/uapi/asm-generic/unistd.h 2016-06-15
> > 11:51:28.258025315 +0530
> > +++ linux-3.10.20_mod/include/uapi/asm-generic/unistd.h 2016-06-15
> > 11:49:32.558022388 +0530
> > @@ -694,9 +694,11 @@ __SYSCALL(__NR_kcmp, sys_kcmp)
> >  __SYSCALL(__NR_finit_module, sys_finit_module)
> >  #define __NR_msa 274
> >  __SYSCALL(__NR_msa, sys_msa)
> > +#define __NR_getrandom 275
> > +__SYSCALL(__NR_getrandom, sys_getrandom)
> >
> >  #undef __NR_syscalls
> > -#define __NR_syscalls 275
> > +#define __NR_syscalls 276
> >
> >  /*
> >   * All syscalls below here should go away really,
> > --- linux-3.10.20/include/uapi/linux/random.h 2013-11-21
> > 01:58:01.000000000 +0530
> > +++ linux-3.10.20_mod/include/uapi/linux/random.h 2016-06-15
> > 11:50:06.350023243 +0530
> > @@ -40,6 +40,15 @@ struct rand_pool_info {
> >   __u32 buf[0];
> >  };
> >
> > +/*
> > + * Flags for getrandom(2)
> > + *
> > + * GRND_NONBLOCK Don't block and return EAGAIN instead
> > + * GRND_RANDOM Use the /dev/random pool instead of /dev/urandom
> > + */
> > +#define GRND_NONBLOCK 0x0001
> > +#define GRND_RANDOM 0x0002
> > +
> >  struct rnd_state {
> >   __u32 s1, s2, s3;
> >  };
> >
> >
> > On Wed, Jun 22, 2016 at 12:40 AM, Manuel P?gouri?-Gonnard
> > <mpg@elzevir.fr> wrote:
> >> Hi,
> >>
> >> Maybe your unistd.h comes from an older kernel? That would explain why
> >> it doesn't define that symbol.
> >>
> >> Here [1] is some code using that syscall successfully, you can see it
> >> looks a lot like Sayutin's code, except it does a few more compile-time
> >> and runtime checks to fallback on using /dev/urandom if necessary.
> >>
> >> [1]:
> >>
> https://github.com/ARMmbed/mbedtls/blob/dd9895d8101f17ce804830472cbb140eba1c46a0/library/entropy_poll.c#L85
> >>
> >> Manuel.
> >>
> >>
> >> On 21/06/2016 15:41, Avantika Rawat wrote:
> >>> Hi,
> >>>
> >>> Thanks for the suggestion but i am getting following error
> >>>
> >>>  error: 'SYS_getrandom' undeclared (first use in this function)
> >>>
> >>> then i have replaced the SYS_getrandom by 275 in syscall(275, --
> args--);
> >>> as 275 is the  __NR_getrandom defines in unistd.h file,  but it is
> >>> returning -1.
> >>> Can somebody tell me what i am missing here??
> >>>
> >>>  . Also in /proc/kallsyms it is showing two syscalls added for
> getrandom
> >>>
> >>> ffffffff80417a38 T SyS_getrandom
> >>> ffffffff80417a38 T sys_getrandom
> >>>
> >>> On Sat, Jun 18, 2016 at 7:12 PM, Sayutin Dmitry <cdkrot@yandex.ru>
> wrote:
> >>>> Well, in fact it is not hard.
> >>>>
> >>>> Just use syscall(2) provided by libc.
> >>>>
> >>>> You need to provide to this function syscall id and syscall args.
> >>>> Syscall id can be retrieved from macro constant
> >>>> Should look something like:
> >>>>
> >>>> #define _GNU_SOURCE
> >>>> #include <unistd.h>
> >>>> #include <sys/syscall.h>
> >>>>
> >>>> syscall(SYS_getrandom, -- your - args - here --);
> >>>>
> >>>> It returns long value - the result of syscall.
> >>>> If it is between [-4095; -1] then it is negated errno, otherways it
> is return value.
> >>>>
> >>>>
> >>>> 18.06.2016, 16:32, "Anoop" <anoop.chargotra@gmail.com>:
> >>>>> Hi Avantika,
> >>>>>
> >>>>> On Sat, Jun 18, 2016 at 5:32 PM, Avantika Rawat <
> avani.rawat at gmail.com> wrote:
> >>>>>>  Hi ALL,
> >>>>>>
> >>>>>>  I am trying to use getrandom syscall in kernel 3.10.20 by
> following this
> >>>>>>  link
> >>>>>>
> >>>>>>
> https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=c6e9d6f38894798696f23c8084ca7edbf16ee895
> >>>>>>
> >>>>>>  i have compiled the kernel and now want to call the getrandom
> syscall from
> >>>>>>  userspace to generate random numbers. But i am getting following
> error while
> >>>>>>  calling the getrandom () from userspace.
> >>>>>>
> >>>>>>  (.text.startup+0x18): undefined reference to `getrandom'
> >>>>>>  (.text.startup+0x1c): undefined reference to `getrandom'
> >>>>>
> >>>>> Your user space program will not know where 'getrandom' is defined
> >>>>> unless it's in the C library. You need to research more on how to
> call
> >>>>> custom system calls.
> >>>>>
> >>>>> -Anoop
> >>>>>
> >>>>>>  --
> >>>>>>  Regards,
> >>>>>>  Avantika Rawat
> >>>>>>
> >>>>>>  _______________________________________________
> >>>>>>  Kernelnewbies mailing list
> >>>>>>  Kernelnewbies at kernelnewbies.org
> >>>>>>  http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
> >>>>>
> >>>>> _______________________________________________
> >>>>> Kernelnewbies mailing list
> >>>>> Kernelnewbies at kernelnewbies.org
> >>>>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
> >>>>
> >>>> -----
> >>>> Sayutin Dmitry <cdkrot@yandex.com>
> >>>
> >>>
> >>>
> >
> >
> >
> > --
> > Regards,
> > Avantika Rawat
> >
> > _______________________________________________
> > Kernelnewbies mailing list
> > Kernelnewbies at kernelnewbies.org
> > http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
> I think you need to 352 or 315 ie the values from .tbl (so 315 if you
> are calling on a x64 kernel or 352 if you are calling x86 kernel). The
> 275 is for the uapi but syscall accepts the 315 value on a x64.
>
>  Please try with 315 and 352 after running your modified kernel and
> report back. Atleast that is the way it worked for me on a 4.x kernel.
> Ideally uapi is for userspace like glibc and they come man 3 where as
> the syscall is (man 2) ie system call.
>
> --
> -- Navin
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20160622/da7ccc23/attachment-0001.html 

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Regarding getrandom syscall
  2016-06-22 14:58         ` Avantika Rawat
  2016-06-22 16:15           ` Navin P.S
@ 2016-06-22 17:11           ` Markus Böhme
  2016-06-24 14:44             ` Avantika Rawat
  1 sibling, 1 reply; 10+ messages in thread
From: Markus Böhme @ 2016-06-22 17:11 UTC (permalink / raw)
  To: kernelnewbies

On 06/22/2016 04:58 PM, Avantika Rawat wrote:
> Thanks for the link but i am getting "Function not implemented" error.
> I have added a custom syscall in kernel for testing, getting similar
> error for that also. I am working on  3.10.20 Kernel and MIPS
> architecture. Pasting the kernel changes done to spport getrandom
> syscall in 3.10.20 kernel. Can someone please help me here that what
> needs to be done.

If you're on MIPS, x86 code and syscall numbers won't help you. In this
case the proper syscall numbers are defined in
arch/mips/include/uapi/asm/unistd.h.

Additionally, note that your kernel version does not seem to implement
the getrandom syscall for MIPS:

 $ git blame arch/mips/include/uapi/asm/unistd.h | grep getrandom
 42944521 (Ralf Baechle  2014-08-26 03:03:40 +0200  376) #define
__NR_getrandom			(__NR_Linux + 353)
 42944521 (Ralf Baechle  2014-08-26 03:03:40 +0200  716) #define
__NR_getrandom			(__NR_Linux + 313)
 42944521 (Ralf Baechle  2014-08-26 03:03:40 +0200 1060) #define
__NR_getrandom			(__NR_Linux + 317)

 $ git show 42944521 | head -n 5
 commit 42944521af97a3b25516f15f3149aec3779656dc
 Author: Ralf Baechle <ralf@linux-mips.org>
 Date:   Tue Aug 26 03:03:40 2014 +0200

     MIPS: Wire up new syscalls getrandom and memfd_create.

 $ git show v3.10.20 | head -n 3
 tag v3.10.20
 Tagger: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
 Date:   Wed Nov 20 12:28:06 2013 -0800


Regards,
Markus

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Regarding getrandom syscall
  2016-06-22 17:11           ` Markus Böhme
@ 2016-06-24 14:44             ` Avantika Rawat
  0 siblings, 0 replies; 10+ messages in thread
From: Avantika Rawat @ 2016-06-24 14:44 UTC (permalink / raw)
  To: kernelnewbies

Hi All,

Thanks for the help

I was getting SYS_getrandom not defined compilation error as it is not
defined in my c libraries. Also now i am able to call getrandom
through syscall with proper syscall number which is arch dependent.
syscall (6314, buf, l , o);

On Wed, Jun 22, 2016 at 10:41 PM, Markus B?hme
<markus.boehme@mailbox.org> wrote:
> On 06/22/2016 04:58 PM, Avantika Rawat wrote:
>> Thanks for the link but i am getting "Function not implemented" error.
>> I have added a custom syscall in kernel for testing, getting similar
>> error for that also. I am working on  3.10.20 Kernel and MIPS
>> architecture. Pasting the kernel changes done to spport getrandom
>> syscall in 3.10.20 kernel. Can someone please help me here that what
>> needs to be done.
>
> If you're on MIPS, x86 code and syscall numbers won't help you. In this
> case the proper syscall numbers are defined in
> arch/mips/include/uapi/asm/unistd.h.
>
> Additionally, note that your kernel version does not seem to implement
> the getrandom syscall for MIPS:
>
>  $ git blame arch/mips/include/uapi/asm/unistd.h | grep getrandom
>  42944521 (Ralf Baechle  2014-08-26 03:03:40 +0200  376) #define
> __NR_getrandom                  (__NR_Linux + 353)
>  42944521 (Ralf Baechle  2014-08-26 03:03:40 +0200  716) #define
> __NR_getrandom                  (__NR_Linux + 313)
>  42944521 (Ralf Baechle  2014-08-26 03:03:40 +0200 1060) #define
> __NR_getrandom                  (__NR_Linux + 317)
>
>  $ git show 42944521 | head -n 5
>  commit 42944521af97a3b25516f15f3149aec3779656dc
>  Author: Ralf Baechle <ralf@linux-mips.org>
>  Date:   Tue Aug 26 03:03:40 2014 +0200
>
>      MIPS: Wire up new syscalls getrandom and memfd_create.
>
>  $ git show v3.10.20 | head -n 3
>  tag v3.10.20
>  Tagger: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
>  Date:   Wed Nov 20 12:28:06 2013 -0800
>
>
> Regards,
> Markus



-- 
Regards,
Avantika Rawat

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2016-06-24 14:44 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-18 12:02 Regarding getrandom syscall Avantika Rawat
2016-06-18 13:30 ` Anoop
2016-06-18 13:42   ` Sayutin Dmitry
2016-06-21 13:41     ` Avantika Rawat
2016-06-21 19:10       ` Manuel Pégourié-Gonnard
2016-06-22 14:58         ` Avantika Rawat
2016-06-22 16:15           ` Navin P.S
2016-06-22 16:40             ` Avantika Rawat
2016-06-22 17:11           ` Markus Böhme
2016-06-24 14:44             ` Avantika Rawat

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.