Module Name: src
Committed By: martin
Date: Sat Aug 25 14:35:22 UTC 2018
Modified Files:
src/sys/netipsec [netbsd-8]: key.c
Log Message:
Pull up following revision(s) (requested by ozaki-r in ticket #986):
sys/netipsec/key.c: revision 1.257
Don't call key_ismyaddr, which may sleep, in a pserialize read section
Use mutex here instead of pserialize because using mutex is simpler than
using psz+ref, which is another solution, and key_checkspidup isn't called in
any performance-sensitive paths.
To generate a diff of this commit:
cvs rdiff -u -r1.163.2.9 -r1.163.2.10 src/sys/netipsec/key.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/netipsec/key.c
diff -u src/sys/netipsec/key.c:1.163.2.9 src/sys/netipsec/key.c:1.163.2.10
--- src/sys/netipsec/key.c:1.163.2.9 Wed Apr 18 14:06:24 2018
+++ src/sys/netipsec/key.c Sat Aug 25 14:35:21 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: key.c,v 1.163.2.9 2018/04/18 14:06:24 martin Exp $ */
+/* $NetBSD: key.c,v 1.163.2.10 2018/08/25 14:35:21 martin Exp $ */
/* $FreeBSD: src/sys/netipsec/key.c,v 1.3.2.3 2004/02/14 22:23:23 bms Exp $ */
/* $KAME: key.c,v 1.191 2001/06/27 10:46:49 sakane Exp $ */
@@ -32,7 +32,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: key.c,v 1.163.2.9 2018/04/18 14:06:24 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: key.c,v 1.163.2.10 2018/08/25 14:35:21 martin Exp $");
/*
* This code is referred to RFC 2367
@@ -3458,7 +3458,6 @@ key_checkspidup(const struct secasindex
{
struct secashead *sah;
struct secasvar *sav;
- int s;
/* check address family */
if (saidx->src.sa.sa_family != saidx->dst.sa.sa_family) {
@@ -3467,18 +3466,19 @@ key_checkspidup(const struct secasindex
}
/* check all SAD */
- s = pserialize_read_enter();
- SAHLIST_READER_FOREACH(sah) {
+ /* key_ismyaddr may sleep, so use mutex, not pserialize, here. */
+ mutex_enter(&key_sad.lock);
+ SAHLIST_WRITER_FOREACH(sah) {
if (!key_ismyaddr((struct sockaddr *)&sah->saidx.dst))
continue;
sav = key_getsavbyspi(sah, spi);
if (sav != NULL) {
- pserialize_read_exit(s);
KEY_SA_UNREF(&sav);
+ mutex_exit(&key_sad.lock);
return true;
}
}
- pserialize_read_exit(s);
+ mutex_exit(&key_sad.lock);
return false;
}