From 8ca778c15652219578531c20872bba924d69ddd5 Mon Sep 17 00:00:00 2001 From: CentOS Sources Date: May 04 2023 12:55:37 +0000 Subject: import libreswan-4.5-1.el8_7.1 --- diff --git a/SOURCES/libreswan-4.5-ikev1-aggr.patch b/SOURCES/libreswan-4.5-ikev1-aggr.patch new file mode 100644 index 0000000..960e73c --- /dev/null +++ b/SOURCES/libreswan-4.5-ikev1-aggr.patch @@ -0,0 +1,217 @@ +From c964eedcefb52eadcc7b30178378ed7d07b3510f Mon Sep 17 00:00:00 2001 +From: Daiki Ueno +Date: Tue, 18 Apr 2023 10:43:30 +0900 +Subject: [PATCH 1/2] Fix CVE-2023-30570 + +Signed-off-by: Daiki Ueno +--- + programs/pluto/ikev1.c | 61 +++++++++++++++++++++++++++++++++++-- + programs/pluto/ikev1_aggr.c | 5 +-- + 2 files changed, 61 insertions(+), 5 deletions(-) + +diff --git a/programs/pluto/ikev1.c b/programs/pluto/ikev1.c +index 9f4847874d..fa7adba2ba 100644 +--- a/programs/pluto/ikev1.c ++++ b/programs/pluto/ikev1.c +@@ -1250,10 +1250,20 @@ void process_v1_packet(struct msg_digest *md) + struct state *st = NULL; + enum state_kind from_state = STATE_UNDEFINED; /* state we started in */ + ++ /* ++ * For the initial responses, don't leak the responder's SPI. ++ * Hence the use of send_v1_notification_from_md(). ++ * ++ * AGGR mode is a mess in that the R0->R1 transition happens ++ * well before the transition succeeds. ++ */ + #define SEND_NOTIFICATION(t) \ + { \ + pstats(ikev1_sent_notifies_e, t); \ +- if (st != NULL) \ ++ if (st != NULL && \ ++ st->st_state->kind != STATE_AGGR_R0 && \ ++ st->st_state->kind != STATE_AGGR_R1 && \ ++ st->st_state->kind != STATE_MAIN_R0) \ + send_notification_from_state(st, from_state, t); \ + else \ + send_notification_from_md(md, t); \ +@@ -1323,17 +1333,26 @@ void process_v1_packet(struct msg_digest *md) + from_state = (md->hdr.isa_xchg == ISAKMP_XCHG_IDPROT ? + STATE_MAIN_R0 : STATE_AGGR_R0); + } else { +- /* not an initial message */ ++ /* ++ * Possibly not an initial message. Possibly ++ * from initiator. Possibly from responder. ++ * ++ * Possibly. Which is probably hopeless. ++ */ + + st = find_state_ikev1(&md->hdr.isa_ike_spis, + md->hdr.isa_msgid); + + if (st == NULL) { + /* +- * perhaps this is a first message ++ * Perhaps this is a first message + * from the responder and contains a + * responder cookie that we've not yet + * seen. ++ * ++ * Perhaps this is a random message ++ * with a bogus non-zero responder IKE ++ * SPI. + */ + st = find_state_ikev1_init(&md->hdr.isa_ike_initiator_spi, + md->hdr.isa_msgid); +@@ -1344,6 +1363,21 @@ void process_v1_packet(struct msg_digest *md) + /* XXX Could send notification back */ + return; + } ++ if (st->st_state->kind == STATE_AGGR_R0) { ++ /* ++ * The only way for this to ++ * happen is for the attacker ++ * to guess the responder's ++ * IKE SPI that hasn't been ++ * sent over the wire? ++ * ++ * Well that or played 1/2^32 ++ * odds. ++ */ ++ llog_pexpect(md->md_logger, HERE, ++ "phase 1 message matching AGGR_R0 state"); ++ return; ++ } + } + from_state = st->st_state->kind; + } +@@ -3052,7 +3086,28 @@ void complete_v1_state_transition(struct state *st, struct msg_digest *md, stf_s + delete_state(st); + /* wipe out dangling pointer to st */ + md->v1_st = NULL; ++ } else if (st->st_state->kind == STATE_AGGR_R0 || ++ st->st_state->kind == STATE_AGGR_R1 || ++ st->st_state->kind == STATE_MAIN_R0) { ++ /* ++ * ++ * Wipe out the incomplete larval state. ++ * ++ * ARGH! In <=v4.10, the aggr code flipped the ++ * larval state to R1 right at the start of ++ * the transition and not the end, so using ++ * state to figure things out is close to ++ * useless. ++ * ++ * Deleting the state means that pluto has no ++ * way to detect and ignore amplification ++ * attacks. ++ */ ++ delete_state(st); ++ /* wipe out dangling pointer to st */ ++ md->v1_st = NULL; + } ++ + break; + } + } +diff --git a/programs/pluto/ikev1_aggr.c b/programs/pluto/ikev1_aggr.c +index 8ad4678e1f..47a1eda424 100644 +--- a/programs/pluto/ikev1_aggr.c ++++ b/programs/pluto/ikev1_aggr.c +@@ -176,7 +176,7 @@ stf_status aggr_inI1_outR1(struct state *unused_st UNUSED, + struct ike_sa *ike = new_v1_rstate(c, md); + struct state *st = &ike->sa; + md->v1_st = st; /* (caller will reset cur_state) */ +- change_state(st, STATE_AGGR_R1); ++ change_state(st, STATE_AGGR_R0); + + /* warn for especially dangerous Aggressive Mode and PSK */ + if (LIN(POLICY_PSK, c->policy) && LIN(POLICY_AGGRESSIVE, c->policy)) { +@@ -193,7 +193,8 @@ stf_status aggr_inI1_outR1(struct state *unused_st UNUSED, + + if (!v1_decode_certs(md)) { + log_state(RC_LOG, st, "X509: CERT payload bogus or revoked"); +- return false; ++ /* XXX notification is in order! */ ++ return STF_FAIL + INVALID_ID_INFORMATION; + } + + /* +-- +2.39.2 + + +From 1d8b49905b374af294f23dad2e165931ca081d16 Mon Sep 17 00:00:00 2001 +From: Andrew Cagney +Date: Sat, 25 Mar 2023 19:40:52 -0400 +Subject: [PATCH 2/2] ikev1: add --impair + copy_v1_notify_response_SPIs_to_retransmission + +--- + include/impair.h | 2 ++ + lib/libswan/impair.c | 6 ++++++ + programs/pluto/ikev1.c | 10 ++++++++++ + 3 files changed, 18 insertions(+) + +diff --git a/include/impair.h b/include/impair.h +index 15fa2a2dc3..26900146e0 100644 +--- a/include/impair.h ++++ b/include/impair.h +@@ -153,6 +153,8 @@ struct impair { + bool omit_v2_ike_auth_child; + bool ignore_v2_ike_auth_child; + ++ bool copy_v1_notify_response_SPIs_to_retransmission; ++ + /* + * add more here + */ +diff --git a/lib/libswan/impair.c b/lib/libswan/impair.c +index 404ca96f1a..5d139410ad 100644 +--- a/lib/libswan/impair.c ++++ b/lib/libswan/impair.c +@@ -97,6 +97,8 @@ struct impairment impairments[] = { + + #define A(WHAT, ACTION, PARAM, HELP, UNSIGNED_HELP, ...) { .what = WHAT, .action = CALL_##ACTION, .param = PARAM, .help = HELP, .unsigned_help = UNSIGNED_HELP, ##__VA_ARGS__, } + #define V(WHAT, VALUE, HELP, ...) { .what = WHAT, .action = CALL_IMPAIR_UPDATE, .value = &impair.VALUE, .help = HELP, .sizeof_value = sizeof(impair.VALUE), ##__VA_ARGS__, } ++#define B(VALUE, HELP, ...) \ ++ { .what = #VALUE, .action = CALL_IMPAIR_UPDATE, .value = &impair.VALUE, .help = HELP, .sizeof_value = sizeof(impair.VALUE), ##__VA_ARGS__, } + + V("allow-dns-insecure", allow_dns_insecure, "allow IPSECKEY lookups without DNSSEC protection"), + V("allow-null-none", allow_null_none, "cause pluto to allow esp=null-none and ah=none for testing"), +@@ -198,6 +200,10 @@ struct impairment impairments[] = { + A("event-sa-replace", STATE_EVENT_HANDLER, EVENT_SA_REPLACE, + "trigger the replace event", "SA"), + ++ B(copy_v1_notify_response_SPIs_to_retransmission, ++ "copy SPIs in IKEv1 notify response to last sent packet and then retransmit"), ++ ++#undef B + #undef V + #undef A + +diff --git a/programs/pluto/ikev1.c b/programs/pluto/ikev1.c +index fa7adba2ba..b822995f1f 100644 +--- a/programs/pluto/ikev1.c ++++ b/programs/pluto/ikev1.c +@@ -2398,6 +2398,16 @@ void process_packet_tail(struct msg_digest *md) + enum_show(& ikev1_notify_names, + p->payload.notification.isan_type, &b)); + } else { ++ if (impair.copy_v1_notify_response_SPIs_to_retransmission) { ++ dbg("IMPAIR: copying notify response SPIs to recorded message and then resending it"); ++ /* skip non-ESP marker if needed */ ++ size_t skip = (st->st_interface->esp_encapsulation_enabled ? NON_ESP_MARKER_SIZE : 0); ++ size_t spis = sizeof(md->hdr.isa_ike_spis); ++ PASSERT(st->st_logger, st->st_v1_tpacket.len >= skip + spis); ++ memcpy(st->st_v1_tpacket.ptr + skip, &md->hdr.isa_ike_spis, spis); ++ resend_recorded_v1_ike_msg(st, "IMPAIR: retransmitting mangled packet"); ++ } ++ + esb_buf b; + LOG_PACKET(RC_LOG_SERIOUS, + "ignoring informational payload %s, msgid=%08" PRIx32 ", length=%d", +-- +2.39.2 + diff --git a/SPECS/libreswan.spec b/SPECS/libreswan.spec index dac2503..486c06a 100644 --- a/SPECS/libreswan.spec +++ b/SPECS/libreswan.spec @@ -37,7 +37,7 @@ Name: libreswan Summary: IPsec implementation with IKEv1 and IKEv2 keying protocols # version is generated in the release script Version: 4.5 -Release: %{?prever:0.}1%{?prever:.%{prever}}%{?dist} +Release: %{?prever:0.}1%{?prever:.%{prever}}%{?dist}.1 License: GPLv2 Url: https://libreswan.org/ @@ -53,6 +53,7 @@ Patch2: libreswan-3.32-1861360-nodefault-rsa-pss.patch Patch3: libreswan-4.1-maintain-obsolete-keywords.patch Patch6: libreswan-4.3-1934186-config.patch Patch7: libreswan-4.4-ikev1-disable-diagnostics.patch +Patch8: libreswan-4.5-ikev1-aggr.patch BuildRequires: audit-libs-devel BuildRequires: bison @@ -112,6 +113,7 @@ Libreswan is based on Openswan-2.6.38 which in turn is based on FreeS/WAN-2.04 %patch3 -p1 %patch6 -p1 %patch7 -p1 +%patch8 -p1 # linking to freebl is not needed sed -i "s/-lfreebl //" mk/config.mk @@ -215,6 +217,9 @@ certutil -N -d sql:$tmpdir --empty-password %attr(0644,root,root) %doc %{_mandir}/*/* %changelog +* Fri Apr 21 2023 Daiki Ueno - 4.5-1.1 +- Resolves: rhbz#2187178 fix handling of IKEv1 aggressive mode packets + * Thu Jan 13 2022 Daiki Ueno - 4.5-1 - Resolves: rhbz#2017352 Rebase libreswan to 4.5 - Resolves: rhbz#2036903 ikev1: disable diagnostics logging on receiving malformed packets