diff --git a/0001-libreswan-anolis-rebrand-to-anolis.patch b/0001-libreswan-anolis-rebrand-to-anolis.patch deleted file mode 100644 index 21068ddbe717a63231880fb31567b2762731b8d1..0000000000000000000000000000000000000000 --- a/0001-libreswan-anolis-rebrand-to-anolis.patch +++ /dev/null @@ -1,87 +0,0 @@ -From c0ae1f9070d386036a793d3e8eac7a787e7017a0 Mon Sep 17 00:00:00 2001 -From: "yangxiaoxuan@openanolis.org" -Date: Mon, 21 Jun 2021 22:48:03 +0800 -Subject: [PATCH] libreswan anolis rebrand to anolis - ---- - Makefile | 2 +- - mk/defaults/linux.mk | 2 +- - programs/barf/barf.in | 2 +- - testing/guestbin/docker-transmogrify | 8 +++++--- - 4 files changed, 8 insertions(+), 6 deletions(-) - -diff --git a/Makefile b/Makefile -index db230d4..bafddc2 100644 ---- a/Makefile -+++ b/Makefile -@@ -27,7 +27,7 @@ include ${LIBRESWANSRCDIR}/Makefile.inc - MAIN_RPM_VERSION = $(shell make showversion | sed "s/-.*//") - MAIN_RPM_PREVER = $(shell make showversion | sed -e "s/^.[^-]*-\([^-]*\)-\(.*\)/rc\1_\2/" -e "s/-/_/g") - MAIN_RPM_PREFIX = libreswan-$(MAIN_RPM_VERSION)$(MAIN_RPM_PREVER) --MAIN_RPM_RHEL_PKG = $(shell rpm -qf /etc/redhat-release) -+MAIN_RPM_RHEL_PKG = $(shell rpm -qf /etc/anolis-release) - MAIN_RPM_RHEL_VERSION = $(shell echo $(MAIN_RPM_RHEL_PKG) | sed "s/.*-release-\(.\).*/\1/") - MAIN_RPM_SPECFILE = $(shell if [ -f /etc/fedora-release ]; then echo packaging/fedora/libreswan.spec; elif [ -n "$(MAIN_RPM_RHEL_VERSION)" ]; then echo packaging/rhel/$(MAIN_RPM_RHEL_VERSION)/libreswan.spec; else echo "unknown distro, cannot find spec file to use in packaging directory"; fi) - RHEL_LIKE= $(shell cat /etc/os-release | grep ID_LIKE | sed -e "s/ID_LIKE=//" -e 's/"//g' -e "s/ .*//") -diff --git a/mk/defaults/linux.mk b/mk/defaults/linux.mk -index c286a7d..56a3e20 100644 ---- a/mk/defaults/linux.mk -+++ b/mk/defaults/linux.mk -@@ -131,7 +131,7 @@ ifndef INITSYSTEM - INITSYSTEM=systemd - else ifneq ($(and $(wildcard /lib/systemd/systemd),$(wildcard /var/run/systemd)),) - INITSYSTEM=systemd -- else ifneq ($(and $(wildcard /sbin/start),$(wildcard /etc/redhat-release)),) -+ else ifneq ($(and $(wildcard /sbin/start),$(wildcard /etc/anolis-release)),) - # override for rhel/centos to use sysvinit - INITSYSTEM=sysvinit - else ifneq ($(wildcard /sbin/start),) -diff --git a/programs/barf/barf.in b/programs/barf/barf.in -index e76c62f..7a7a61a 100755 ---- a/programs/barf/barf.in -+++ b/programs/barf/barf.in -@@ -248,7 +248,7 @@ if [ -r /proc/config_built_with ]; then - cat /proc/config_built_with - fi - _________________________ distro-release --for distro in /etc/redhat-release /etc/debian-release /etc/SuSE-release /etc/mandrake-release /etc/mandriva-release /etc/gentoo-release -+for distro in /etc/redhat-release /etc/anolis-release /etc/debian-release /etc/SuSE-release /etc/mandrake-release /etc/mandriva-release /etc/gentoo-release - do - if [ -f ${distro} ]; then - cat ${distro} -diff --git a/testing/guestbin/docker-transmogrify b/testing/guestbin/docker-transmogrify -index 0afa1f1..4dc7539 100755 ---- a/testing/guestbin/docker-transmogrify -+++ b/testing/guestbin/docker-transmogrify -@@ -34,7 +34,9 @@ macs['sunset'] = "12:00:00:ab:cd:01" - # conflicts with north - #macs['japan'] = "12:00:00:ab:cd:02" - --if os.path.isfile("/etc/redhat-release"): -+if os.path.isfile("/etc/anolis-release"): -+ GUESTOS = "anolis" -+elif os.path.isfile("/etc/redhat-release"): - GUESTOS = "redhat" - elif os.path.isfile("/etc/debian_version"): - GUESTOS = "debian" -@@ -136,7 +138,7 @@ else: - if os.path.isfile(hostname_file): - shutil.copyfile(hostname_file, "/etc/hostname") - --if GUESTOS == "redhat": -+if GUESTOS == "anolis": - - # these files are needed for systemd-networkd too - fnames = glob.glob("/testing/baseconfigs/all/etc/sysconfig/*") -@@ -216,7 +218,7 @@ for dbfile in glob.glob("/etc/ipsec.d/*.db"): - os.chmod(dbfile, 0o600) - - # SElinux fixup --if GUESTOS == "redhat": -+if GUESTOS == "anolis": - output += "\n" + subprocess.getoutput("restorecon -R /etc/") - - # selinux does not like our /testing include files --- -2.18.4 - diff --git a/dist b/dist new file mode 100644 index 0000000000000000000000000000000000000000..535c6900412d365bb0ff6de8d1f27110833b3ae3 --- /dev/null +++ b/dist @@ -0,0 +1 @@ +an8_7 diff --git a/libreswan-4.5-ikev1-aggr.patch b/libreswan-4.5-ikev1-aggr.patch new file mode 100644 index 0000000000000000000000000000000000000000..960e73c64ef697562a25f994243313db393470e9 --- /dev/null +++ b/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/libreswan.spec b/libreswan.spec index 77ec46646d19b43f8c83d2a95ed8084e854c9177..486c06a71965b9e4496cdc3c13d1fd0f71501f91 100644 --- a/libreswan.spec +++ b/libreswan.spec @@ -1,4 +1,3 @@ -%define anolis_release .0.1 %global _hardened_build 1 # These are rpm macros and are 0 or 1 %global with_efence 0 @@ -38,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}}%{anolis_release}%{?dist} +Release: %{?prever:0.}1%{?prever:.%{prever}}%{?dist}.1 License: GPLv2 Url: https://libreswan.org/ @@ -54,10 +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 - -#Add by Anolis -Patch1000: 0001-libreswan-anolis-rebrand-to-anolis.patch -#End +Patch8: libreswan-4.5-ikev1-aggr.patch BuildRequires: audit-libs-devel BuildRequires: bison @@ -117,8 +113,8 @@ 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 -%patch1000 -p1 # linking to freebl is not needed sed -i "s/-lfreebl //" mk/config.mk @@ -221,8 +217,8 @@ certutil -N -d sql:$tmpdir --empty-password %attr(0644,root,root) %doc %{_mandir}/*/* %changelog -* Mon Apr 18 2022 yangxiaoxuan - 4.5-1.0.1 -- Rebrand to anolis +* 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