From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/12297 Path: news.gmane.org!.POSTED!not-for-mail From: Hauke Mehrtens Newsgroups: gmane.linux.lib.musl.general Subject: Re: [PATCH] Add getrandom syscall wrapper function Date: Mon, 1 Jan 2018 22:51:34 +0100 Message-ID: <501306ff-c0e3-f1be-a81b-ba6e619fd807@hauke-m.de> References: <20180101203123.12816-1-hauke@hauke-m.de> <20180101204748.GH1627@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Trace: blaine.gmane.org 1514843404 19267 195.159.176.226 (1 Jan 2018 21:50:04 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 1 Jan 2018 21:50:04 +0000 (UTC) To: musl@lists.openwall.com, Rich Felker Original-X-From: musl-return-12313-gllmg-musl=m.gmane.org@lists.openwall.com Mon Jan 01 22:50:00 2018 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1eW7xx-0004Jp-1g for gllmg-musl@m.gmane.org; Mon, 01 Jan 2018 22:49:53 +0100 Original-Received: (qmail 32569 invoked by uid 550); 1 Jan 2018 21:51:54 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 32551 invoked from network); 1 Jan 2018 21:51:53 -0000 X-Virus-Scanned: amavisd-new at heinlein-support.de In-Reply-To: <20180101204748.GH1627@brightrain.aerifal.cx> Content-Language: en-US Xref: news.gmane.org gmane.linux.lib.musl.general:12297 Archived-At: On 01/01/2018 09:47 PM, Rich Felker wrote: > On Mon, Jan 01, 2018 at 09:31:23PM +0100, Hauke Mehrtens wrote: >> This syscall is available since Linux 3.17 and was also implemented in >> glibc in version 2.25. This is a pure syscall wrapper liker glibc does >> it. >> --- >> include/sys/random.h | 19 +++++++++++++++++++ >> src/linux/getrandom.c | 11 +++++++++++ >> 2 files changed, 30 insertions(+) >> create mode 100644 include/sys/random.h >> create mode 100644 src/linux/getrandom.c >> >> diff --git a/include/sys/random.h b/include/sys/random.h >> new file mode 100644 >> index 00000000..5540f877 >> --- /dev/null >> +++ b/include/sys/random.h >> @@ -0,0 +1,19 @@ >> +#ifndef _SYS_RANDOM_H >> +#define _SYS_RANDOM_H >> +#ifdef __cplusplus >> +extern "C" { >> +#endif >> + >> +#define __NEED_size_t >> +#define __NEED_ssize_t >> +#include >> + >> +#define GRND_NONBLOCK 0x0001 >> +#define GRND_RANDOM 0x0002 >> + >> +ssize_t getrandom(void *buf, size_t buflen, unsigned int flags); >> + >> +#ifdef __cplusplus >> +} >> +#endif >> +#endif >> diff --git a/src/linux/getrandom.c b/src/linux/getrandom.c >> new file mode 100644 >> index 00000000..50b07df9 >> --- /dev/null >> +++ b/src/linux/getrandom.c >> @@ -0,0 +1,11 @@ >> +#include >> +#include "syscall.h" >> + >> +ssize_t getrandom(void *buf, size_t buflen, unsigned int flags) >> +{ >> +#ifdef SYS_getrandom >> + return syscall_cp(SYS_getrandom, buf, buflen, flags); >> +#else >> + return __syscall_ret(-ENOSYS); >> +#endif >> +} >> -- >> 2.11.0 > > The #ifdef doesn't make sense; if the definition is missing then it's > a bug in musl source. Ok, If I can assume that SYS_getrandom is always defined I will remove this. > Aside from that I think the patch is okay but I'm not sure it's > complete. There should probably also be getentropy(), Adding getentropy() should not be so hard, I can do that. > and we've > discussed in the past but never reached any conclusion on whether > there should be a fallback when the syscall doesn't exist (running on > old kernel). glibc does not have a fallback for this syscall there was a long discussion about this, see here: https://lwn.net/Articles/711013/ As they never found a good solution for their fallback. I think musl should also not provide a fallback. This is the glibc implementation: https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=92dcaa3e2f7bf0f7f1c04cd2fb6a317df1a4e225 Hauke