From owner-svn-src-all@freebsd.org Tue May 26 14:16:27 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 37E302FFDFA; Tue, 26 May 2020 14:16:27 +0000 (UTC) (envelope-from mw@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 49WbcC0mGNz4F14; Tue, 26 May 2020 14:16:27 +0000 (UTC) (envelope-from mw@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id F10B224851; Tue, 26 May 2020 14:16:26 +0000 (UTC) (envelope-from mw@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 04QEGQeB014380; Tue, 26 May 2020 14:16:26 GMT (envelope-from mw@FreeBSD.org) Received: (from mw@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 04QEGQtN014379; Tue, 26 May 2020 14:16:26 GMT (envelope-from mw@FreeBSD.org) Message-Id: <202005261416.04QEGQtN014379@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mw set sender to mw@FreeBSD.org using -f From: Marcin Wojtas Date: Tue, 26 May 2020 14:16:26 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r361507 - head/sys/netipsec X-SVN-Group: head X-SVN-Commit-Author: mw X-SVN-Commit-Paths: head/sys/netipsec X-SVN-Commit-Revision: 361507 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 May 2020 14:16:27 -0000 Author: mw Date: Tue May 26 14:16:26 2020 New Revision: 361507 URL: https://svnweb.freebsd.org/changeset/base/361507 Log: 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 Reviewed by: jhb Obtained from: Semihalf Sponsored by: Stormshield Differential Revision: https://reviews.freebsd.org/D24999 Modified: head/sys/netipsec/xform_esp.c Modified: head/sys/netipsec/xform_esp.c ============================================================================== --- head/sys/netipsec/xform_esp.c Tue May 26 14:10:53 2020 (r361506) +++ head/sys/netipsec/xform_esp.c Tue May 26 14:16:26 2020 (r361507) @@ -80,6 +80,8 @@ #include 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, struc 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;