From patchwork Tue Jul 23 04:34:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lev Stipakov X-Patchwork-Id: 785 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director11.mail.ord1d.rsapps.net ([172.31.255.6]) by backend30.mail.ord1d.rsapps.net with LMTP id sPYaIFYbN13HRAAAIUCqbw for ; Tue, 23 Jul 2019 10:36:06 -0400 Received: from proxy16.mail.iad3b.rsapps.net ([172.31.255.6]) by director11.mail.ord1d.rsapps.net with LMTP id 0NHXHFYbN10ySgAAvGGmqA ; Tue, 23 Jul 2019 10:36:06 -0400 Received: from smtp36.gate.iad3b ([172.31.255.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy16.mail.iad3b.rsapps.net with LMTP id sEyiFVYbN12RGAAAPj+4aA ; Tue, 23 Jul 2019 10:36:06 -0400 X-Spam-Threshold: 95 X-Spam-Score: 0 X-Spam-Flag: NO X-Virus-Scanned: OK X-Orig-To: openvpnslackdevel@openvpn.net X-Originating-Ip: [216.105.38.7] Authentication-Results: smtp36.gate.iad3b.rsapps.net; iprev=pass policy.iprev="216.105.38.7"; spf=pass smtp.mailfrom="openvpn-devel-bounces@lists.sourceforge.net" smtp.helo="lists.sourceforge.net"; dkim=fail (signature verification failed) header.d=sourceforge.net; dkim=fail (signature verification failed) header.d=sf.net; dkim=fail (signature verification failed) header.d=gmail.com; dmarc=fail (p=none; dis=none) header.from=gmail.com X-Suspicious-Flag: YES X-Classification-ID: 33ca040e-ad57-11e9-bade-5254003a7283-1-1 Received: from [216.105.38.7] ([216.105.38.7:45012] helo=lists.sourceforge.net) by smtp36.gate.iad3b.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 66/DB-15498-55B173D5; Tue, 23 Jul 2019 10:36:06 -0400 Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1hpvsk-0005sU-Sk; Tue, 23 Jul 2019 14:35:10 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1hpvsj-0005sL-FZ for openvpn-devel@lists.sourceforge.net; Tue, 23 Jul 2019 14:35:09 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=References:In-Reply-To:Message-Id:Date:Subject:To: From:Sender:Reply-To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=iYzi9u2a2oZ0Rg2uWOlV+HJx7/9tTknSiX2sinQPkbY=; b=iOpl3SmypXwtrsWZmMMVxS45oO 8ViJvELB3BL6eMvarDX1B00bMI55CBkZzfLbwyL/FWL3EL2PHZ+g22n9lCxWpBmyOrOSv15HNNLhJ qgDtjqF/aYJ92nkXFdMZg9VMTgimRyK7s9vrO7tsQzYDzZiF8kc+iG2doCs53NvigPLg=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=References:In-Reply-To:Message-Id:Date:Subject:To:From:Sender:Reply-To:Cc :MIME-Version:Content-Type:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=iYzi9u2a2oZ0Rg2uWOlV+HJx7/9tTknSiX2sinQPkbY=; b=dtcC9cqPS7ijMXeGt7XwCE4Oba 9Up36o9lUuJMWyGUhMLXYTJOHZRw+DtJL23YzCe43kbv/moe88cvR0+6sT6Sd214OMoeShxWosarw pEAbxdRCm6WarIDd+5apG43JwZfVfuxr4expKMm/UcCzKbO5VPv0PzMtcs3TzU6bZmcY=; Received: from mail-ed1-f66.google.com ([209.85.208.66]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.90_1) id 1hpvsh-00EZIM-Tc for openvpn-devel@lists.sourceforge.net; Tue, 23 Jul 2019 14:35:09 +0000 Received: by mail-ed1-f66.google.com with SMTP id x19so38241598eda.12 for ; Tue, 23 Jul 2019 07:35:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=iYzi9u2a2oZ0Rg2uWOlV+HJx7/9tTknSiX2sinQPkbY=; b=Q+gSogqKJxbXk5/4ZQmbJO1Xj+lVsG/4x72GbbqLJ+sSsQfA7mNmCYVj4tAbkGDg5H 84MNv32qQD5qvEAl49BNI5cDAKx33PtLZjF0IQzgOFDjTOESozQVAZs1advtdyhuwF9b xOU/ge2JwrOYSoa4PonBzHV/b1FEFwA78iydTO2FKV9Ta73xixhqbG4T2lEH+lXt5CjB jMaZyHyLsr6RTPELEnvLAhORbbUPASi8+0o9veDdTQxmvtg8oVYslx3OhrI/D0zTeoaj 89aL+cMV2s0xxNhfczcKJpc+re0+CkNc5wt+cU5AbAjAYDh2p0S4OH2cKvH4wSIono+b vSLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=iYzi9u2a2oZ0Rg2uWOlV+HJx7/9tTknSiX2sinQPkbY=; b=U8WqjKtntn4gbzzzxp+pHfWynAe1y29EKVfdFDUa/T8JAVckUFKLGkR75otuAvkKQn uZcE8su7f3PizpIA72OjpI2jk8bTu0a58Os/GCdMIbr8hutjkEi1bDJ7VpWYax+Yq975 Cq56eozz1xuhkqSJazDlV3uVKlfAuvnJjUkl4sTR1FwMAdLoLqZjOSEM5R1fQFrRw5ah 6zBK4wiZ8GlhjVoxyHy9sn4wDbMGh60DCk+z1KZlYlsg+Xi/g3pmBQrY3kz9mLBByGIB 9VyOi4LS3gGkN4EwC97EVg0wsjouT2mmfSTVIzmQXFrSiQ+EYC+/tqR8yM/swco5FoTX m1Ow== X-Gm-Message-State: APjAAAU8bEHh64XWhGLZV05tMA+bx9IRJnz903qnw6oSqpjNAY8nxZxL ho6bqvL/IxqIXAjA9rZi1/VbkQtfH5ks+TUW X-Google-Smtp-Source: APXvYqwGhpSKwrTyYxQRCdCwqy4FXWDFzl0VJ5Hr7q+Aj0QxxG9zSSX6DuWr4u4zEUocKwVpUKB8lA== X-Received: by 2002:a50:8ba6:: with SMTP id m35mr66164140edm.199.1563892500948; Tue, 23 Jul 2019 07:35:00 -0700 (PDT) Received: from stipakov.fi (stipakov.fi. [128.199.52.117]) by smtp.gmail.com with ESMTPSA id c15sm8751631ejs.17.2019.07.23.07.34.59 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 23 Jul 2019 07:34:59 -0700 (PDT) From: Lev Stipakov To: openvpn-devel@lists.sourceforge.net Date: Tue, 23 Jul 2019 17:34:47 +0300 Message-Id: <1563892487-12063-1-git-send-email-lstipakov@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <201907221844.x6MIiHtw009666@chekov.greenie.muc.de> References: <201907221844.x6MIiHtw009666@chekov.greenie.muc.de> X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [209.85.208.66 listed in list.dnswl.org] 0.0 URIBL_BLOCKED ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [URIs: openvpn.net] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (lstipakov[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-Headers-End: 1hpvsh-00EZIM-Tc Subject: [Openvpn-devel] [PATCH v2 release/2.4] Fix broken fragment/mssfix with NCP X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox From: Lev Stipakov This is the 2.4 backport of master patch (commit d22ba6b). NCP negotiation replaces worst cast crypto overhead with actual one in data channel frame. That frame params are used by mssfix. Fragment frame still contains worst case overhead. Because of that TCP packets are fragmented, since MSS value exceeds max fragment size. Fix by replacing worst case crypto overhead with actual one for fragment frame, as it is done for data channel frame. Trac #1140 Signed-off-by: Lev Stipakov --- v2: fix --disable-fragment build src/openvpn/forward.c | 3 +++ src/openvpn/init.c | 12 +++++++++++- src/openvpn/openvpn.h | 1 + src/openvpn/push.c | 9 ++++++++- src/openvpn/ssl.c | 19 ++++++++++++++++++- src/openvpn/ssl.h | 13 ++++++++----- 6 files changed, 49 insertions(+), 8 deletions(-) diff --git a/src/openvpn/forward.c b/src/openvpn/forward.c index 65f790f..84bb584 100644 --- a/src/openvpn/forward.c +++ b/src/openvpn/forward.c @@ -873,6 +873,9 @@ process_incoming_link_part1(struct context *c, struct link_socket_info *lsi, boo if (is_hard_reset(opcode, c->options.key_method)) { c->c2.frame = c->c2.frame_initial; +#ifdef ENABLE_FRAGMENT + c->c2.frame_fragment = c->c2.frame_fragment_initial; +#endif } interval_action(&c->c2.tmp_int); diff --git a/src/openvpn/init.c b/src/openvpn/init.c index d3785ca..37b832a 100644 --- a/src/openvpn/init.c +++ b/src/openvpn/init.c @@ -2294,9 +2294,18 @@ do_deferred_options(struct context *c, const unsigned int found) { tls_poor_mans_ncp(&c->options, c->c2.tls_multi->remote_ciphername); } + struct frame *frame_fragment = NULL; +#ifdef ENABLE_FRAGMENT + if (c->options.ce.fragment) + { + frame_fragment = &c->c2.frame_fragment; + } +#endif + /* Do not regenerate keys if server sends an extra push reply */ if (!session->key[KS_PRIMARY].crypto_options.key_ctx_bi.initialized - && !tls_session_update_crypto_params(session, &c->options, &c->c2.frame)) + && !tls_session_update_crypto_params(session, &c->options, &c->c2.frame, + frame_fragment)) { msg(D_TLS_ERRORS, "OPTIONS ERROR: failed to import crypto options"); return false; @@ -3035,6 +3044,7 @@ do_init_frame(struct context *c) */ c->c2.frame_fragment = c->c2.frame; frame_subtract_extra(&c->c2.frame_fragment, &c->c2.frame_fragment_omit); + c->c2.frame_fragment_initial = c->c2.frame_fragment; #endif #if defined(ENABLE_FRAGMENT) && defined(ENABLE_OCC) diff --git a/src/openvpn/openvpn.h b/src/openvpn/openvpn.h index 7736183..ed7975c 100644 --- a/src/openvpn/openvpn.h +++ b/src/openvpn/openvpn.h @@ -269,6 +269,7 @@ struct context_2 /* Object to handle advanced MTU negotiation and datagram fragmentation */ struct fragment_master *fragment; struct frame frame_fragment; + struct frame frame_fragment_initial; struct frame frame_fragment_omit; #endif diff --git a/src/openvpn/push.c b/src/openvpn/push.c index dd5bd41..ba2fbe4 100644 --- a/src/openvpn/push.c +++ b/src/openvpn/push.c @@ -287,11 +287,18 @@ incoming_push_message(struct context *c, const struct buffer *buffer) { if (c->options.mode == MODE_SERVER) { + struct frame *frame_fragment = NULL; +#ifdef ENABLE_FRAGMENT + if (c->options.ce.fragment) + { + frame_fragment = &c->c2.frame_fragment; + } +#endif struct tls_session *session = &c->c2.tls_multi->session[TM_ACTIVE]; /* Do not regenerate keys if client send a second push request */ if (!session->key[KS_PRIMARY].crypto_options.key_ctx_bi.initialized && !tls_session_update_crypto_params(session, &c->options, - &c->c2.frame)) + &c->c2.frame, frame_fragment)) { msg(D_TLS_ERRORS, "TLS Error: initializing data channel failed"); goto error; diff --git a/src/openvpn/ssl.c b/src/openvpn/ssl.c index 9696e9b..7dcd962 100644 --- a/src/openvpn/ssl.c +++ b/src/openvpn/ssl.c @@ -1962,7 +1962,8 @@ cleanup: bool tls_session_update_crypto_params(struct tls_session *session, - struct options *options, struct frame *frame) + struct options *options, struct frame *frame, + struct frame *frame_fragment) { if (!session->opt->server && 0 != strcmp(options->ciphername, session->opt->config_ciphername) @@ -2006,6 +2007,22 @@ tls_session_update_crypto_params(struct tls_session *session, frame_init_mssfix(frame, options); frame_print(frame, D_MTU_INFO, "Data Channel MTU parms"); + /* + * mssfix uses data channel framing, which at this point contains + * actual overhead. Fragmentation logic uses frame_fragment, which + * still contains worst case overhead. Replace it with actual overhead + * to prevent unneeded fragmentation. + */ + + if (frame_fragment) + { + frame_remove_from_extra_frame(frame_fragment, crypto_max_overhead()); + crypto_adjust_frame_parameters(frame_fragment, &session->opt->key_type, + options->use_iv, options->replay, packet_id_long_form); + frame_set_mtu_dynamic(frame_fragment, options->ce.fragment, SET_MTU_UPPER_BOUND); + frame_print(frame_fragment, D_MTU_INFO, "Fragmentation MTU parms"); + } + return tls_session_generate_data_channel_keys(session); } diff --git a/src/openvpn/ssl.h b/src/openvpn/ssl.h index 8066789..6672d43 100644 --- a/src/openvpn/ssl.h +++ b/src/openvpn/ssl.h @@ -475,15 +475,18 @@ void tls_update_remote_addr(struct tls_multi *multi, * Update TLS session crypto parameters (cipher and auth) and derive data * channel keys based on the supplied options. * - * @param session The TLS session to update. - * @param options The options to use when updating session. - * @param frame The frame options for this session (frame overhead is - * adjusted based on the selected cipher/auth). + * @param session The TLS session to update. + * @param options The options to use when updating session. + * @param frame The frame options for this session (frame overhead is + * adjusted based on the selected cipher/auth). + * @param frame_fragment The fragment frame options. * * @return true if updating succeeded, false otherwise. */ bool tls_session_update_crypto_params(struct tls_session *session, - struct options *options, struct frame *frame); + struct options *options, + struct frame *frame, + struct frame *frame_fragment); /** * "Poor man's NCP": Use peer cipher if it is an allowed (NCP) cipher.