1ea45c
From 7a6c217f47b1ae37e32b173dc6d3ea7fdb86d532 Mon Sep 17 00:00:00 2001
1ea45c
From: Paul Wouters <paul.wouters@aiven.io>
1ea45c
Date: Tue, 28 Feb 2023 11:24:22 -0500
1ea45c
Subject: [PATCH 1/2] pluto: abort processing corrupt TS payloads
1ea45c
 CVE-2023-23009
1ea45c
1ea45c
Latest updates on this issue at https://libreswan.org/security/CVE-2023-23009
1ea45c
---
1ea45c
 programs/pluto/ikev2_ts.c | 5 +++++
1ea45c
 1 file changed, 5 insertions(+)
1ea45c
1ea45c
diff --git a/programs/pluto/ikev2_ts.c b/programs/pluto/ikev2_ts.c
1ea45c
index 3f7519ca38..f06c40ba46 100644
1ea45c
--- a/programs/pluto/ikev2_ts.c
1ea45c
+++ b/programs/pluto/ikev2_ts.c
1ea45c
@@ -437,6 +437,11 @@ static bool v2_parse_tss(struct payload_digest *const ts_pd,
1ea45c
 		d = pbs_in_struct(&ts_pd->pbs, &ikev2_ts_header_desc,
1ea45c
 			  &ts_h, sizeof(ts_h), &ts_body_pbs);
1ea45c
 
1ea45c
+		if (d != NULL) {
1ea45c
+			llog_diag(RC_LOG, logger, &d, "%s", "");
1ea45c
+			return false;
1ea45c
+		}
1ea45c
+
1ea45c
 		switch (ts_h.isath_type) {
1ea45c
 		case IKEv2_TS_IPV4_ADDR_RANGE:
1ea45c
 		case IKEv2_TS_IPV6_ADDR_RANGE:
1ea45c
-- 
1ea45c
2.39.2
1ea45c
1ea45c
1ea45c
From 52c19ccc9455ccd91fa4946b09f8e11222f1c923 Mon Sep 17 00:00:00 2001
1ea45c
From: Andrew Cagney <cagney@gnu.org>
1ea45c
Date: Tue, 28 Feb 2023 14:10:44 -0500
1ea45c
Subject: [PATCH 2/2] ikev1: only clean up a connection when it isn't deleted
1ea45c
1ea45c
fix #1018 reported by Wolfgang.
1ea45c
see also ecb9c88910df1fb070488835bf3180096f3ccba3:
1ea45c
IKEv1: Remove all IPsec SA's of a connection when newest SA is removed.
1ea45c
---
1ea45c
 programs/pluto/ikev1_main.c | 14 ++++++++++----
1ea45c
 1 file changed, 10 insertions(+), 4 deletions(-)
1ea45c
1ea45c
diff --git a/programs/pluto/ikev1_main.c b/programs/pluto/ikev1_main.c
1ea45c
index a616c5ccf3..21765d4002 100644
1ea45c
--- a/programs/pluto/ikev1_main.c
1ea45c
+++ b/programs/pluto/ikev1_main.c
1ea45c
@@ -2130,15 +2130,16 @@ bool accept_delete(struct msg_digest *md,
1ea45c
 						  ntohl(spi));
1ea45c
 				}
1ea45c
 
1ea45c
-				struct connection *rc = dst->st_connection;
1ea45c
+				/* save for post delete_state() code */
1ea45c
+				co_serial_t rc_serialno = dst->st_connection->serialno;
1ea45c
 
1ea45c
 				if (nat_traversal_enabled && dst->st_connection->ikev1_natt != NATT_NONE) {
1ea45c
 					nat_traversal_change_port_lookup(md, dst);
1ea45c
 					v1_maybe_natify_initiator_endpoints(st, HERE);
1ea45c
 				}
1ea45c
 
1ea45c
-				if (rc->newest_ipsec_sa == dst->st_serialno &&
1ea45c
-					(rc->policy & POLICY_UP)) {
1ea45c
+				if (dst->st_connection->newest_ipsec_sa == dst->st_serialno &&
1ea45c
+				    (dst->st_connection->policy & POLICY_UP)) {
1ea45c
 					/*
1ea45c
 					 * Last IPsec SA for a permanent
1ea45c
 					 * connection that we have initiated.
1ea45c
@@ -2162,7 +2163,12 @@ bool accept_delete(struct msg_digest *md,
1ea45c
 						md->v1_st = NULL;
1ea45c
 				}
1ea45c
 
1ea45c
-				if (rc->newest_ipsec_sa == SOS_NOBODY) {
1ea45c
+				/*
1ea45c
+				 * Either .newest_ipsec_sa matches DST
1ea45c
+				 * and is cleared, or was never set.
1ea45c
+				 */
1ea45c
+				struct connection *rc = connection_by_serialno(rc_serialno);
1ea45c
+				if (rc != NULL && rc->newest_ipsec_sa == SOS_NOBODY) {
1ea45c
 					dbg("%s() connection '%s' -POLICY_UP", __func__, rc->name);
1ea45c
 					rc->policy &= ~POLICY_UP;
1ea45c
 					if (!shared_phase1_connection(rc)) {
1ea45c
-- 
1ea45c
2.39.2
1ea45c