From patchwork Fri Jan 24 09:30:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 232841 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E7AFC2D0DB for ; Fri, 24 Jan 2020 11:39:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 154A220708 for ; Fri, 24 Jan 2020 11:39:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579865989; bh=2qLNSVlKCzjET/toYUlwu2CpfwILDJlUSxqs0/7lDGU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=N2OEi0ktVEqx5t+1JsEuJk/Uq3SZWb00e7D2j+cIwrxQ52JIc2x0GZpO9+l7mrMJv xkiwFOU2rvYf0MjPDTggWquOQSAf6pXeCHeirMFgGkiNSvF42qi3u5KusTP5Ye+Tai k83rsUcd8iqqgCi/DudIlA6RLvCwBsoIKjDonpSk= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2403807AbgAXLYo (ORCPT ); Fri, 24 Jan 2020 06:24:44 -0500 Received: from mail.kernel.org ([198.145.29.99]:38342 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403806AbgAXLYn (ORCPT ); Fri, 24 Jan 2020 06:24:43 -0500 Received: from localhost (ip-213-127-102-57.ip.prioritytelecom.net [213.127.102.57]) (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 D973020718; Fri, 24 Jan 2020 11:24:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579865082; bh=2qLNSVlKCzjET/toYUlwu2CpfwILDJlUSxqs0/7lDGU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kX3aJ1yBGvfzAd4qxzjvQMS4Oczqsdxh+77Ihgh9Qxs339WIpw/fYyvbZR3Q4Y+Pu RN4c+puOnkesxAsFSWkbTTJSGKBh/7LbjwEtaU8V0skE4Xz/8NzJAgGTKA4QpP04r4 S8d6cXL5uYw0tn0sUbOKCpNmXAmkqi4qnsDd8n+o= 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.19 435/639] net: netem: fix backlog accounting for corrupted GSO frames Date: Fri, 24 Jan 2020 10:30:05 +0100 Message-Id: <20200124093141.503539537@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200124093047.008739095@linuxfoundation.org> References: <20200124093047.008739095@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@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 15f8f24c190d4..1cd7266140e6a 100644 --- a/net/sched/sch_netem.c +++ b/net/sched/sch_netem.c @@ -436,8 +436,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; @@ -494,6 +493,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; } @@ -583,6 +583,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; @@ -598,9 +603,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; }