Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp481156ybl; Tue, 28 Jan 2020 06:37:38 -0800 (PST) X-Google-Smtp-Source: APXvYqyRnm5Evc1FW/SbwgwbeoHGAHkZM4IBXWzZxgCTv1VQTKKxkuG+JMPNz6A7WJ1Tn8vhe3xz X-Received: by 2002:aca:d787:: with SMTP id o129mr3047998oig.75.1580222257946; Tue, 28 Jan 2020 06:37:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580222257; cv=none; d=google.com; s=arc-20160816; b=zcTUYo3pAZYI5vGpN4vgCqWN1nFRcAa9x+B/2Z2wZPVMaHHrZRovYMZXcj84f3sEpM PQYwNrkW/00MobmB6AjA3txH0RTwYrDaSfWZ6aErIXhDFTGZP/OcSnZUNXZ/aBsqOH97 t9qVr9n9Fi+7olaY1Fv6hVxfLStMD4xLaJXMNvhwhkik3HS5Kh4kj1z5gkor2nKuPT/J Gg17R9G/+wesQMH6q21FUWlcvbWi4L67DLKEx3dzpafY7qleR03Qlw+diXK0tNxne6Uf abQi5Gwh9egG6SquPALvkBMHwiZ8+wP2Q5IggY+G5qDVYhR8eNiWo+rRcTh3FZXAnGz8 SL7Q== 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=uCp0+Tjgjzd8YV1PTwpBluhuMofco8/hJ4KPXN5Je60=; b=Rr0j3uTj+rAFp0Kx3Xr8sGJ3CJLNuThrfmqoOrkM9gyJAgwBvDbcHi220UsZCwByRb IV8oNtBsFm4Z4bTMt8UJ2UKK01U9bcaLY7/FI5qEXt7+0wYj7Y1AzkKxeAXWi8Q+xKrP 0aDbo+Zc8lVPTaBLT12xyGjoAEHLsuOU6U+nMiknJ4OKW36Iyyzt93A7HKkjkLZY0Pco k/jsAIVefYMrwnVh/0v9JcWYOk5t88rfQ+De2BduJueEluUIGITMSSNAKZssE9qoougI OYAN5V7EL+TG2wTcpaK/eHyEfksbUip1zhwyl9RHGxnO2pAzA8WJKd8SxOWwEvAqRPah b4rw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=m2NOmsR2; 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 i7si3121985oib.63.2020.01.28.06.37.25; Tue, 28 Jan 2020 06:37:37 -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=m2NOmsR2; 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 S1731309AbgA1OWk (ORCPT + 99 others); Tue, 28 Jan 2020 09:22:40 -0500 Received: from mail.kernel.org ([198.145.29.99]:48446 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731591AbgA1OWg (ORCPT ); Tue, 28 Jan 2020 09:22:36 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.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 A21DA24692; Tue, 28 Jan 2020 14:22:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1580221356; bh=lKuh8kUzrzC0Ya9d900qL0BQ9vCnuvjCKGEbQHkXQw0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m2NOmsR2W6dL+Rl6XkdHrEVaCaiygKMJyzhQcVUFq94Zd0hgJnbq5GXv9jQb74Xvb E2xFxfXVhx5RGae6mwvhoqKMmPmA3ylOCuhK8xw+NgshX/Tqd3NEwwlKzOBYAuCQ5c IXLl8oU8YQ5rChmqxe6SLqc5jvQTD4uQ1AvwuAms= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jakub Kicinski , Dirk van der Merwe , Cong Wang , "David S. Miller" , Sasha Levin Subject: [PATCH 4.9 155/271] net: netem: fix backlog accounting for corrupted GSO frames Date: Tue, 28 Jan 2020 15:05:04 +0100 Message-Id: <20200128135904.103779079@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200128135852.449088278@linuxfoundation.org> References: <20200128135852.449088278@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Jakub Kicinski [ Upstream commit 177b8007463c4f36c9a2c7ce7aa9875a4cad9bd5 ] When GSO frame has to be corrupted netem uses skb_gso_segment() to produce the list of frames, and re-enqueues the segments one by one. The backlog length has to be adjusted to account for new frames. The current calculation is incorrect, leading to wrong backlog lengths in the parent qdisc (both bytes and packets), and incorrect packet backlog count in netem itself. Parent backlog goes negative, netem's packet backlog counts all non-first segments twice (thus remaining non-zero even after qdisc is emptied). Move the variables used to count the adjustment into local scope to make 100% sure they aren't used at any stage in backports. Fixes: 6071bd1aa13e ("netem: Segment GSO packets on enqueue") Signed-off-by: Jakub Kicinski Reviewed-by: Dirk van der Merwe Acked-by: Cong Wang Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/sched/sch_netem.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/net/sched/sch_netem.c b/net/sched/sch_netem.c index 95002e56fa48b..308d92491757e 100644 --- a/net/sched/sch_netem.c +++ b/net/sched/sch_netem.c @@ -437,8 +437,7 @@ static int netem_enqueue(struct sk_buff *skb, struct Qdisc *sch, struct netem_skb_cb *cb; struct sk_buff *skb2; struct sk_buff *segs = NULL; - unsigned int len = 0, last_len, prev_len = qdisc_pkt_len(skb); - int nb = 0; + unsigned int prev_len = qdisc_pkt_len(skb); int count = 1; int rc = NET_XMIT_SUCCESS; int rc_drop = NET_XMIT_DROP; @@ -495,6 +494,7 @@ static int netem_enqueue(struct sk_buff *skb, struct Qdisc *sch, segs = netem_segment(skb, sch, to_free); if (!segs) return rc_drop; + qdisc_skb_cb(segs)->pkt_len = segs->len; } else { segs = skb; } @@ -585,6 +585,11 @@ static int netem_enqueue(struct sk_buff *skb, struct Qdisc *sch, finish_segs: if (segs) { + unsigned int len, last_len; + int nb = 0; + + len = skb->len; + while (segs) { skb2 = segs->next; segs->next = NULL; @@ -600,9 +605,7 @@ finish_segs: } segs = skb2; } - sch->q.qlen += nb; - if (nb > 1) - qdisc_tree_reduce_backlog(sch, 1 - nb, prev_len - len); + qdisc_tree_reduce_backlog(sch, -nb, prev_len - len); } return NET_XMIT_SUCCESS; } -- 2.20.1