View | Details | Raw Unified | Return to bug 194204 | Differences between
and this patch

Collapse All | Expand All

(-)b/include/unistd.h (+1 lines)
Lines 581-586 off_t __syscall(quad_t, ...); Link Here
581
int	 undelete(const char *);
581
int	 undelete(const char *);
582
int	 unwhiteout(const char *);
582
int	 unwhiteout(const char *);
583
void	*valloc(size_t);			/* obsoleted by malloc() */
583
void	*valloc(size_t);			/* obsoleted by malloc() */
584
int	 getentropy(void *, size_t);
584
585
585
#ifndef _OPTRESET_DECLARED
586
#ifndef _OPTRESET_DECLARED
586
#define	_OPTRESET_DECLARED
587
#define	_OPTRESET_DECLARED
(-)b/lib/libc/sys/Makefile.inc (+1 lines)
Lines 123-128 MAN+= abort2.2 \ Link Here
123
	fsync.2 \
123
	fsync.2 \
124
	getdirentries.2 \
124
	getdirentries.2 \
125
	getdtablesize.2 \
125
	getdtablesize.2 \
126
	getentropy.2 \
126
	getfh.2 \
127
	getfh.2 \
127
	getfsstat.2 \
128
	getfsstat.2 \
128
	getgid.2 \
129
	getgid.2 \
(-)b/lib/libc/sys/Symbol.map (+3 lines)
Lines 393-398 FBSD_1.3 { Link Here
393
	ffclock_getcounter;
393
	ffclock_getcounter;
394
	ffclock_getestimate;
394
	ffclock_getestimate;
395
	ffclock_setestimate;
395
	ffclock_setestimate;
396
	getentropy;
396
	pipe2;
397
	pipe2;
397
	posix_fadvise;
398
	posix_fadvise;
398
	procctl;
399
	procctl;
Lines 612-617 FBSDprivate_1.0 { Link Here
612
	_getegid;
613
	_getegid;
613
	__sys_getegid;
614
	__sys_getegid;
614
	_geteuid;
615
	_geteuid;
616
	__sys_getentropy;
617
	_getentropy;
615
	__sys_geteuid;
618
	__sys_geteuid;
616
	_getfh;
619
	_getfh;
617
	__sys_getfh;
620
	__sys_getfh;
(-)b/lib/libc/sys/getentropy.2 (+69 lines)
Added Link Here
1
.\"	$OpenBSD: getentropy.2,v 1.6 2014/07/18 18:20:17 deraadt Exp $
2
.\"
3
.\" Copyright (c) 2014 Theo de Raadt
4
.\"
5
.\" Permission to use, copy, modify, and distribute this software for any
6
.\" purpose with or without fee is hereby granted, provided that the above
7
.\" copyright notice and this permission notice appear in all copies.
8
.\"
9
.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
.\"
17
.Dd $Mdocdate: July 18 2014 $
18
.Dt GETENTROPY 2
19
.Os
20
.Sh NAME
21
.Nm getentropy
22
.Nd get entropy
23
.Sh SYNOPSIS
24
.Fd #include <unistd.h>
25
.Ft int
26
.Fn getentropy "void *buf" "size_t buflen"
27
.Sh DESCRIPTION
28
.Nm
29
fills a buffer with high-quality entropy, which can be used
30
as input for process-context pseudorandom generators like
31
.Xr arc4random 3 .
32
.Pp
33
The maximum buffer size permitted is 256 bytes.
34
Even if
35
.Va buflen
36
exceeds this.
37
.Pp
38
.Nm
39
is not intended for regular code; please use the
40
.Xr arc4random 3
41
family of functions instead.
42
.Sh RETURN VALUES
43
Upon successful completion, a value of 0 is returned.
44
Otherwise, a value of \-1 is returned and
45
.Va errno
46
is set to indicate the error.
47
.Sh ERRORS
48
.Fn getentropy
49
will succeed unless:
50
.Bl -tag -width Er
51
.It Bq Er EFAULT
52
The
53
.Fa buf
54
parameter points to an
55
invalid address.
56
.El
57
.It Bq Er EIO
58
Too
59
.Fa many bytes
60
requested, or some other
61
fatal error occurred.
62
.El
63
.Sh SEE ALSO
64
.Xr arc4random 3
65
.Sh HISTORY
66
The
67
.Nm
68
function appeared in
69
.Ox 5.6 .
(-)b/sys/compat/freebsd32/freebsd32_syscall.h (-1 / +2 lines)
Lines 452-455 Link Here
452
#define	FREEBSD32_SYS_freebsd32_aio_mlock	543
452
#define	FREEBSD32_SYS_freebsd32_aio_mlock	543
453
#define	FREEBSD32_SYS_freebsd32_procctl	544
453
#define	FREEBSD32_SYS_freebsd32_procctl	544
454
#define	FREEBSD32_SYS_freebsd32_procctl	544
454
#define	FREEBSD32_SYS_freebsd32_procctl	544
455
#define	FREEBSD32_SYS_MAXSYSCALL	545
455
#define	FREEBSD32_SYS_getentropy	545
456
#define	FREEBSD32_SYS_MAXSYSCALL	546
(-)b/sys/compat/freebsd32/freebsd32_syscalls.c (+1 lines)
Lines 578-581 const char *freebsd32_syscallnames[] = { Link Here
578
#else
578
#else
579
	"freebsd32_procctl",			/* 544 = freebsd32_procctl */
579
	"freebsd32_procctl",			/* 544 = freebsd32_procctl */
580
#endif
580
#endif
581
	"getentropy",			/* 545 = getentropy */
581
};
582
};
(-)b/sys/compat/freebsd32/freebsd32_sysent.c (+1 lines)
Lines 615-618 struct sysent freebsd32_sysent[] = { Link Here
615
#else
615
#else
616
	{ AS(freebsd32_procctl_args), (sy_call_t *)freebsd32_procctl, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC },	/* 544 = freebsd32_procctl */
616
	{ AS(freebsd32_procctl_args), (sy_call_t *)freebsd32_procctl, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC },	/* 544 = freebsd32_procctl */
617
#endif
617
#endif
618
	{ AS(getentropy_args), (sy_call_t *)sys_getentropy, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC },	/* 545 = getentropy */
618
};
619
};
(-)b/sys/compat/freebsd32/freebsd32_systrace_args.c (+26 lines)
Lines 3299-3304 systrace_args(int sysnum, void *params, uint64_t *uarg, int *n_args) Link Here
3299
		break;
3299
		break;
3300
	}
3300
	}
3301
#endif
3301
#endif
3302
	/* getentropy */
3303
	case 545: {
3304
		struct getentropy_args *p = params;
3305
		uarg[0] = (intptr_t) p->ptr; /* void * */
3306
		uarg[1] = p->len; /* size_t */
3307
		*n_args = 2;
3308
		break;
3309
	}
3302
	default:
3310
	default:
3303
		*n_args = 0;
3311
		*n_args = 0;
3304
		break;
3312
		break;
Lines 8844-8849 systrace_entry_setargdesc(int sysnum, int ndx, char *desc, size_t descsz) Link Here
8844
		};
8852
		};
8845
		break;
8853
		break;
8846
#endif
8854
#endif
8855
	/* getentropy */
8856
	case 545:
8857
		switch(ndx) {
8858
		case 0:
8859
			p = "void *";
8860
			break;
8861
		case 1:
8862
			p = "size_t";
8863
			break;
8864
		default:
8865
			break;
8866
		};
8867
		break;
8847
	default:
8868
	default:
8848
		break;
8869
		break;
8849
	};
8870
	};
Lines 10717-10722 systrace_return_setargdesc(int sysnum, int ndx, char *desc, size_t descsz) Link Here
10717
			p = "int";
10738
			p = "int";
10718
		break;
10739
		break;
10719
#endif
10740
#endif
10741
	/* getentropy */
10742
	case 545:
10743
		if (ndx == 0 || ndx == 1)
10744
			p = "int";
10745
		break;
10720
	default:
10746
	default:
10721
		break;
10747
		break;
10722
	};
10748
	};
(-)b/sys/compat/freebsd32/syscalls.master (+2 lines)
Lines 1066-1068 Link Here
1066
				    uint32_t id1, uint32_t id2, int com, \
1066
				    uint32_t id1, uint32_t id2, int com, \
1067
				    void *data); }
1067
				    void *data); }
1068
#endif
1068
#endif
1069
545	AUE_NULL	NOPROTO	{ int getentropy(void *ptr, \
1070
				    size_t len); }
(-)b/sys/conf/files (+1 lines)
Lines 3068-3073 kern/sys_pipe.c standard Link Here
3068
kern/sys_procdesc.c		standard
3068
kern/sys_procdesc.c		standard
3069
kern/sys_process.c		standard
3069
kern/sys_process.c		standard
3070
kern/sys_socket.c		standard
3070
kern/sys_socket.c		standard
3071
kern/sys_random.c		standard
3071
kern/syscalls.c			standard
3072
kern/syscalls.c			standard
3072
kern/sysv_ipc.c			standard
3073
kern/sysv_ipc.c			standard
3073
kern/sysv_msg.c			optional sysvmsg
3074
kern/sysv_msg.c			optional sysvmsg
(-)b/sys/kern/init_sysent.c (+1 lines)
Lines 579-582 struct sysent sysent[] = { Link Here
579
	{ AS(pipe2_args), (sy_call_t *)sys_pipe2, AUE_PIPE, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC },	/* 542 = pipe2 */
579
	{ AS(pipe2_args), (sy_call_t *)sys_pipe2, AUE_PIPE, NULL, 0, 0, SYF_CAPENABLED, SY_THR_STATIC },	/* 542 = pipe2 */
580
	{ AS(aio_mlock_args), (sy_call_t *)lkmressys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },	/* 543 = aio_mlock */
580
	{ AS(aio_mlock_args), (sy_call_t *)lkmressys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },	/* 543 = aio_mlock */
581
	{ AS(procctl_args), (sy_call_t *)sys_procctl, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC },	/* 544 = procctl */
581
	{ AS(procctl_args), (sy_call_t *)sys_procctl, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC },	/* 544 = procctl */
582
	{ AS(getentropy_args), (sy_call_t *)sys_getentropy, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC },	/* 545 = getentropy */
582
};
583
};
(-)b/sys/kern/sys_random.c (+61 lines)
Added Link Here
1
/*-
2
 * Copyright (c) 2014, by Theo de Raadt
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 * 1. Redistributions of source code must retain the above copyright
9
 *    notice, this list of conditions and the following disclaimer.
10
 * 2. Redistributions in binary form must reproduce the above copyright
11
 *    notice, this list of conditions and the following disclaimer in the
12
 *    documentation and/or other materials provided with the distribution.
13
 * 3. The name of the author may not be used to endorse or promote products
14
 *    derived from this software without specific prior written permission.
15
 *
16
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
 *
27
 * $FreeBSD$
28
 */
29
30
#include <sys/cdefs.h>
31
__FBSDID("$FreeBSD$");
32
33
#include <sys/sysent.h>
34
#include <sys/sysproto.h>
35
#include <sys/libkern.h>
36
#include <sys/proc.h>
37
38
#ifndef	_SYS_SYSPROTO_H_
39
struct getentropy_args {
40
	void	*ptr;
41
	size_t	len;
42
};
43
#endif
44
45
int
46
sys_getentropy(struct thread *td, struct getentropy_args *uap)
47
{
48
	char buf[256];
49
	int error;
50
51
	if (uap->len > sizeof(buf))
52
		return (EIO);
53
54
	arc4rand(buf, uap->len, 1);
55
	if ((error = copyout(buf, uap->ptr, uap->len)) != 0)	
56
		return (error);
57
58
	explicit_bzero(buf, sizeof(buf));
59
60
	return (0);
61
}
(-)b/sys/kern/syscalls.c (+1 lines)
Lines 552-555 const char *syscallnames[] = { Link Here
552
	"pipe2",			/* 542 = pipe2 */
552
	"pipe2",			/* 542 = pipe2 */
553
	"aio_mlock",			/* 543 = aio_mlock */
553
	"aio_mlock",			/* 543 = aio_mlock */
554
	"procctl",			/* 544 = procctl */
554
	"procctl",			/* 544 = procctl */
555
	"getentropy",			/* 545 = getentropy */
555
};
556
};
(-)b/sys/kern/syscalls.master (+1 lines)
Lines 980-984 Link Here
980
543	AUE_NULL	NOSTD	{ int aio_mlock(struct aiocb *aiocbp); }
980
543	AUE_NULL	NOSTD	{ int aio_mlock(struct aiocb *aiocbp); }
981
544	AUE_NULL	STD	{ int procctl(idtype_t idtype, id_t id, \
981
544	AUE_NULL	STD	{ int procctl(idtype_t idtype, id_t id, \
982
				    int com, void *data); }
982
				    int com, void *data); }
983
545	AUE_NULL	STD	{ int getentropy(void *ptr, size_t len); }
983
; Please copy any additions and changes to the following compatability tables:
984
; Please copy any additions and changes to the following compatability tables:
984
; sys/compat/freebsd32/syscalls.master
985
; sys/compat/freebsd32/syscalls.master
(-)b/sys/kern/systrace_args.c (+26 lines)
Lines 3372-3377 systrace_args(int sysnum, void *params, uint64_t *uarg, int *n_args) Link Here
3372
		*n_args = 4;
3372
		*n_args = 4;
3373
		break;
3373
		break;
3374
	}
3374
	}
3375
	/* getentropy */
3376
	case 545: {
3377
		struct getentropy_args *p = params;
3378
		uarg[0] = (intptr_t) p->ptr; /* void * */
3379
		uarg[1] = p->len; /* size_t */
3380
		*n_args = 2;
3381
		break;
3382
	}
3375
	default:
3383
	default:
3376
		*n_args = 0;
3384
		*n_args = 0;
3377
		break;
3385
		break;
Lines 8990-8995 systrace_entry_setargdesc(int sysnum, int ndx, char *desc, size_t descsz) Link Here
8990
			break;
8998
			break;
8991
		};
8999
		};
8992
		break;
9000
		break;
9001
	/* getentropy */
9002
	case 545:
9003
		switch(ndx) {
9004
		case 0:
9005
			p = "void *";
9006
			break;
9007
		case 1:
9008
			p = "size_t";
9009
			break;
9010
		default:
9011
			break;
9012
		};
9013
		break;
8993
	default:
9014
	default:
8994
		break;
9015
		break;
8995
	};
9016
	};
Lines 10928-10933 systrace_return_setargdesc(int sysnum, int ndx, char *desc, size_t descsz) Link Here
10928
		if (ndx == 0 || ndx == 1)
10949
		if (ndx == 0 || ndx == 1)
10929
			p = "int";
10950
			p = "int";
10930
		break;
10951
		break;
10952
	/* getentropy */
10953
	case 545:
10954
		if (ndx == 0 || ndx == 1)
10955
			p = "int";
10956
		break;
10931
	default:
10957
	default:
10932
		break;
10958
		break;
10933
	};
10959
	};
(-)b/sys/sys/syscall.h (-1 / +2 lines)
Lines 462-465 Link Here
462
#define	SYS_pipe2	542
462
#define	SYS_pipe2	542
463
#define	SYS_aio_mlock	543
463
#define	SYS_aio_mlock	543
464
#define	SYS_procctl	544
464
#define	SYS_procctl	544
465
#define	SYS_MAXSYSCALL	545
465
#define	SYS_getentropy	545
466
#define	SYS_MAXSYSCALL	546
(-)b/sys/sys/syscall.mk (-1 / +2 lines)
Lines 409-412 MIASM = \ Link Here
409
	accept4.o \
409
	accept4.o \
410
	pipe2.o \
410
	pipe2.o \
411
	aio_mlock.o \
411
	aio_mlock.o \
412
	procctl.o
412
	procctl.o \
413
	getentropy.o
(-)b/sys/sys/sysproto.h (+6 lines)
Lines 1813-1818 struct procctl_args { Link Here
1813
	char com_l_[PADL_(int)]; int com; char com_r_[PADR_(int)];
1813
	char com_l_[PADL_(int)]; int com; char com_r_[PADR_(int)];
1814
	char data_l_[PADL_(void *)]; void * data; char data_r_[PADR_(void *)];
1814
	char data_l_[PADL_(void *)]; void * data; char data_r_[PADR_(void *)];
1815
};
1815
};
1816
struct getentropy_args {
1817
	char ptr_l_[PADL_(void *)]; void * ptr; char ptr_r_[PADR_(void *)];
1818
	char len_l_[PADL_(size_t)]; size_t len; char len_r_[PADR_(size_t)];
1819
};
1816
int	nosys(struct thread *, struct nosys_args *);
1820
int	nosys(struct thread *, struct nosys_args *);
1817
void	sys_sys_exit(struct thread *, struct sys_exit_args *);
1821
void	sys_sys_exit(struct thread *, struct sys_exit_args *);
1818
int	sys_fork(struct thread *, struct fork_args *);
1822
int	sys_fork(struct thread *, struct fork_args *);
Lines 2204-2209 int sys_accept4(struct thread *, struct accept4_args *); Link Here
2204
int	sys_pipe2(struct thread *, struct pipe2_args *);
2208
int	sys_pipe2(struct thread *, struct pipe2_args *);
2205
int	sys_aio_mlock(struct thread *, struct aio_mlock_args *);
2209
int	sys_aio_mlock(struct thread *, struct aio_mlock_args *);
2206
int	sys_procctl(struct thread *, struct procctl_args *);
2210
int	sys_procctl(struct thread *, struct procctl_args *);
2211
int	sys_getentropy(struct thread *, struct getentropy_args *);
2207
2212
2208
#ifdef COMPAT_43
2213
#ifdef COMPAT_43
2209
2214
Lines 2909-2914 int freebsd7_shmctl(struct thread *, struct freebsd7_shmctl_args *); Link Here
2909
#define	SYS_AUE_pipe2	AUE_PIPE
2914
#define	SYS_AUE_pipe2	AUE_PIPE
2910
#define	SYS_AUE_aio_mlock	AUE_NULL
2915
#define	SYS_AUE_aio_mlock	AUE_NULL
2911
#define	SYS_AUE_procctl	AUE_NULL
2916
#define	SYS_AUE_procctl	AUE_NULL
2917
#define	SYS_AUE_getentropy	AUE_NULL
2912
2918
2913
#undef PAD_
2919
#undef PAD_
2914
#undef PADL_
2920
#undef PADL_

Return to bug 194204