From owner-svn-src-all@freebsd.org Sat May 2 01:00:30 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 7AA932B5E4E; Sat, 2 May 2020 01:00:30 +0000 (UTC) (envelope-from jhb@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) server-signature RSA-PSS (4096 bits) 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 49DW4t2hBzz4M4C; Sat, 2 May 2020 01:00:30 +0000 (UTC) (envelope-from jhb@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 574C6192D6; Sat, 2 May 2020 01:00:30 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 04210UFk026242; Sat, 2 May 2020 01:00:30 GMT (envelope-from jhb@FreeBSD.org) Received: (from jhb@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 04210Tgm026239; Sat, 2 May 2020 01:00:29 GMT (envelope-from jhb@FreeBSD.org) Message-Id: <202005020100.04210Tgm026239@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jhb set sender to jhb@FreeBSD.org using -f From: John Baldwin Date: Sat, 2 May 2020 01:00:29 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r360560 - head/sys/netipsec X-SVN-Group: head X-SVN-Commit-Author: jhb X-SVN-Commit-Paths: head/sys/netipsec X-SVN-Commit-Revision: 360560 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.29 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: Sat, 02 May 2020 01:00:30 -0000 Author: jhb Date: Sat May 2 01:00:29 2020 New Revision: 360560 URL: https://svnweb.freebsd.org/changeset/base/360560 Log: Don't pass bogus keys down for NULL algorithms. The changes in r359374 added various sanity checks in sessions and requests created by crypto consumers in part to permit backend drivers to make assumptions instead of duplicating checks for various edge cases. One of the new checks was to reject sessions which provide a pointer to a key while claiming the key is zero bits long. IPsec ESP tripped over this as it passes along whatever key is provided for NULL, including a pointer to a zero-length key when an empty string ("") is used with setkey(8). One option would be to teach the IPsec key layer to not allocate keys of zero length, but I went with a simpler fix of just not passing any keys down and always using a key length of zero for NULL algorithms. PR: 245832 Reported by: CI Modified: head/sys/netipsec/xform_ah.c head/sys/netipsec/xform_esp.c Modified: head/sys/netipsec/xform_ah.c ============================================================================== --- head/sys/netipsec/xform_ah.c Sat May 2 00:10:25 2020 (r360559) +++ head/sys/netipsec/xform_ah.c Sat May 2 01:00:29 2020 (r360560) @@ -215,8 +215,10 @@ ah_init0(struct secasvar *sav, struct xformsw *xsp, /* Initialize crypto session. */ csp->csp_auth_alg = sav->tdb_authalgxform->type; - csp->csp_auth_klen = _KEYBITS(sav->key_auth) / 8; - csp->csp_auth_key = sav->key_auth->key_data; + if (csp->csp_auth_alg != CRYPTO_NULL_HMAC) { + csp->csp_auth_klen = _KEYBITS(sav->key_auth) / 8; + csp->csp_auth_key = sav->key_auth->key_data; + }; csp->csp_auth_mlen = AUTHSIZE(sav); return 0; Modified: head/sys/netipsec/xform_esp.c ============================================================================== --- head/sys/netipsec/xform_esp.c Sat May 2 00:10:25 2020 (r360559) +++ head/sys/netipsec/xform_esp.c Sat May 2 01:00:29 2020 (r360560) @@ -220,9 +220,11 @@ esp_init(struct secasvar *sav, struct xformsw *xsp) /* Initialize crypto session. */ csp.csp_cipher_alg = sav->tdb_encalgxform->type; - csp.csp_cipher_key = sav->key_enc->key_data; - csp.csp_cipher_klen = _KEYBITS(sav->key_enc) / 8 - - SAV_ISCTRORGCM(sav) * 4; + if (csp.csp_cipher_alg != CRYPTO_NULL_CBC) { + csp.csp_cipher_key = sav->key_enc->key_data; + csp.csp_cipher_klen = _KEYBITS(sav->key_enc) / 8 - + SAV_ISCTRORGCM(sav) * 4; + }; csp.csp_ivlen = txform->ivsize; error = crypto_newsession(&sav->tdb_cryptoid, &csp, V_crypto_support);