Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp748052imm; Thu, 13 Sep 2018 07:11:23 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZRUAatJjgPJS/1KGysKRQcVtV6UboFkHwpHxUULitVMk+jSLSrQPPevWUpMFOua7MJCtkQ X-Received: by 2002:a62:cac5:: with SMTP id y66-v6mr7670772pfk.187.1536847883519; Thu, 13 Sep 2018 07:11:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536847883; cv=none; d=google.com; s=arc-20160816; b=lczeaARGcn48Ofb3O0NJrcif26c81Dj/aAv/IXOUTFhoT4VHf9F7KbUGYbDSLoHsHz 57UBMhsUei3QAUmjEtqqrCdh6DNTqjOJvHrkJQ9kPxD12Q5SE3tg67QSKf+w3S72sHW/ +uDL6RuDwfrt+M+UUBz5yDnGkQDW2AKPuGX0+/ajZcEGyoSVTC+aPEsJvb5vHRcNzYsh Gily2Rs+4H9plrDNGYPB22YQtgO1VEOyvP7X7qw9no02nXSQTcStI2EfLOB2qCFClFD0 oaPCkHZ/eLgog/lDk1Tskpw13PFqbszyCYCFxyONpPkZGE5/nhm53it4aTZmMvJ+kKo0 oDwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from; bh=ntEbZzq0bx6qD0lcDkLqJB7Lfsj3xakKjcj3YuTjPTY=; b=vX20GAtrYzs+UiTFzjokjyNqAVhl9RA06ZROpJUhtHqJCBBM7eMgizlcoVocenHKAK d6eRQBatJADlM9/Gkm68yecmlOlbyXdKxS+ssT52x8YWFlaImMNBt6FCkyAAAaNkmgFP MLupYa8sGjwd7fBhF07bfv+tfWi9zFVXoe1g67N9OyhY/4rn5Kcmg22ceZMRRmw3UnaG c/iCSTUYmEtYViyF8Vvju3G7G7It1wTi7/6eM8Joz17xlTwHOF22YixN/BiH2eh/KihK RtmhinrzYpZql/RIC3FiKgYsyy6/dmromniCZzxsB6shx9sHvyhLbDf7huHs1ucQuCDZ eNMA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v3-v6si4155201plp.85.2018.09.13.07.11.05; Thu, 13 Sep 2018 07:11:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729243AbeIMTUk (ORCPT + 99 others); Thu, 13 Sep 2018 15:20:40 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:33518 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730642AbeIMTCM (ORCPT ); Thu, 13 Sep 2018 15:02:12 -0400 Received: from localhost (ip-213-127-77-73.ip.prioritytelecom.net [213.127.77.73]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 236F2CE7; Thu, 13 Sep 2018 13:52:35 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Michal Tesar , Florian Westphal , Eric Dumazet , "David S. Miller" Subject: [PATCH 4.18 009/197] tcp: do not restart timewait timer on rst reception Date: Thu, 13 Sep 2018 15:29:18 +0200 Message-Id: <20180913131841.941076353@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180913131841.568116777@linuxfoundation.org> References: <20180913131841.568116777@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Florian Westphal [ Upstream commit 63cc357f7bba6729869565a12df08441a5995d9a ] RFC 1337 says: ''Ignore RST segments in TIME-WAIT state. If the 2 minute MSL is enforced, this fix avoids all three hazards.'' So with net.ipv4.tcp_rfc1337=1, expected behaviour is to have TIME-WAIT sk expire rather than removing it instantly when a reset is received. However, Linux will also re-start the TIME-WAIT timer. This causes connect to fail when tying to re-use ports or very long delays (until syn retry interval exceeds MSL). packetdrill test case: // Demonstrate bogus rearming of TIME-WAIT timer in rfc1337 mode. `sysctl net.ipv4.tcp_rfc1337=1` 0.000 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3 0.000 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0 0.000 bind(3, ..., ...) = 0 0.000 listen(3, 1) = 0 0.100 < S 0:0(0) win 29200 0.100 > S. 0:0(0) ack 1 0.200 < . 1:1(0) ack 1 win 257 0.200 accept(3, ..., ...) = 4 // Receive first segment 0.310 < P. 1:1001(1000) ack 1 win 46 // Send one ACK 0.310 > . 1:1(0) ack 1001 // read 1000 byte 0.310 read(4, ..., 1000) = 1000 // Application writes 100 bytes 0.350 write(4, ..., 100) = 100 0.350 > P. 1:101(100) ack 1001 // ACK 0.500 < . 1001:1001(0) ack 101 win 257 // close the connection 0.600 close(4) = 0 0.600 > F. 101:101(0) ack 1001 win 244 // Our side is in FIN_WAIT_1 & waits for ack to fin 0.7 < . 1001:1001(0) ack 102 win 244 // Our side is in FIN_WAIT_2 with no outstanding data. 0.8 < F. 1001:1001(0) ack 102 win 244 0.8 > . 102:102(0) ack 1002 win 244 // Our side is now in TIME_WAIT state, send ack for fin. 0.9 < F. 1002:1002(0) ack 102 win 244 0.9 > . 102:102(0) ack 1002 win 244 // Peer reopens with in-window SYN: 1.000 < S 1000:1000(0) win 9200 // Therefore, reply with ACK. 1.000 > . 102:102(0) ack 1002 win 244 // Peer sends RST for this ACK. Normally this RST results // in tw socket removal, but rfc1337=1 setting prevents this. 1.100 < R 1002:1002(0) win 244 // second syn. Due to rfc1337=1 expect another pure ACK. 31.0 < S 1000:1000(0) win 9200 31.0 > . 102:102(0) ack 1002 win 244 // .. and another RST from peer. 31.1 < R 1002:1002(0) win 244 31.2 `echo no timer restart;ss -m -e -a -i -n -t -o state TIME-WAIT` // third syn after one minute. Time-Wait socket should have expired by now. 63.0 < S 1000:1000(0) win 9200 // so we expect a syn-ack & 3whs to proceed from here on. 63.0 > S. 0:0(0) ack 1 Without this patch, 'ss' shows restarts of tw timer and last packet is thus just another pure ack, more than one minute later. This restores the original code from commit 283fd6cf0be690a83 ("Merge in ANK networking jumbo patch") in netdev-vger-cvs.git . For some reason the else branch was removed/lost in 1f28b683339f7 ("Merge in TCP/UDP optimizations and [..]") and timer restart became unconditional. Reported-by: Michal Tesar Signed-off-by: Florian Westphal Signed-off-by: Eric Dumazet Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/ipv4/tcp_minisocks.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/net/ipv4/tcp_minisocks.c +++ b/net/ipv4/tcp_minisocks.c @@ -184,8 +184,9 @@ kill: inet_twsk_deschedule_put(tw); return TCP_TW_SUCCESS; } + } else { + inet_twsk_reschedule(tw, TCP_TIMEWAIT_LEN); } - inet_twsk_reschedule(tw, TCP_TIMEWAIT_LEN); if (tmp_opt.saw_tstamp) { tcptw->tw_ts_recent = tmp_opt.rcv_tsval;