aboutsummaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorMarcin Wojtas <mw@FreeBSD.org>2020-05-26 14:16:26 +0000
committerMarcin Wojtas <mw@FreeBSD.org>2020-05-26 14:16:26 +0000
commitb01edfb515c96c7b437127f62a809da45435d2e7 (patch)
treec7408cf0a67872cfdac9c1474dfb8e38d5ac8e32 /sys
parentda6526096f021e2d0a3ff728545da9b8e87ba2e2 (diff)
downloadsrc-b01edfb515c96c7b437127f62a809da45435d2e7.tar.gz
src-b01edfb515c96c7b437127f62a809da45435d2e7.zip
Fix AES-CTR compatibility issue in ipsec
r361390 decreased blocksize of AES-CTR from 16 to 1. Because of that ESP payload is no longer aligned to 16 bytes before being encrypted and sent. This is a good change since RFC3686 specifies that the last block doesn't need to be aligned. Since FreeBSD before r361390 couldn't decrypt partial blocks encrypted with AES-CTR we need to enforce 16 byte alignment in order to preserve compatibility. Add a sysctl(on by default) to control it. Submitted by: Kornel Duleba <mindal@semihalf.com> Reviewed by: jhb Obtained from: Semihalf Sponsored by: Stormshield Differential Revision: https://reviews.freebsd.org/D24999
Notes
Notes: svn path=/head/; revision=361507
Diffstat (limited to 'sys')
-rw-r--r--sys/netipsec/xform_esp.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/sys/netipsec/xform_esp.c b/sys/netipsec/xform_esp.c
index 214df48157c9..8a378c4adaf8 100644
--- a/sys/netipsec/xform_esp.c
+++ b/sys/netipsec/xform_esp.c
@@ -80,6 +80,8 @@
#include <opencrypto/xform.h>
VNET_DEFINE(int, esp_enable) = 1;
+VNET_DEFINE_STATIC(int, esp_ctr_compatibility) = 1;
+#define V_esp_ctr_compatibility VNET(esp_ctr_compatibility)
VNET_PCPUSTAT_DEFINE(struct espstat, espstat);
VNET_PCPUSTAT_SYSINIT(espstat);
@@ -90,6 +92,9 @@ VNET_PCPUSTAT_SYSUNINIT(espstat);
SYSCTL_DECL(_net_inet_esp);
SYSCTL_INT(_net_inet_esp, OID_AUTO, esp_enable,
CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(esp_enable), 0, "");
+SYSCTL_INT(_net_inet_esp, OID_AUTO, ctr_compatibility,
+ CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(esp_ctr_compatibility), 0,
+ "Align AES-CTR encrypted transmitted frames to blocksize");
SYSCTL_VNET_PCPUSTAT(_net_inet_esp, IPSECCTL_STATS, stats,
struct espstat, espstat,
"ESP statistics (struct espstat, netipsec/esp_var.h");
@@ -652,8 +657,14 @@ esp_output(struct mbuf *m, struct secpolicy *sp, struct secasvar *sav,
rlen = m->m_pkthdr.len - skip; /* Raw payload length. */
/*
* RFC4303 2.4 Requires 4 byte alignment.
+ * Old versions of FreeBSD can't decrypt partial blocks encrypted
+ * with AES-CTR. Align payload to native_blocksize (16 bytes)
+ * in order to preserve compatibility.
*/
- blks = MAX(4, espx->blocksize); /* Cipher blocksize */
+ if (SAV_ISCTR(sav) && V_esp_ctr_compatibility)
+ blks = MAX(4, espx->native_blocksize); /* Cipher blocksize */
+ else
+ blks = MAX(4, espx->blocksize);
/* XXX clamp padding length a la KAME??? */
padding = ((blks - ((rlen + 2) % blks)) % blks) + 2;