Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2827160pxb; Mon, 1 Nov 2021 02:38:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx2RF9jon2eRbGbFEv5w7t3nQG/rS8ZlKI4BE/vMnFer0U3eaxRMpxvgdxMd4h2wJ5am0yq X-Received: by 2002:a17:906:5811:: with SMTP id m17mr35387320ejq.289.1635759527547; Mon, 01 Nov 2021 02:38:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635759527; cv=none; d=google.com; s=arc-20160816; b=A3ep0xYpItBKMZpqa9twru9g5i8kR2rCvcHAZN6MuZRHTRHkNmLI2U9GOX0ogSWIdO 0I6aXHEtm0osrbmQoXbmAkzPuIts60hZ958QFxcIY1IMSDoN0v966vv01R26r0PBbiwN uG14xCYa7QEOqeA8r6Wii/pOiDbgnF9SOF9MuxSJNmldf9AHN6DQTRHDJNg8k9IX+2nq f3AvCpkjV1ogQcR7X0XP1o7cHdUnP7a9aOBlk5S9jSKWKoudnQacRq7Px50HOU70mVTf r/HSbCY3girx/5v58qclrXs38UHyMtsn/zC/HT4woxoe4KkCKXuA7cxBQYqxRWeSus4h 32Yg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=PQXe76RLOKOd4TQQX2uPmPmKTl7XkYblFTzQERLa8Aw=; b=llQXFizaGIYyUHbmx9Z6EFrgEbct/IS1VvBtIGhqGcy08OheyLL/zXY39+3hd1VCQl MHLp+LmKW357NVvc39rDAkPpteQ0X21qHqT6T7G/Jzy5wQpmSGDuGLZd3ecL5V+M67Ao /DDFUN5cP86uL01j6dAEIlRZICiDNLNCGnOg/chdiDGeKu37ejex+ArYZz9SA86fJt1d VgcqUwF6CeZn7x7UJPBsE4OhDZJF2jplkLFJMTxyO5/vrh1RmFkn6J5xO1byoJdw8aFq DamJullhKvBmF4np03Asn4uN2gAWWV99FmaYgN229H99QNUgoq0N+qCYZIn/bFc0Ey0g HCzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=aZRf6z6d; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id mp16si30979513ejc.680.2021.11.01.02.38.24; Mon, 01 Nov 2021 02:38:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=aZRf6z6d; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233974AbhKAJib (ORCPT + 99 others); Mon, 1 Nov 2021 05:38:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:43676 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233277AbhKAJf7 (ORCPT ); Mon, 1 Nov 2021 05:35:59 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0391D6115B; Mon, 1 Nov 2021 09:26:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1635758772; bh=I+p1RbHMY/qMyBbrckyFHTOaJRnNI+atK/hm/ghOfA8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aZRf6z6dWIIuL1Wg92L/7rPoeQdZ8MQHjoSwrRNF2jPezc1gw4Y6nf+lF77RBugDm BBTh2OepByKyS+cjWXU5hPGBFSekTPMXP6jcEcMOp8/XqInuGIm0/c6ZNT9Xye4XU3 2iucKa6rmRODVqcItYlsy0uoiBowI9IPY19zIyUo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andy Gospodarek , Michael Chan , "David S. Miller" Subject: [PATCH 5.10 52/77] net: Prevent infinite while loop in skb_tx_hash() Date: Mon, 1 Nov 2021 10:17:40 +0100 Message-Id: <20211101082522.634266313@linuxfoundation.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211101082511.254155853@linuxfoundation.org> References: <20211101082511.254155853@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Michael Chan commit 0c57eeecc559ca6bc18b8c4e2808bc78dbe769b0 upstream. Drivers call netdev_set_num_tc() and then netdev_set_tc_queue() to set the queue count and offset for each TC. So the queue count and offset for the TCs may be zero for a short period after dev->num_tc has been set. If a TX packet is being transmitted at this time in the code path netdev_pick_tx() -> skb_tx_hash(), skb_tx_hash() may see nonzero dev->num_tc but zero qcount for the TC. The while loop that keeps looping while hash >= qcount will not end. Fix it by checking the TC's qcount to be nonzero before using it. Fixes: eadec877ce9c ("net: Add support for subordinate traffic classes to netdev_pick_tx") Reviewed-by: Andy Gospodarek Signed-off-by: Michael Chan Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/core/dev.c | 6 ++++++ 1 file changed, 6 insertions(+) --- a/net/core/dev.c +++ b/net/core/dev.c @@ -3171,6 +3171,12 @@ static u16 skb_tx_hash(const struct net_ qoffset = sb_dev->tc_to_txq[tc].offset; qcount = sb_dev->tc_to_txq[tc].count; + if (unlikely(!qcount)) { + net_warn_ratelimited("%s: invalid qcount, qoffset %u for tc %u\n", + sb_dev->name, qoffset, tc); + qoffset = 0; + qcount = dev->real_num_tx_queues; + } } if (skb_rx_queue_recorded(skb)) {