From owner-svn-src-all@freebsd.org Mon Apr 27 22:31:43 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 56F6E2C8AB4; Mon, 27 Apr 2020 22:31:43 +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 499zz31gzXz3JS4; Mon, 27 Apr 2020 22:31:43 +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 34EDC19E91; Mon, 27 Apr 2020 22:31:43 +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 03RMVhQJ028694; Mon, 27 Apr 2020 22:31:43 GMT (envelope-from jhb@FreeBSD.org) Received: (from jhb@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 03RMVgeR028690; Mon, 27 Apr 2020 22:31:42 GMT (envelope-from jhb@FreeBSD.org) Message-Id: <202004272231.03RMVgeR028690@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jhb set sender to jhb@FreeBSD.org using -f From: John Baldwin Date: Mon, 27 Apr 2020 22:31:42 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r360402 - in head/sys: kern netinet sys X-SVN-Group: head X-SVN-Commit-Author: jhb X-SVN-Commit-Paths: in head/sys: kern netinet sys X-SVN-Commit-Revision: 360402 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: Mon, 27 Apr 2020 22:31:43 -0000 Author: jhb Date: Mon Apr 27 22:31:42 2020 New Revision: 360402 URL: https://svnweb.freebsd.org/changeset/base/360402 Log: Add the initial sequence number to the TLS enable socket option. This will be needed for KTLS RX. Reviewed by: gallatin Sponsored by: Chelsio Communications Differential Revision: https://reviews.freebsd.org/D24451 Modified: head/sys/kern/uipc_ktls.c head/sys/netinet/tcp_usrreq.c head/sys/sys/ktls.h Modified: head/sys/kern/uipc_ktls.c ============================================================================== --- head/sys/kern/uipc_ktls.c Mon Apr 27 22:29:24 2020 (r360401) +++ head/sys/kern/uipc_ktls.c Mon Apr 27 22:31:42 2020 (r360402) @@ -957,6 +957,7 @@ ktls_enable_tx(struct socket *so, struct tls_enable *e } SOCKBUF_LOCK(&so->so_snd); + so->so_snd.sb_tls_seqno = be64dec(en->rec_seq); so->so_snd.sb_tls_info = tls; if (tls->mode != TCP_TLS_MODE_SW) so->so_snd.sb_flags |= SB_TLS_IFNET; Modified: head/sys/netinet/tcp_usrreq.c ============================================================================== --- head/sys/netinet/tcp_usrreq.c Mon Apr 27 22:29:24 2020 (r360401) +++ head/sys/netinet/tcp_usrreq.c Mon Apr 27 22:31:42 2020 (r360402) @@ -1823,6 +1823,37 @@ CTASSERT(TCP_CA_NAME_MAX <= TCP_LOG_ID_LEN); CTASSERT(TCP_LOG_REASON_LEN <= TCP_LOG_ID_LEN); #endif +#ifdef KERN_TLS +static int +copyin_tls_enable(struct sockopt *sopt, struct tls_enable *tls) +{ + struct tls_enable_v0 tls_v0; + int error; + + if (sopt->sopt_valsize == sizeof(tls_v0)) { + error = sooptcopyin(sopt, &tls_v0, sizeof(tls_v0), + sizeof(tls_v0)); + if (error) + return (error); + memset(tls, 0, sizeof(*tls)); + tls->cipher_key = tls_v0.cipher_key; + tls->iv = tls_v0.iv; + tls->auth_key = tls_v0.auth_key; + tls->cipher_algorithm = tls_v0.cipher_algorithm; + tls->cipher_key_len = tls_v0.cipher_key_len; + tls->iv_len = tls_v0.iv_len; + tls->auth_algorithm = tls_v0.auth_algorithm; + tls->auth_key_len = tls_v0.auth_key_len; + tls->flags = tls_v0.flags; + tls->tls_vmajor = tls_v0.tls_vmajor; + tls->tls_vminor = tls_v0.tls_vminor; + return (0); + } + + return (sooptcopyin(sopt, tls, sizeof(*tls), sizeof(*tls))); +} +#endif + int tcp_default_ctloutput(struct socket *so, struct sockopt *sopt, struct inpcb *inp, struct tcpcb *tp) { @@ -2034,8 +2065,7 @@ unlock_and_done: #ifdef KERN_TLS case TCP_TXTLS_ENABLE: INP_WUNLOCK(inp); - error = sooptcopyin(sopt, &tls, sizeof(tls), - sizeof(tls)); + error = copyin_tls_enable(sopt, &tls); if (error) break; error = ktls_enable_tx(so, &tls); Modified: head/sys/sys/ktls.h ============================================================================== --- head/sys/sys/ktls.h Mon Apr 27 22:29:24 2020 (r360401) +++ head/sys/sys/ktls.h Mon Apr 27 22:31:42 2020 (r360402) @@ -99,6 +99,22 @@ struct tls_mac_data { #define TLS_MINOR_VER_THREE 4 /* 3, 4 */ /* For TCP_TXTLS_ENABLE */ +#ifdef _KERNEL +struct tls_enable_v0 { + const uint8_t *cipher_key; + const uint8_t *iv; /* Implicit IV. */ + const uint8_t *auth_key; + int cipher_algorithm; /* e.g. CRYPTO_AES_CBC */ + int cipher_key_len; + int iv_len; + int auth_algorithm; /* e.g. CRYPTO_SHA2_256_HMAC */ + int auth_key_len; + int flags; + uint8_t tls_vmajor; + uint8_t tls_vminor; +}; +#endif + struct tls_enable { const uint8_t *cipher_key; const uint8_t *iv; /* Implicit IV. */ @@ -111,6 +127,7 @@ struct tls_enable { int flags; uint8_t tls_vmajor; uint8_t tls_vminor; + uint8_t rec_seq[8]; }; struct tls_session_params {