Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3719913imu; Mon, 7 Jan 2019 08:15:45 -0800 (PST) X-Google-Smtp-Source: ALg8bN5vMP6NCC6YPDKaVPqRkOW6VqU+tcfQBCpyr74ywAnLgwqL8Zl8P3A9XublFNEt3MmkmvX8 X-Received: by 2002:a63:d818:: with SMTP id b24mr29881476pgh.174.1546877745027; Mon, 07 Jan 2019 08:15:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546877744; cv=none; d=google.com; s=arc-20160816; b=otBT/Xs2wvry71wn8jCO4Q0UtRbKcFnorSHsrYdrY4HofUAWHB6Pc92GfFV6ei+PhX 34RDbRe3Gsh53NyqAjtGfrn4r/J8LVARadL9gitlkA7SCHgsktXvBKjmGo1dz9TAUZtT S9wXXi7cCPntMR00fC5NA8kBSuApbgtBdvjp7tIQMNFdBQ8uoLPj8wwiNDZMG2b4kHxn wK55fIQXxdnugbFDXhRiSsgWDwVSp8ozbSNIGAAooHd9ATUxLf2iLgKJCniOlVe3LoxT 1nmtUfKVwCM57gcJ4+c7nX9yGSCkSrfbR2nV2oRbBaweVBNW6KO+vWYZ9s3OMrtYk2qY iz4w== 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=gkio4n2UkgGa8drhfycROVm5I7uCt3xuw9s64AiW9zY=; b=J4TnhgzPT/emWdpVw5iDtZph8D2PlaG1KAio9waJHicWDt1Saj/3TVOfymPYY40d4q Qxvndgv/2JfvJZrUjZT8Or7Iw4Mu6ekw/rCeedhZ+VgcU4JOYx6i5fGgJiGH0SgMGRMN yjk5fnW0F7IUeivgZUjKUyahAgrbWgXxDkuQts1finjijbmZo8hituITniP0+OzG+uGv tNa/Uew/leqRZTH2hUem58DllrZsfSSgJIxJKxXjiPuwyZlh5Uxbvi+6RXEVUDxoqEDD oeDybLD3N4G5iNfXT23BwV5+xGZwXgxUQP5X1hXkAMODRyEP2UKLT9jiN5GzET9AlR+2 2/tQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ciBabHEE; 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 q64si4347887pga.280.2019.01.07.08.15.29; Mon, 07 Jan 2019 08:15:44 -0800 (PST) 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=ciBabHEE; 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 S1730358AbfAGM76 (ORCPT + 99 others); Mon, 7 Jan 2019 07:59:58 -0500 Received: from mail.kernel.org ([198.145.29.99]:47470 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727866AbfAGM75 (ORCPT ); Mon, 7 Jan 2019 07:59:57 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (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 177B321736; Mon, 7 Jan 2019 12:59:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1546865995; bh=/SRndYlewk0Zym3L2jlb3BvYPJcha42of4ak9Xsg7q4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ciBabHEE8qg2gqK+Wor+DK2kSmEHJ8qGG+HNSu2AwlYhUA+Ol5EPgOS66lti6t2iA CXETWYFyu5W4aksiMwxDiJ9EbOU0bmvqHJBA9QRWZrnmr/jSC1iwTIcJISd+sBwnCU gtFg3RAjMenD6wIzArPrNF+B7KNFa7av15lfrMx4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Michal Kubecek , "David S. Miller" Subject: [PATCH 4.14 012/101] net: ipv4: do not handle duplicate fragments as overlapping Date: Mon, 7 Jan 2019 13:32:00 +0100 Message-Id: <20190107105331.690671354@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190107105330.372621917@linuxfoundation.org> References: <20190107105330.372621917@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Michal Kubecek [ Upstream commit ade446403bfb79d3528d56071a84b15351a139ad ] Since commit 7969e5c40dfd ("ip: discard IPv4 datagrams with overlapping segments.") IPv4 reassembly code drops the whole queue whenever an overlapping fragment is received. However, the test is written in a way which detects duplicate fragments as overlapping so that in environments with many duplicate packets, fragmented packets may be undeliverable. Add an extra test and for (potentially) duplicate fragment, only drop the new fragment rather than the whole queue. Only starting offset and length are checked, not the contents of the fragments as that would be too expensive. For similar reason, linear list ("run") of a rbtree node is not iterated, we only check if the new fragment is a subset of the interval covered by existing consecutive fragments. v2: instead of an exact check iterating through linear list of an rbtree node, only check if the new fragment is subset of the "run" (suggested by Eric Dumazet) Fixes: 7969e5c40dfd ("ip: discard IPv4 datagrams with overlapping segments.") Signed-off-by: Michal Kubecek Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/ipv4/ip_fragment.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) --- a/net/ipv4/ip_fragment.c +++ b/net/ipv4/ip_fragment.c @@ -347,10 +347,10 @@ static int ip_frag_queue(struct ipq *qp, struct net *net = container_of(qp->q.net, struct net, ipv4.frags); struct rb_node **rbn, *parent; struct sk_buff *skb1, *prev_tail; + int ihl, end, skb1_run_end; struct net_device *dev; unsigned int fragsize; int flags, offset; - int ihl, end; int err = -ENOENT; u8 ecn; @@ -420,7 +420,9 @@ static int ip_frag_queue(struct ipq *qp, * overlapping fragment, the entire datagram (and any constituent * fragments) MUST be silently discarded. * - * We do the same here for IPv4 (and increment an snmp counter). + * We do the same here for IPv4 (and increment an snmp counter) but + * we do not want to drop the whole queue in response to a duplicate + * fragment. */ /* Find out where to put this fragment. */ @@ -444,13 +446,17 @@ static int ip_frag_queue(struct ipq *qp, do { parent = *rbn; skb1 = rb_to_skb(parent); + skb1_run_end = skb1->ip_defrag_offset + + FRAG_CB(skb1)->frag_run_len; if (end <= skb1->ip_defrag_offset) rbn = &parent->rb_left; - else if (offset >= skb1->ip_defrag_offset + - FRAG_CB(skb1)->frag_run_len) + else if (offset >= skb1_run_end) rbn = &parent->rb_right; - else /* Found an overlap with skb1. */ - goto discard_qp; + else if (offset >= skb1->ip_defrag_offset && + end <= skb1_run_end) + goto err; /* No new data, potential duplicate */ + else + goto discard_qp; /* Found an overlap */ } while (*rbn); /* Here we have parent properly set, and rbn pointing to * one of its NULL left/right children. Insert skb.