Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp5899913imb; Fri, 8 Mar 2019 05:04:43 -0800 (PST) X-Google-Smtp-Source: APXvYqzxd9zEcvnTHC6r82VLN+QajxWtK6zllqnSH1lEjcqszQfqlgjCUjbv/xQpmo3JfR63A+cg X-Received: by 2002:a62:20d2:: with SMTP id m79mr18784075pfj.135.1552050283830; Fri, 08 Mar 2019 05:04:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1552050283; cv=none; d=google.com; s=arc-20160816; b=czGlr51rQMxJWiLjnEE/B3ojukRzpSakpBJ08fNWuV62iNLkhYU+3pwrwKyGhPa3LA VFhLsDUPJao/xe+E8ynUEHeLR1PpNWvl6uA9a+NTZDJBfm+pbpjfHaKgMii2sz9Kk89w SYe67doyyJbg5w66yuvCH3JwCUYYl88CCgvuoDLUpdFqhPyxWSoYHJHJs5UpF2dJnSHF qwUBu0lb1JaWc70XsVtUfvYzxr8ZASjPRCk11+E4j1MmXMaRNOz5qktIebaY5Vq9yoeU P+QsUawICvaG3YMlfEQCpgAEElJxQ6AkmVFqoF9kD5hR4zCR0esiVTDeLopNqSj4LUEU lqtQ== 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=YOgbgIQNWZH8q8Uh7wZqziDOlEJOdYa9hFonwjnBeS4=; b=SojWdRa+zIBnKFvikuF4+r3PIQej1NRITN6MaO6rkzTcPG7/Pu5QsMmgfWZgTHf+c7 ajf7gHeFSIgMzGaemr5ZLKgELrXSFmJBiHTjCesB8jSqXCBkSkiDV9Y1ztgd500Cn/rb LKIdj0m/dTH43woyD9Dp5EhrdbgM/ZY8N0N0cIY9Mgann/wJkKAuqasAmJ1KmsGFBvpp AzXUobT4s9qOJW3QNSCZKDsRuq6pWSCmhLrxN8uClj93Qkm4hrc1U83tKsUwWhntHnIN esCRvRq+wWAXhnBNxOHcmkc6yHsY6HhMQWzRWAO+imb0IxU3tvbOCbFKQ0QROj+lOXW8 WcMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jv5A3pnt; 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 f23si7567439pfa.228.2019.03.08.05.04.28; Fri, 08 Mar 2019 05:04:43 -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=jv5A3pnt; 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 S1727677AbfCHM66 (ORCPT + 99 others); Fri, 8 Mar 2019 07:58:58 -0500 Received: from mail.kernel.org ([198.145.29.99]:35436 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727695AbfCHM64 (ORCPT ); Fri, 8 Mar 2019 07:58:56 -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 288D020449; Fri, 8 Mar 2019 12:58:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1552049935; bh=37kohoiBdSfl+aM2obJsOx68F4S734vggYas1aE+two=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jv5A3pnt7Fn3nm4bQamtfbr/N+wj/npQNfT4DpIWO4c4bxIBZemKnqRR/iq/Fv3ts dBwKsroy55kie3LNgjM/RHcel1B+aSPRGhbngcGadrA7bZ45b/Now7SJI09fDpURsx D7BQZkkmeWITX8RAKE4KSSPsSvRMLaVkUdXIWkLE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sheng Lan , Qin Ji , Eric Dumazet , Eric Dumazet , "David S. Miller" Subject: [PATCH 4.19 31/68] net: netem: fix skb length BUG_ON in __skb_to_sgvec Date: Fri, 8 Mar 2019 13:50:01 +0100 Message-Id: <20190308124912.306051142@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190308124910.696595153@linuxfoundation.org> References: <20190308124910.696595153@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.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Sheng Lan [ Upstream commit 5845f706388a4cde0f6b80f9e5d33527e942b7d9 ] It can be reproduced by following steps: 1. virtio_net NIC is configured with gso/tso on 2. configure nginx as http server with an index file bigger than 1M bytes 3. use tc netem to produce duplicate packets and delay: tc qdisc add dev eth0 root netem delay 100ms 10ms 30% duplicate 90% 4. continually curl the nginx http server to get index file on client 5. BUG_ON is seen quickly [10258690.371129] kernel BUG at net/core/skbuff.c:4028! [10258690.371748] invalid opcode: 0000 [#1] SMP PTI [10258690.372094] CPU: 5 PID: 0 Comm: swapper/5 Tainted: G W 5.0.0-rc6 #2 [10258690.372094] RSP: 0018:ffffa05797b43da0 EFLAGS: 00010202 [10258690.372094] RBP: 00000000000005ea R08: 0000000000000000 R09: 00000000000005ea [10258690.372094] R10: ffffa0579334d800 R11: 00000000000002c0 R12: 0000000000000002 [10258690.372094] R13: 0000000000000000 R14: ffffa05793122900 R15: ffffa0578f7cb028 [10258690.372094] FS: 0000000000000000(0000) GS:ffffa05797b40000(0000) knlGS:0000000000000000 [10258690.372094] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [10258690.372094] CR2: 00007f1a6dc00868 CR3: 000000001000e000 CR4: 00000000000006e0 [10258690.372094] Call Trace: [10258690.372094] [10258690.372094] skb_to_sgvec+0x11/0x40 [10258690.372094] start_xmit+0x38c/0x520 [virtio_net] [10258690.372094] dev_hard_start_xmit+0x9b/0x200 [10258690.372094] sch_direct_xmit+0xff/0x260 [10258690.372094] __qdisc_run+0x15e/0x4e0 [10258690.372094] net_tx_action+0x137/0x210 [10258690.372094] __do_softirq+0xd6/0x2a9 [10258690.372094] irq_exit+0xde/0xf0 [10258690.372094] smp_apic_timer_interrupt+0x74/0x140 [10258690.372094] apic_timer_interrupt+0xf/0x20 [10258690.372094] In __skb_to_sgvec(), the skb->len is not equal to the sum of the skb's linear data size and nonlinear data size, thus BUG_ON triggered. Because the skb is cloned and a part of nonlinear data is split off. Duplicate packet is cloned in netem_enqueue() and may be delayed some time in qdisc. When qdisc len reached the limit and returns NET_XMIT_DROP, the skb will be retransmit later in write queue. the skb will be fragmented by tso_fragment(), the limit size that depends on cwnd and mss decrease, the skb's nonlinear data will be split off. The length of the skb cloned by netem will not be updated. When we use virtio_net NIC and invoke skb_to_sgvec(), the BUG_ON trigger. To fix it, netem returns NET_XMIT_SUCCESS to upper stack when it clones a duplicate packet. Fixes: 35d889d1 ("sch_netem: fix skb leak in netem_enqueue()") Signed-off-by: Sheng Lan Reported-by: Qin Ji Suggested-by: Eric Dumazet Signed-off-by: Eric Dumazet Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/sched/sch_netem.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) --- a/net/sched/sch_netem.c +++ b/net/sched/sch_netem.c @@ -440,6 +440,7 @@ static int netem_enqueue(struct sk_buff int nb = 0; int count = 1; int rc = NET_XMIT_SUCCESS; + int rc_drop = NET_XMIT_DROP; /* Do not fool qdisc_drop_all() */ skb->prev = NULL; @@ -479,6 +480,7 @@ static int netem_enqueue(struct sk_buff q->duplicate = 0; rootq->enqueue(skb2, rootq, to_free); q->duplicate = dupsave; + rc_drop = NET_XMIT_SUCCESS; } /* @@ -491,7 +493,7 @@ static int netem_enqueue(struct sk_buff if (skb_is_gso(skb)) { segs = netem_segment(skb, sch, to_free); if (!segs) - return NET_XMIT_DROP; + return rc_drop; } else { segs = skb; } @@ -514,8 +516,10 @@ static int netem_enqueue(struct sk_buff 1<<(prandom_u32() % 8); } - if (unlikely(sch->q.qlen >= sch->limit)) - return qdisc_drop_all(skb, sch, to_free); + if (unlikely(sch->q.qlen >= sch->limit)) { + qdisc_drop_all(skb, sch, to_free); + return rc_drop; + } qdisc_qstats_backlog_inc(sch, skb);