Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp246100imj; Thu, 7 Feb 2019 03:44:57 -0800 (PST) X-Google-Smtp-Source: AHgI3IaLcE1rMTsrckA51v1crRAhQKyXE+s75aSm2VdoqvA6dg290eIxMWiFVaGlvLQTR3l91s/m X-Received: by 2002:a63:f006:: with SMTP id k6mr14363297pgh.259.1549539897082; Thu, 07 Feb 2019 03:44:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549539897; cv=none; d=google.com; s=arc-20160816; b=XISTJcksA5V1W0o2nWH3s+++jvunk7NWUzUVJ+lWFU0e+L4bCiNT7/QlDpjJMBHKkd wA8E/491+O32Vhf32s1a0v+O6uQPTGve4XYhOKs6chCI67shNI6MsFjsgvD1UcTumfqU vm7doGLpOCs0gNc8i8lA6/a+ZgRwKnAQHZbEQh0eNPkLAIB0/doRX4QZ8rp7AJaBI+N8 422ItomCHTSUr+kiXcr58vxt/+sAt9IvgNXJbGk7gD7wlCj/f3RCAbsH8ir9hN5O0zop Y2EzIPNttaBtX7IPMalc7a6gRHmwBdZvNVmEK0tXepqPnAexrFATuF49VCfSGpIxONaV r0mA== 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=sL0/6DK4OiyRUmrTu4o6t4bFLhqI22IUkOhouDcmcKQ=; b=wprVcLVta/u8XcGmjo7RhpGGKVO1gKcwKguo4e2TXZvZvnEQ70m5V5YS/QQE39wegw C9RRisxdMiSvvh7IkuPrFm6/APUvx+fghvPlpz+wtCdp17fdJllbqmQ5qWKV9FJSdaso Pfupt355FAV3nPD4sm6VWnSJYmiuZ0q378WCnghdmcPd0Cw1oKmveLhS0xt3kMHcswyb dPIlcDH/Ny/455g3KTlaXP1RnsIV8vdBCU6L1K3ZtkU03Iy5vv0XBLqYOryf8oO1j3NB 4LIqhH/eyPonULr2NDI5mRw348K4RNP/ODSFWKt4yU74qgwyzv+vT/Pra+oMzjwsS2Is 17Ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=L7vkpUcI; 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 n125si7206898pga.179.2019.02.07.03.44.41; Thu, 07 Feb 2019 03:44:57 -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=L7vkpUcI; 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 S1727070AbfBGLoG (ORCPT + 99 others); Thu, 7 Feb 2019 06:44:06 -0500 Received: from mail.kernel.org ([198.145.29.99]:34608 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727662AbfBGLoD (ORCPT ); Thu, 7 Feb 2019 06:44:03 -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 C98FD2080A; Thu, 7 Feb 2019 11:44:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549539842; bh=1q6ACRP4drC5sRnQIE1+3l8VTZnWbOW28my+CDcCFCs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L7vkpUcInwf71H/lFFJmXbcjEIcz+VzsoYXRr0lREzt0iI+2Ww6E4JYKQ4NHtxxLz +93kxcA68xcJNXu/ftr36Et5ZeYZ9mnTQGjGiiPMzxMbqzo+U2CiPRkUrRKPqt4eui 6H/s9R4+CaIyKALM+pj7Jt1ABURXki/H7qailgWY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Michal Kubecek , "David S. Miller" , Mao Wenan , Ben Hutchings Subject: [PATCH 4.4 33/34] net: ipv4: do not handle duplicate fragments as overlapping Date: Thu, 7 Feb 2019 12:42:15 +0100 Message-Id: <20190207113026.832381171@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190207113025.552605181@linuxfoundation.org> References: <20190207113025.552605181@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.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Michal Kubecek commit ade446403bfb79d3528d56071a84b15351a139ad upstream. 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: Mao Wenan [bwh: Backported to 4.4: - goto discard_qp, not err, in case of overlap - Set err earlier variable, as done upstream in commit 0ff89efb5246 "ip: fail fast on IP defrag errors"] Signed-off-by: Ben Hutchings Signed-off-by: Greg Kroah-Hartman --- net/ipv4/ip_fragment.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 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,9 +420,12 @@ 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. */ + err = -EINVAL; /* Find out where to put this fragment. */ prev_tail = qp->q.fragments_tail; if (!prev_tail) @@ -444,13 +447,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. @@ -495,7 +502,6 @@ static int ip_frag_queue(struct ipq *qp, discard_qp: inet_frag_kill(&qp->q); - err = -EINVAL; IP_INC_STATS_BH(net, IPSTATS_MIB_REASM_OVERLAPS); err: kfree_skb(skb);