From mboxrd@z Thu Jan 1 00:00:00 1970 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=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,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 7C3C9C4360D for ; Sun, 8 Sep 2019 12:55:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4873F20693 for ; Sun, 8 Sep 2019 12:55:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567947317; bh=1HgWfFEiXK+kna90PfsnfcU1m1Ld0CmnpIk7xow7eLQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=VeA+KxQlngGlCuEWUalYK9CqdWi8Oj2ZALeAXoyEEuF1//ELxzmDpIWO/PTy4zoPV 5CTB+O2OmFXhAy72s079SUuaFSEhupH3v9ivifj9Wiz37PTTX9SWiNscc1mpCQt3f5 8GThFL/igSqj/2OFTWsPUK/udm+9Ex0ROEBok6cE= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732582AbfIHMvX (ORCPT ); Sun, 8 Sep 2019 08:51:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:42718 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732577AbfIHMvW (ORCPT ); Sun, 8 Sep 2019 08:51:22 -0400 Received: from localhost (unknown [62.28.240.114]) (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 709A320863; Sun, 8 Sep 2019 12:51:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567947081; bh=1HgWfFEiXK+kna90PfsnfcU1m1Ld0CmnpIk7xow7eLQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rsRZtJTgB4xE8Hdqw0Au8OZGTd9V7HWi5s0eYBWaCF219DrOQx1cDwyY+qR6OdgJ7 Q/0gViy7PS6LPGzcryvEc9thVYPtzPA309o8ewXhykBcgYRupOdUTXz+CtFR67FCAN dbIb9gmR9jxjBijQxE8IzGHjj+F31O5MQXSflOhk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Leandro Dorileo , Vladimir Oltean , Vinicius Costa Gomes , "David S. Miller" Subject: [PATCH 5.2 12/94] taprio: Fix kernel panic in taprio_destroy Date: Sun, 8 Sep 2019 13:41:08 +0100 Message-Id: <20190908121150.784656515@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190908121150.420989666@linuxfoundation.org> References: <20190908121150.420989666@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Vladimir Oltean taprio_init may fail earlier than this line: list_add(&q->taprio_list, &taprio_list); i.e. due to the net device not being multi queue. Attempting to remove q from the global taprio_list when it is not part of it will result in a kernel panic. Fix it by matching list_add and list_del better to one another in the order of operations. This way we can keep the deletion unconditional and with lower complexity - O(1). Cc: Leandro Dorileo Fixes: 7b9eba7ba0c1 ("net/sched: taprio: fix picos_per_byte miscalculation") Signed-off-by: Vladimir Oltean Acked-by: Vinicius Costa Gomes Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/sched/sch_taprio.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) --- a/net/sched/sch_taprio.c +++ b/net/sched/sch_taprio.c @@ -903,6 +903,10 @@ static int taprio_init(struct Qdisc *sch */ q->clockid = -1; + spin_lock(&taprio_list_lock); + list_add(&q->taprio_list, &taprio_list); + spin_unlock(&taprio_list_lock); + if (sch->parent != TC_H_ROOT) return -EOPNOTSUPP; @@ -920,10 +924,6 @@ static int taprio_init(struct Qdisc *sch if (!opt) return -EINVAL; - spin_lock(&taprio_list_lock); - list_add(&q->taprio_list, &taprio_list); - spin_unlock(&taprio_list_lock); - for (i = 0; i < dev->num_tx_queues; i++) { struct netdev_queue *dev_queue; struct Qdisc *qdisc;