Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp4131381ybe; Mon, 9 Sep 2019 04:52:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqyFF3PZ+b/f4ntkGa6JDdQY+z6pQNgIbuN/iat4dZGI8O+/eLRpUKgqbTH/ZC27nwuVmwH/ X-Received: by 2002:a17:906:1694:: with SMTP id s20mr18881880ejd.262.1568029922812; Mon, 09 Sep 2019 04:52:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568029922; cv=none; d=google.com; s=arc-20160816; b=AQIvi+QNDNJGJWlO687nZ1k30kaSqN4fVCMjHYlBxMj33naAbWNMFZQnwcfDCESaxS SflzbJdLsrwCHtS6shDBZ5zDtyDvGXOVfhGrONeRFz24ejQ2gaIZ5Hd2mWz+Rcy5jzqH U8pnJQeOciwiGAnNu1NnzNlbjAcglxs/mnXw61xsfxASlaew6H+DGSJercGLNikB0xro ICaykOOIs0YDqa5yVHbsbCef3iZgZUtAd/w97vPhSiKGaTw9sfBvmmE9zPpc1KvGgiIt yBt7/xG0o1My1YCWhEmtYnRP7eHXg5Pbh3RcX7i2crezT6RL5ji9lH/IFkBKOq4FukXP ZF0Q== 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=HgeA3kz6vtblQ5/fZmcRAIFvf3vi8m93F8JIfyAwK+0=; b=F3jDZD/8vVGiKewfecMjPX2RLU/8eeSHrNy55q0oiG1GlukyL4iKrXtILHk37udSqw 8zKEMoPv1XzivjAxQOl5RAoTAbn3nE2PcZ1yWQrnko2OOGG+99yPm8g6uoOXehgzuZ1q jkV9S4v/RwXKe1+7BKoq384RAkPsTNK0W6BXXeH1Nm6oAfLxFiICFhVsA6OzejtfNBwT LkF4gHD1Eo3JCU9Gdr2buuOBf8iX2TREuJSDmdx65RqgOGzqum4cJ4PkDzJ8RY4qYsno oJvzp7J0vOxoT4mhZ2ilBk945MXqBs3R1aFxvYYA0Zth7BZje/1eQrg8dU03T8Lve6+d fbSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rsRZtJTg; 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 q4si7259033ejb.186.2019.09.09.04.51.39; Mon, 09 Sep 2019 04:52:02 -0700 (PDT) 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=rsRZtJTg; 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 S1732643AbfIHMvc (ORCPT + 99 others); Sun, 8 Sep 2019 08:51:32 -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: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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;