| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: rndpseudo.c,v 1.29 2015/04/14 12:25:41 riastradh Exp $ */ | | 1 | /* $NetBSD: rndpseudo.c,v 1.30 2015/04/14 12:27:02 riastradh Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 1997-2013 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 1997-2013 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Michael Graff <explorer@flame.org>, Thor Lancelot Simon, and | | 8 | * by Michael Graff <explorer@flame.org>, Thor Lancelot Simon, and |
9 | * Taylor R. Campbell. | | 9 | * Taylor R. Campbell. |
10 | * | | 10 | * |
11 | * Redistribution and use in source and binary forms, with or without | | 11 | * Redistribution and use in source and binary forms, with or without |
12 | * modification, are permitted provided that the following conditions | | 12 | * modification, are permitted provided that the following conditions |
13 | * are met: | | 13 | * are met: |
14 | * 1. Redistributions of source code must retain the above copyright | | 14 | * 1. Redistributions of source code must retain the above copyright |
| @@ -21,27 +21,27 @@ | | | @@ -21,27 +21,27 @@ |
21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
30 | * POSSIBILITY OF SUCH DAMAGE. | | 30 | * POSSIBILITY OF SUCH DAMAGE. |
31 | */ | | 31 | */ |
32 | | | 32 | |
33 | #include <sys/cdefs.h> | | 33 | #include <sys/cdefs.h> |
34 | __KERNEL_RCSID(0, "$NetBSD: rndpseudo.c,v 1.29 2015/04/14 12:25:41 riastradh Exp $"); | | 34 | __KERNEL_RCSID(0, "$NetBSD: rndpseudo.c,v 1.30 2015/04/14 12:27:02 riastradh Exp $"); |
35 | | | 35 | |
36 | #if defined(_KERNEL_OPT) | | 36 | #if defined(_KERNEL_OPT) |
37 | #include "opt_compat_netbsd.h" | | 37 | #include "opt_compat_netbsd.h" |
38 | #endif | | 38 | #endif |
39 | | | 39 | |
40 | #include <sys/param.h> | | 40 | #include <sys/param.h> |
41 | #include <sys/ioctl.h> | | 41 | #include <sys/ioctl.h> |
42 | #include <sys/fcntl.h> | | 42 | #include <sys/fcntl.h> |
43 | #include <sys/file.h> | | 43 | #include <sys/file.h> |
44 | #include <sys/filedesc.h> | | 44 | #include <sys/filedesc.h> |
45 | #include <sys/select.h> | | 45 | #include <sys/select.h> |
46 | #include <sys/poll.h> | | 46 | #include <sys/poll.h> |
47 | #include <sys/kmem.h> | | 47 | #include <sys/kmem.h> |
| @@ -422,27 +422,27 @@ rnd_read(struct file *fp, off_t *offp, s | | | @@ -422,27 +422,27 @@ rnd_read(struct file *fp, off_t *offp, s |
422 | error = EINTR; | | 422 | error = EINTR; |
423 | goto out; | | 423 | goto out; |
424 | } | | 424 | } |
425 | } | | 425 | } |
426 | | | 426 | |
427 | out: pool_cache_put(rnd_temp_buffer_cache, buf); | | 427 | out: pool_cache_put(rnd_temp_buffer_cache, buf); |
428 | return error; | | 428 | return error; |
429 | } | | 429 | } |
430 | | | 430 | |
431 | static int | | 431 | static int |
432 | rnd_write(struct file *fp, off_t *offp, struct uio *uio, | | 432 | rnd_write(struct file *fp, off_t *offp, struct uio *uio, |
433 | kauth_cred_t cred, int flags) | | 433 | kauth_cred_t cred, int flags) |
434 | { | | 434 | { |
435 | u_int8_t *bf; | | 435 | uint8_t *bf; |
436 | int n, ret = 0, estimate_ok = 0, estimate = 0, added = 0; | | 436 | int n, ret = 0, estimate_ok = 0, estimate = 0, added = 0; |
437 | | | 437 | |
438 | ret = kauth_authorize_device(cred, | | 438 | ret = kauth_authorize_device(cred, |
439 | KAUTH_DEVICE_RND_ADDDATA, NULL, NULL, NULL, NULL); | | 439 | KAUTH_DEVICE_RND_ADDDATA, NULL, NULL, NULL, NULL); |
440 | if (ret) { | | 440 | if (ret) { |
441 | return (ret); | | 441 | return (ret); |
442 | } | | 442 | } |
443 | estimate_ok = !kauth_authorize_device(cred, | | 443 | estimate_ok = !kauth_authorize_device(cred, |
444 | KAUTH_DEVICE_RND_ADDDATA_ESTIMATE, NULL, NULL, NULL, NULL); | | 444 | KAUTH_DEVICE_RND_ADDDATA_ESTIMATE, NULL, NULL, NULL, NULL); |
445 | | | 445 | |
446 | DPRINTF(RND_DEBUG_WRITE, | | 446 | DPRINTF(RND_DEBUG_WRITE, |
447 | ("Random: Write of %zu requested\n", uio->uio_resid)); | | 447 | ("Random: Write of %zu requested\n", uio->uio_resid)); |
448 | | | 448 | |
| @@ -590,27 +590,27 @@ rnd_ioctl(struct file *fp, u_long cmd, v | | | @@ -590,27 +590,27 @@ rnd_ioctl(struct file *fp, u_long cmd, v |
590 | | | 590 | |
591 | switch (cmd) { | | 591 | switch (cmd) { |
592 | | | 592 | |
593 | /* | | 593 | /* |
594 | * Handled in upper layer really, but we have to return zero | | 594 | * Handled in upper layer really, but we have to return zero |
595 | * for it to be accepted by the upper layer. | | 595 | * for it to be accepted by the upper layer. |
596 | */ | | 596 | */ |
597 | case FIONBIO: | | 597 | case FIONBIO: |
598 | case FIOASYNC: | | 598 | case FIOASYNC: |
599 | break; | | 599 | break; |
600 | | | 600 | |
601 | case RNDGETENTCNT: | | 601 | case RNDGETENTCNT: |
602 | mutex_spin_enter(&rndpool_mtx); | | 602 | mutex_spin_enter(&rndpool_mtx); |
603 | *(u_int32_t *)addr = rndpool_get_entropy_count(&rnd_pool); | | 603 | *(uint32_t *)addr = rndpool_get_entropy_count(&rnd_pool); |
604 | mutex_spin_exit(&rndpool_mtx); | | 604 | mutex_spin_exit(&rndpool_mtx); |
605 | break; | | 605 | break; |
606 | | | 606 | |
607 | case RNDGETPOOLSTAT: | | 607 | case RNDGETPOOLSTAT: |
608 | mutex_spin_enter(&rndpool_mtx); | | 608 | mutex_spin_enter(&rndpool_mtx); |
609 | rndpool_get_stats(&rnd_pool, addr, sizeof(rndpoolstat_t)); | | 609 | rndpool_get_stats(&rnd_pool, addr, sizeof(rndpoolstat_t)); |
610 | mutex_spin_exit(&rndpool_mtx); | | 610 | mutex_spin_exit(&rndpool_mtx); |
611 | break; | | 611 | break; |
612 | | | 612 | |
613 | case RNDGETSRCNUM: | | 613 | case RNDGETSRCNUM: |
614 | rst = (rndstat_t *)addr; | | 614 | rst = (rndstat_t *)addr; |
615 | | | 615 | |
616 | if (rst->count == 0) | | 616 | if (rst->count == 0) |