From nobody Thu Oct 19 18:36:45 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4SBGdn2Z5qz4xkf3; Thu, 19 Oct 2023 18:36:45 +0000 (UTC) (envelope-from git@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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4SBGdn1wWPz3VsF; Thu, 19 Oct 2023 18:36:45 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1697740605; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=BBVhHzfQ8BduRX5ZoRQAQZUGnh0AzoI7v2MC8oS7qdk=; b=MofE2VL7KfwqLpFON1y2XcCes46nGbP77/cfHhyrVZCA+JNMElEXoCfsN8wv1LYEFj0uwC 69nJu+d+vAirNYYjW2m6Vuu4ZY676IQ/GprJxPhoVABwQEkO91fTTznEOa/vx2awjBMUsv OO08+H8GyGRW7HuJuxeYq+aZ0TaGFYqaB60nJt+LaTOkiFxvg0yRehesMuLxJ+Go7rjS7N WgoO6pV9m3wAi9rPUhI681FXEBx1Fd4bbvGCZdImY3NWLassbdPMnd+UpWUioQo78YuHBZ luv3h9IGFxGlxw21+GnmyGOjzSUEIPUyk28F+QtkfC3DbuJxR6y4mHj3iEhibw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1697740605; a=rsa-sha256; cv=none; b=RXT5enLXDxxpov08+d8d2IWHQ/HrpYAs/MMSe5+jPKtxbez1b3bugB5zEVH5kL/J3wbHQt PqsAvqYfXWzVSsnhpBUsg5oe0lRPMesOMf9w/euuzQhYghxoY+GnJJrApJP+FtjVxWsOyH TP+kB9Y4dzZM661JQz2EqFP1JznMVSKmBiLRRfRqdQXtKDiCng6VbeGEXTAg4qjlud2AZ4 JBWAy83zIkZ+/VzpOUKXvUJvnd+jWdiYtayuCk/lZKow3KRH4KcZEy8P+B9AWx9FiAzB/o hdsFCXkKQl27xiQXaph3Y1n9oWZVLuxlcJUjgwmg0tCXAEbLSm4ezBO9B51etQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1697740605; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=BBVhHzfQ8BduRX5ZoRQAQZUGnh0AzoI7v2MC8oS7qdk=; b=A8EjZLBjU5x1ESTUz3YMd90SkZSvOgT7KH46VmWyFUns23F8qwl9Yr3PTsGmynP5RUjBOD FWWysj4ZfFqpwiRcbjRuH/3uLH9WI7S/ZTbAQQxDMzz8a8ivperbOrKMG1dRQ+XeQbJy5Z +omwn4RmRMHHKOwvagX01zoJqDQo+w+PM4MvyAvSXd4C3wUPktWkF7g8EdZTTIQbeMzcRH wZcWOfzAy2lRHU1p+AEj3QpfJbaRLSNRl521uTEQU4h3cGUQkCgdr+44mHSZZzaOQbRyvF snmCEvKhiSwCzMcWjc6xq7vzqm4h3i0bvWEoVI26YPHIRxPXh+zXwI2XLFzbiQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4SBGdn0jQvz11bZ; Thu, 19 Oct 2023 18:36:45 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 39JIaj97094248; Thu, 19 Oct 2023 18:36:45 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 39JIajHo094245; Thu, 19 Oct 2023 18:36:45 GMT (envelope-from git) Date: Thu, 19 Oct 2023 18:36:45 GMT Message-Id: <202310191836.39JIajHo094245@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: 0fc28f22d5b6 - main - KTLS: Add using_ktls helper variable in ssl3_get_record(). List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 0fc28f22d5b6a75d8a0449262a05cefe1040f982 Auto-Submitted: auto-generated The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=0fc28f22d5b6a75d8a0449262a05cefe1040f982 commit 0fc28f22d5b6a75d8a0449262a05cefe1040f982 Author: John Baldwin AuthorDate: 2022-03-08 00:55:18 +0000 Commit: John Baldwin CommitDate: 2023-10-19 18:34:58 +0000 KTLS: Add using_ktls helper variable in ssl3_get_record(). When KTLS receive is enabled, pending data may still be present due to read ahead. This data must still be processed the same as records received without KTLS. To ease readability (especially in consideration of additional checks which will be added for TLS 1.3), add a helper variable 'using_ktls' that is true when the KTLS receive path is being used to receive a record. Obtained from: OpenSSL commit 031132c297e54cbc20404a0bf8de6ed863196399 --- crypto/openssl/ssl/record/ssl3_record.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/crypto/openssl/ssl/record/ssl3_record.c b/crypto/openssl/ssl/record/ssl3_record.c index 3c0b1323a459..57915e1bd6e0 100644 --- a/crypto/openssl/ssl/record/ssl3_record.c +++ b/crypto/openssl/ssl/record/ssl3_record.c @@ -185,18 +185,23 @@ int ssl3_get_record(SSL *s) int imac_size; size_t num_recs = 0, max_recs, j; PACKET pkt, sslv2pkt; - int is_ktls_left; + int using_ktls; SSL_MAC_BUF *macbufs = NULL; int ret = -1; rr = RECORD_LAYER_get_rrec(&s->rlayer); rbuf = RECORD_LAYER_get_rbuf(&s->rlayer); - is_ktls_left = (SSL3_BUFFER_get_left(rbuf) > 0); max_recs = s->max_pipelines; if (max_recs == 0) max_recs = 1; sess = s->session; + /* + * KTLS reads full records. If there is any data left, + * then it is from before enabling ktls. + */ + using_ktls = BIO_get_ktls_recv(s->rbio) && SSL3_BUFFER_get_left(rbuf) == 0; + do { thisrr = &rr[num_recs]; @@ -409,7 +414,7 @@ int ssl3_get_record(SSL *s) #endif /* KTLS may use all of the buffer */ - if (BIO_get_ktls_recv(s->rbio) && !is_ktls_left) + if (using_ktls) len = SSL3_BUFFER_get_left(rbuf); if (thisrr->length > len) { @@ -518,11 +523,7 @@ int ssl3_get_record(SSL *s) return 1; } - /* - * KTLS reads full records. If there is any data left, - * then it is from before enabling ktls - */ - if (BIO_get_ktls_recv(s->rbio) && !is_ktls_left) + if (using_ktls) goto skip_decryption; if (s->read_hash != NULL) { @@ -734,8 +735,7 @@ int ssl3_get_record(SSL *s) * Therefore we have to rely on KTLS to check the plaintext length * limit in the kernel. */ - if (thisrr->length > SSL3_RT_MAX_PLAIN_LENGTH - && (!BIO_get_ktls_recv(s->rbio) || is_ktls_left)) { + if (thisrr->length > SSL3_RT_MAX_PLAIN_LENGTH && !using_ktls) { SSLfatal(s, SSL_AD_RECORD_OVERFLOW, SSL_R_DATA_LENGTH_TOO_LONG); goto end; }