Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp2337041imm; Thu, 11 Oct 2018 08:43:27 -0700 (PDT) X-Google-Smtp-Source: ACcGV60I6vYkYeuMgoolmS3BfLCQzoyrAKDvkp78S3WnyVU/CzsyCZspXvM//K/6DX9SlgDlVTc+ X-Received: by 2002:a62:c4c5:: with SMTP id h66-v6mr2079297pfk.39.1539272607899; Thu, 11 Oct 2018 08:43:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539272607; cv=none; d=google.com; s=arc-20160816; b=gQP8GJgV19wfA9LMeF0n89l9OngCcE2dNNxklIQcTQObhfDm6Qi+AjpsDqQMIgRovC AdPEXRQTmyizvbpBghQNv+nsyJc+IkoMbbkiTnu1LAxVrcjw4XfBbPaVhGrM4JGJ8eBu xdcVgkklUZb1Y8895EDSG7MlV2gVluNcU759y1OTCxAwCjaH3xOd0IpzeSEPT23oHd+w ZDrQ/+ITPLfJOwJNAe0rgSQz5CzYTKPciNWaSbR7nLmq168V/BM3CmYc2GZ7cJc3n2SW KvMIBEDA/4ha1jgrUo5tB0Lo48Cw9b1pNoGpGtKUWkio9eyfe4rUMSH/g0h2b7Ps9g1S TO8w== 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:dkim-signature; bh=gEHSXl70rI4NSmwSafhJgb5gzgzOT7CTrlZrFjVF05g=; b=aUvWbDcxr2PdiXPlE5++KQysafRNOCPZfVZQsJoXJRfU82TCWmw8z3xVS6ROOAw/bB CjrCWXk0OrAiUMBDeok5gG1W8hOxsYP10WNpNBGmAUljHEmgcQiow11fRrS4/LMe8aa1 P6SubiwzH7JtAlVxnkCBzJCNa6jH6086Z4p03XJixkhAmj9dT/udOsmaV72MFKgb6m/M Wr+4q0smvDXw2yYJae1iOPd5+62pF7FzHRLvFT9wUZvUb87cPSf8GmjPDoQxB8D0h5Sl 9v98AQi3E6qc+Er6nUS/DouIcwrh0ONzaIDVo41PPIs9K0w7egC0TAf8T5MmsW37x9ZJ R7QQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="z/PEzuhE"; 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 q19-v6si3495631pll.286.2018.10.11.08.43.13; Thu, 11 Oct 2018 08:43:27 -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; dkim=pass header.i=@kernel.org header.s=default header.b="z/PEzuhE"; 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 S1730643AbeJKXJ5 (ORCPT + 99 others); Thu, 11 Oct 2018 19:09:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:41034 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726700AbeJKXJ5 (ORCPT ); Thu, 11 Oct 2018 19:09:57 -0400 Received: from localhost (ip-213-127-77-176.ip.prioritytelecom.net [213.127.77.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BAD5721470; Thu, 11 Oct 2018 15:42:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539272533; bh=rzTJfud4wUEy5a8X/WhD3pnzBtUIWo+yqx11yCzKM8s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=z/PEzuhEUmGstWSrT5QevLJl5efsZuxdjDRsxoaemenEbXDy8LFmAft9hGpaHg0PT JpTVFWxKJSCh3g5DCpB+Hm7t73QsD502dn9W7LhI/GT84L6B9Ybj2oxsLtgvVZbqRu /aQFHdUUv1xegTqk70iyIfT5n0J989uZAgB0C8xg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Dumazet , Yuchung Cheng , Yaogong Wang , "David S. Miller" , Mao Wenan Subject: [PATCH 4.4 22/27] tcp: fix a stale ooo_last_skb after a replace Date: Thu, 11 Oct 2018 17:35:09 +0200 Message-Id: <20181011152535.091804300@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181011152534.014964888@linuxfoundation.org> References: <20181011152534.014964888@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.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Eric Dumazet [ Upstream commit 76f0dcbb5ae1a7c3dbeec13dd98233b8e6b0b32a ] When skb replaces another one in ooo queue, I forgot to also update tp->ooo_last_skb as well, if the replaced skb was the last one in the queue. To fix this, we simply can re-use the code that runs after an insertion, trying to merge skbs at the right of current skb. This not only fixes the bug, but also remove all small skbs that might be a subset of the new one. Example: We receive segments 2001:3001, 4001:5001 Then we receive 2001:8001 : We should replace 2001:3001 with the big skb, but also remove 4001:50001 from the queue to save space. packetdrill test demonstrating the bug 0.000 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3 +0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0 +0 bind(3, ..., ...) = 0 +0 listen(3, 1) = 0 +0 < S 0:0(0) win 32792 +0 > S. 0:0(0) ack 1 +0.100 < . 1:1(0) ack 1 win 1024 +0 accept(3, ..., ...) = 4 +0.01 < . 1001:2001(1000) ack 1 win 1024 +0 > . 1:1(0) ack 1 +0.01 < . 1001:3001(2000) ack 1 win 1024 +0 > . 1:1(0) ack 1 Fixes: 9f5afeae5152 ("tcp: use an RB tree for ooo receive queue") Signed-off-by: Eric Dumazet Reported-by: Yuchung Cheng Cc: Yaogong Wang Signed-off-by: David S. Miller Signed-off-by: Mao Wenan Signed-off-by: Greg Kroah-Hartman --- net/ipv4/tcp_input.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -4465,7 +4465,7 @@ coalesce_done: NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPOFOMERGE); __kfree_skb(skb1); - goto add_sack; + goto merge_right; } } else if (tcp_try_coalesce(sk, skb1, skb, &fragstolen)) { goto coalesce_done; @@ -4477,6 +4477,7 @@ coalesce_done: rb_link_node(&skb->rbnode, parent, p); rb_insert_color(&skb->rbnode, &tp->out_of_order_queue); +merge_right: /* Remove other segments covered by skb. */ while ((q = rb_next(&skb->rbnode)) != NULL) { skb1 = rb_entry(q, struct sk_buff, rbnode);