summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Bluhm <bluhm@cvs.openbsd.org>2021-10-25 18:25:02 +0000
committerAlexander Bluhm <bluhm@cvs.openbsd.org>2021-10-25 18:25:02 +0000
commitef4ace0cd1a164601a905c8cb67cc0e5151d65bb (patch)
tree1e4d5b8979eaa4d7d7b21145934039cb7ff43d5f
parent172c70b6e2ece49a483eaf3f9097804f20220ce5 (diff)
Call a locked variant of tdb_unlink() from tdb_walk(). Fixes a
mutex locking against myself panic introduced by my previous commit. OK beck@ patrick@
-rw-r--r--sys/net/pfkeyv2.c8
-rw-r--r--sys/netinet/ip_ipsp.c14
-rw-r--r--sys/netinet/ip_ipsp.h3
3 files changed, 18 insertions, 7 deletions
diff --git a/sys/net/pfkeyv2.c b/sys/net/pfkeyv2.c
index 336619f4c89..f34bd29a7f5 100644
--- a/sys/net/pfkeyv2.c
+++ b/sys/net/pfkeyv2.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pfkeyv2.c,v 1.220 2021/10/22 12:30:53 bluhm Exp $ */
+/* $OpenBSD: pfkeyv2.c,v 1.221 2021/10/25 18:25:01 bluhm Exp $ */
/*
* @(#)COPYRIGHT 1.1 (NRL) 17 January 1995
@@ -1042,8 +1042,10 @@ int
pfkeyv2_sa_flush(struct tdb *tdb, void *satype_vp, int last)
{
if (!(*((u_int8_t *) satype_vp)) ||
- tdb->tdb_satype == *((u_int8_t *) satype_vp))
- tdb_delete(tdb);
+ tdb->tdb_satype == *((u_int8_t *) satype_vp)) {
+ tdb_unlink_locked(tdb);
+ tdb_free(tdb);
+ }
return (0);
}
diff --git a/sys/netinet/ip_ipsp.c b/sys/netinet/ip_ipsp.c
index 01dec0abc8f..25801a57df1 100644
--- a/sys/netinet/ip_ipsp.c
+++ b/sys/netinet/ip_ipsp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ip_ipsp.c,v 1.247 2021/10/25 16:00:12 bluhm Exp $ */
+/* $OpenBSD: ip_ipsp.c,v 1.248 2021/10/25 18:25:01 bluhm Exp $ */
/*
* The authors of this code are John Ioannidis (ji@tla.org),
* Angelos D. Keromytis (kermit@csd.uch.gr),
@@ -733,10 +733,19 @@ puttdb(struct tdb *tdbp)
void
tdb_unlink(struct tdb *tdbp)
{
+ mtx_enter(&tdb_sadb_mtx);
+ tdb_unlink_locked(tdbp);
+ mtx_leave(&tdb_sadb_mtx);
+}
+
+void
+tdb_unlink_locked(struct tdb *tdbp)
+{
struct tdb *tdbpp;
u_int32_t hashval;
- mtx_enter(&tdb_sadb_mtx);
+ MUTEX_ASSERT_LOCKED(&tdb_sadb_mtx);
+
hashval = tdb_hash(tdbp->tdb_spi, &tdbp->tdb_dst, tdbp->tdb_sproto);
if (tdbh[hashval] == tdbp) {
@@ -793,7 +802,6 @@ tdb_unlink(struct tdb *tdbp)
ipsecstat_inc(ipsec_prevtunnels);
}
#endif /* IPSEC */
- mtx_leave(&tdb_sadb_mtx);
}
void
diff --git a/sys/netinet/ip_ipsp.h b/sys/netinet/ip_ipsp.h
index 1fcd6ca87ff..efe90827f59 100644
--- a/sys/netinet/ip_ipsp.h
+++ b/sys/netinet/ip_ipsp.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ip_ipsp.h,v 1.218 2021/10/24 23:33:37 tobhe Exp $ */
+/* $OpenBSD: ip_ipsp.h,v 1.219 2021/10/25 18:25:01 bluhm Exp $ */
/*
* The authors of this code are John Ioannidis (ji@tla.org),
* Angelos D. Keromytis (kermit@csd.uch.gr),
@@ -558,6 +558,7 @@ struct tdb *tdb_alloc(u_int);
void tdb_free(struct tdb *);
int tdb_init(struct tdb *, u_int16_t, struct ipsecinit *);
void tdb_unlink(struct tdb *);
+void tdb_unlink_locked(struct tdb *);
int tdb_walk(u_int, int (*)(struct tdb *, void *, int), void *);
/* XF_IP4 */