diff options
author | Michael Shalayeff <mickey@cvs.openbsd.org> | 2000-10-20 03:30:07 +0000 |
---|---|---|
committer | Michael Shalayeff <mickey@cvs.openbsd.org> | 2000-10-20 03:30:07 +0000 |
commit | 1075f06ec4f587b7d8a415f7deaeca8c198cabdc (patch) | |
tree | 7bc5caaab3d31e3ad9a6c9a9e20c735e0f71a23e /sys/dev | |
parent | 63fb7c0c6150b6699379b42de130c1a8dd37fba2 (diff) |
fix ioctls; pointed out by Pawel Krawczyk <http://ceti.pl/~kravietz/>
Diffstat (limited to 'sys/dev')
-rw-r--r-- | sys/dev/rnd.c | 29 | ||||
-rw-r--r-- | sys/dev/rndioctl.h | 10 |
2 files changed, 26 insertions, 13 deletions
diff --git a/sys/dev/rnd.c b/sys/dev/rnd.c index 4df276058c1..4f750f7af2d 100644 --- a/sys/dev/rnd.c +++ b/sys/dev/rnd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rnd.c,v 1.43 2000/08/21 01:52:18 jason Exp $ */ +/* $OpenBSD: rnd.c,v 1.44 2000/10/20 03:30:05 mickey Exp $ */ /* * random.c -- A strong random number generator @@ -1037,7 +1037,7 @@ randomioctl(dev, cmd, data, flag, p) int flag; struct proc *p; { - int ret = 0; + int s, ret = 0; u_int cnt; add_timer_randomness((u_long)p ^ (u_long)data ^ cmd); @@ -1052,38 +1052,51 @@ randomioctl(dev, cmd, data, flag, p) break; case RNDGETENTCNT: - ret = copyout(&random_state.entropy_count, data, - sizeof(random_state.entropy_count)); + s = splhigh(); + *(u_int *)data = random_state.entropy_count; + splx(s); break; case RNDADDTOENTCNT: if (suser(p->p_ucred, &p->p_acflag) != 0) ret = EPERM; else { - copyin(&cnt, data, sizeof(cnt)); + cnt = *(u_int *)data; + printf("%d\n", cnt); + s = splhigh(); random_state.entropy_count += cnt; if (random_state.entropy_count > POOLBITS) random_state.entropy_count = POOLBITS; + splx(s); } break; case RNDZAPENTCNT: if (suser(p->p_ucred, &p->p_acflag) != 0) ret = EPERM; - else + else { + s = splhigh(); random_state.entropy_count = 0; + splx(s); + } break; case RNDSTIRARC4: if (suser(p->p_ucred, &p->p_acflag) != 0) ret = EPERM; else if (random_state.entropy_count < 64) ret = EAGAIN; - else + else { + s = splhigh(); arc4random_initialized = 0; + splx(s); + } break; case RNDCLRSTATS: if (suser(p->p_ucred, &p->p_acflag) != 0) ret = EPERM; - else + else { + s = splhigh(); bzero(&rndstats, sizeof(rndstats)); + splx(s); + } break; default: ret = EINVAL; diff --git a/sys/dev/rndioctl.h b/sys/dev/rndioctl.h index e824a4bea67..31e0c0bed8f 100644 --- a/sys/dev/rndioctl.h +++ b/sys/dev/rndioctl.h @@ -1,4 +1,4 @@ -/* $OpenBSD: rndioctl.h,v 1.8 2000/04/13 13:48:30 mickey Exp $ */ +/* $OpenBSD: rndioctl.h,v 1.9 2000/10/20 03:30:06 mickey Exp $ */ /* * Copyright (c) 1996,2000 Michael Shalayeff. @@ -46,10 +46,10 @@ struct rnd_pool_info { u_int32_t *buf; }; -#define RNDGETENTCNT _IOR('R', 0, sizeof(u_int)) -#define RNDADDTOENTCNT _IOW('R', 1, sizeof(u_int)) -#define RNDGETPOOL _IOWR('R', 2, sizeof(struct rnd_pool_info)) -#define RNDADDENTROPY _IOW('R', 3, sizeof(u_int)) +#define RNDGETENTCNT _IOR('R', 0, u_int) +#define RNDADDTOENTCNT _IOW('R', 1, u_int) +#define RNDGETPOOL _IOWR('R', 2, struct rnd_pool_info) +#define RNDADDENTROPY _IOW('R', 3, u_int) #define RNDZAPENTCNT _IO( 'R', 4) #define RNDSTIRARC4 _IO( 'R', 5) #define RNDCLRSTATS _IO( 'R', 6) |