FreeBSD Bugzilla – Attachment 148045 Details for
Bug 194204
getentropy(2): sys call from openbsd
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Proposed patch
patch-getentropy.txt (text/plain), 6.48 KB, created by
David CARLIER
on 2014-10-06 21:28:16 UTC
(
hide
)
Description:
Proposed patch
Filename:
MIME Type:
Creator:
David CARLIER
Created:
2014-10-06 21:28:16 UTC
Size:
6.48 KB
patch
obsolete
>diff --git a/include/unistd.h b/include/unistd.h >index 0329122..40ed78e 100644 >--- a/include/unistd.h >+++ b/include/unistd.h >@@ -581,6 +581,7 @@ off_t __syscall(quad_t, ...); > int undelete(const char *); > int unwhiteout(const char *); > void *valloc(size_t); /* obsoleted by malloc() */ >+int getentropy(void *, size_t); > > #ifndef _OPTRESET_DECLARED > #define _OPTRESET_DECLARED >diff --git a/lib/libc/sys/Makefile.inc b/lib/libc/sys/Makefile.inc >index 07a4537..e5022ab 100644 >--- a/lib/libc/sys/Makefile.inc >+++ b/lib/libc/sys/Makefile.inc >@@ -123,6 +123,7 @@ MAN+= abort2.2 \ > fsync.2 \ > getdirentries.2 \ > getdtablesize.2 \ >+ getentropy.2 \ > getfh.2 \ > getfsstat.2 \ > getgid.2 \ >diff --git a/lib/libc/sys/Symbol.map b/lib/libc/sys/Symbol.map >index fe887c3..ea86e81 100644 >--- a/lib/libc/sys/Symbol.map >+++ b/lib/libc/sys/Symbol.map >@@ -393,6 +393,7 @@ FBSD_1.3 { > ffclock_getcounter; > ffclock_getestimate; > ffclock_setestimate; >+ getentropy; > pipe2; > posix_fadvise; > procctl; >@@ -612,6 +613,8 @@ FBSDprivate_1.0 { > _getegid; > __sys_getegid; > _geteuid; >+ __sys_getentropy; >+ _getentropy; > __sys_geteuid; > _getfh; > __sys_getfh; >diff --git a/lib/libc/sys/getentropy.2 b/lib/libc/sys/getentropy.2 >new file mode 100644 >index 0000000..b9eaa67 >--- /dev/null >+++ b/lib/libc/sys/getentropy.2 >@@ -0,0 +1,63 @@ >+.\" $OpenBSD: getentropy.2,v 1.6 2014/07/18 18:20:17 deraadt Exp $ >+.\" >+.\" Copyright (c) 2014 Theo de Raadt >+.\" >+.\" Permission to use, copy, modify, and distribute this software for any >+.\" purpose with or without fee is hereby granted, provided that the above >+.\" copyright notice and this permission notice appear in all copies. >+.\" >+.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES >+.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF >+.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR >+.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES >+.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN >+.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF >+.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. >+.\" >+.Dd $Mdocdate: July 18 2014 $ >+.Dt GETENTROPY 2 >+.Os >+.Sh NAME >+.Nm getentropy >+.Nd get entropy >+.Sh SYNOPSIS >+.Fd #include <unistd.h> >+.Ft int >+.Fn getentropy "void *buf" "size_t buflen" >+.Sh DESCRIPTION >+.Nm >+fills a buffer with high-quality entropy, which can be used >+as input for process-context pseudorandom generators like >+.Xr arc4random 3 . >+.Pp >+The maximum buffer size permitted is 256 bytes. >+Even if >+.Va buflen >+exceeds this. >+.Pp >+.Nm >+is not intended for regular code; please use the >+.Xr arc4random 3 >+family of functions instead. >+.Sh RETURN VALUES >+Upon successful completion, a value of 0 is returned. >+Otherwise, a value of \-1 is returned and >+.Va errno >+is set to indicate the error. >+.Sh ERRORS >+.Fn getentropy >+will succeed unless: >+.Bl -tag -width Er >+.It Bq Er EFAULT >+The >+.Fa buf >+parameter points to an >+invalid address. >+.El >+.Sh SEE ALSO >+.Xr arc4random 3 >+.Sh HISTORY >+The >+.Nm >+function appeared in >+.Ox 5.6 . >diff --git a/sys/compat/freebsd32/syscalls.master b/sys/compat/freebsd32/syscalls.master >index 161f69d..e838870 100644 >--- a/sys/compat/freebsd32/syscalls.master >+++ b/sys/compat/freebsd32/syscalls.master >@@ -1066,3 +1066,5 @@ > uint32_t id1, uint32_t id2, int com, \ > void *data); } > #endif >+545 AUE_NULL NOPROTO { int getentropy(void *ptr, \ >+ size_t len); } >diff --git a/sys/conf/files b/sys/conf/files >index 3d0d2e1..aacaf14 100644 >--- a/sys/conf/files >+++ b/sys/conf/files >@@ -3067,6 +3067,7 @@ kern/sys_pipe.c standard > kern/sys_procdesc.c standard > kern/sys_process.c standard > kern/sys_socket.c standard >+kern/sys_random.c standard > kern/syscalls.c standard > kern/sysv_ipc.c standard > kern/sysv_msg.c optional sysvmsg >diff --git a/sys/kern/sys_random.c b/sys/kern/sys_random.c >new file mode 100644 >index 0000000..fe7a07c >--- /dev/null >+++ b/sys/kern/sys_random.c >@@ -0,0 +1,60 @@ >+/*- >+ * Copyright (c) 2014, by Theo de Raadt >+ * All rights reserved. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * 3. The name of the author may not be used to endorse or promote products >+ * derived from this software without specific prior written permission. >+ * >+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR >+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES >+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. >+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, >+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT >+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, >+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY >+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT >+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF >+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. >+ * >+ * $FreeBSD$ >+ */ >+ >+#include <sys/cdefs.h> >+__FBSDID("$FreeBSD$"); >+ >+#include <sys/sysent.h> >+#include <sys/sysproto.h> >+#include <sys/libkern.h> >+#include <sys/proc.h> >+ >+#ifndef _SYS_SYSPROTO_H_ >+struct getentropy_args { >+ void *ptr; >+ size_t len; >+}; >+#endif >+ >+int >+sys_getentropy(struct thread *td, struct getentropy_args *uap) >+{ >+ char buf[256]; >+ size_t len; >+ int error; >+ >+ len = MIN(sizeof(buf), uap->len); >+ arc4rand(buf, len, 1); >+ if ((error = copyout(buf, uap->ptr, len)) != 0) >+ return (error); >+ >+ memset(buf, 0, sizeof(buf)); >+ >+ return (0); >+} >diff --git a/sys/kern/syscalls.master b/sys/kern/syscalls.master >index 71e6273..ec8d633 100644 >--- a/sys/kern/syscalls.master >+++ b/sys/kern/syscalls.master >@@ -980,5 +980,6 @@ > 543 AUE_NULL NOSTD { int aio_mlock(struct aiocb *aiocbp); } > 544 AUE_NULL STD { int procctl(idtype_t idtype, id_t id, \ > int com, void *data); } >+545 AUE_NULL STD { int getentropy(void *ptr, size_t len); } > ; Please copy any additions and changes to the following compatability tables: > ; sys/compat/freebsd32/syscalls.master
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 194204
: 148045 |
149067