Changeset View
Changeset View
Standalone View
Standalone View
head/usr.sbin/bhyve/pci_virtio_rnd.c
Show All 29 Lines | |||||
* Randomness is sourced from /dev/random which does not block | * Randomness is sourced from /dev/random which does not block | ||||
* once it has been seeded at bootup. | * once it has been seeded at bootup. | ||||
*/ | */ | ||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#ifndef WITHOUT_CAPSICUM | |||||
#include <sys/capsicum.h> | |||||
#endif | |||||
#include <sys/linker_set.h> | #include <sys/linker_set.h> | ||||
#include <sys/uio.h> | #include <sys/uio.h> | ||||
#include <err.h> | |||||
#include <errno.h> | #include <errno.h> | ||||
#include <fcntl.h> | #include <fcntl.h> | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include <unistd.h> | #include <unistd.h> | ||||
#include <assert.h> | #include <assert.h> | ||||
#include <pthread.h> | #include <pthread.h> | ||||
#include <sysexits.h> | |||||
#include "bhyverun.h" | #include "bhyverun.h" | ||||
#include "pci_emul.h" | #include "pci_emul.h" | ||||
#include "virtio.h" | #include "virtio.h" | ||||
#define VTRND_RINGSZ 64 | #define VTRND_RINGSZ 64 | ||||
▲ Show 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | |||||
static int | static int | ||||
pci_vtrnd_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts) | pci_vtrnd_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts) | ||||
{ | { | ||||
struct pci_vtrnd_softc *sc; | struct pci_vtrnd_softc *sc; | ||||
int fd; | int fd; | ||||
int len; | int len; | ||||
uint8_t v; | uint8_t v; | ||||
#ifndef WITHOUT_CAPSICUM | |||||
cap_rights_t rights; | |||||
#endif | |||||
/* | /* | ||||
* Should always be able to open /dev/random. | * Should always be able to open /dev/random. | ||||
*/ | */ | ||||
fd = open("/dev/random", O_RDONLY | O_NONBLOCK); | fd = open("/dev/random", O_RDONLY | O_NONBLOCK); | ||||
assert(fd >= 0); | assert(fd >= 0); | ||||
#ifndef WITHOUT_CAPSICUM | |||||
cap_rights_init(&rights, CAP_READ); | |||||
if (cap_rights_limit(fd, &rights) == -1 && errno != ENOSYS) | |||||
errx(EX_OSERR, "Unable to apply rights for sandbox"); | |||||
#endif | |||||
/* | /* | ||||
* Check that device is seeded and non-blocking. | * Check that device is seeded and non-blocking. | ||||
*/ | */ | ||||
len = read(fd, &v, sizeof(v)); | len = read(fd, &v, sizeof(v)); | ||||
if (len <= 0) { | if (len <= 0) { | ||||
WPRINTF(("vtrnd: /dev/random not ready, read(): %d", len)); | WPRINTF(("vtrnd: /dev/random not ready, read(): %d", len)); | ||||
return (1); | return (1); | ||||
Show All 34 Lines |