Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-6]: src/sys Apply patch (requested by riastradh in ticket #1512):
details: https://anonhg.NetBSD.org/src/rev/f41d2e7885d2
branches: netbsd-6
changeset: 777290:f41d2e7885d2
user: snj <snj%NetBSD.org@localhost>
date: Sat Mar 03 20:44:38 2018 +0000
description:
Apply patch (requested by riastradh in ticket #1512):
Fix panic when waiting with kqueue/kevent for a read from
/dev/random.
diffstat:
sys/dev/rndpseudo.c | 24 ++++++++++++++++++------
sys/kern/subr_cprng.c | 8 ++++----
sys/sys/cprng.h | 7 +++----
3 files changed, 25 insertions(+), 14 deletions(-)
diffs (121 lines):
diff -r 6b92c34940b6 -r f41d2e7885d2 sys/dev/rndpseudo.c
--- a/sys/dev/rndpseudo.c Mon Feb 19 20:56:37 2018 +0000
+++ b/sys/dev/rndpseudo.c Sat Mar 03 20:44:38 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rndpseudo.c,v 1.6.2.3 2012/05/21 16:49:54 jdc Exp $ */
+/* $NetBSD: rndpseudo.c,v 1.6.2.4 2018/03/03 20:44:38 snj Exp $ */
/*-
* Copyright (c) 1997-2011 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rndpseudo.c,v 1.6.2.3 2012/05/21 16:49:54 jdc Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rndpseudo.c,v 1.6.2.4 2018/03/03 20:44:38 snj Exp $");
#if defined(_KERNEL_OPT)
#include "opt_compat_netbsd.h"
@@ -673,13 +673,13 @@
}
}
+ mutex_enter(&ctx->cprng->mtx);
if (cprng_strong_ready(ctx->cprng)) {
revents |= events & (POLLIN | POLLRDNORM);
} else {
- mutex_enter(&ctx->cprng->mtx);
selrecord(curlwp, &ctx->cprng->selq);
- mutex_exit(&ctx->cprng->mtx);
}
+ mutex_exit(&ctx->cprng->mtx);
return (revents);
}
@@ -731,12 +731,24 @@
filt_rndread(struct knote *kn, long hint)
{
cprng_strong_t *c = kn->kn_hook;
+ int ret;
+ if (hint & NOTE_SUBMIT)
+ KASSERT(mutex_owned(&c->mtx));
+ else
+ mutex_enter(&c->mtx);
if (cprng_strong_ready(c)) {
kn->kn_data = RND_TEMP_BUFFER_SIZE;
- return 1;
+ ret = 1;
+ } else {
+ ret = 0;
}
- return 0;
+ if (hint & NOTE_SUBMIT)
+ KASSERT(mutex_owned(&c->mtx));
+ else
+ mutex_exit(&c->mtx);
+
+ return ret;
}
static const struct filterops rnd_seltrue_filtops =
diff -r 6b92c34940b6 -r f41d2e7885d2 sys/kern/subr_cprng.c
--- a/sys/kern/subr_cprng.c Mon Feb 19 20:56:37 2018 +0000
+++ b/sys/kern/subr_cprng.c Sat Mar 03 20:44:38 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_cprng.c,v 1.5.2.8 2013/03/29 00:44:28 msaitoh Exp $ */
+/* $NetBSD: subr_cprng.c,v 1.5.2.9 2018/03/03 20:44:38 snj Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -46,7 +46,7 @@
#include <sys/cprng.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_cprng.c,v 1.5.2.8 2013/03/29 00:44:28 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_cprng.c,v 1.5.2.9 2018/03/03 20:44:38 snj Exp $");
void
cprng_init(void)
@@ -95,7 +95,7 @@
if (c->flags & CPRNG_USE_CV) {
cv_broadcast(&c->cv);
}
- selnotify(&c->selq, 0, 0);
+ selnotify(&c->selq, 0, NOTE_SUBMIT);
}
static void
@@ -397,7 +397,7 @@
if (c->flags & CPRNG_USE_CV) {
cv_broadcast(&c->cv);
}
- selnotify(&c->selq, 0, 0);
+ selnotify(&c->selq, 0, NOTE_SUBMIT);
}
}
c->flags = flags;
diff -r 6b92c34940b6 -r f41d2e7885d2 sys/sys/cprng.h
--- a/sys/sys/cprng.h Mon Feb 19 20:56:37 2018 +0000
+++ b/sys/sys/cprng.h Sat Mar 03 20:44:38 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cprng.h,v 1.4.2.1 2012/04/20 23:35:20 riz Exp $ */
+/* $NetBSD: cprng.h,v 1.4.2.2 2018/03/03 20:44:39 snj Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -121,12 +121,11 @@
cprng_strong_ready(cprng_strong_t *c)
{
int ret = 0;
-
- mutex_enter(&c->mtx);
+
+ KASSERT(mutex_owned(&c->mtx));
if (c->drbg.reseed_counter < NIST_CTR_DRBG_RESEED_INTERVAL) {
ret = 1;
}
- mutex_exit(&c->mtx);
return ret;
}
Home |
Main Index |
Thread Index |
Old Index