Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp2273607pxb; Mon, 11 Jan 2021 05:46:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJy0jwHEt67bqvTrVHlbgw+yIK70qx+jj+wVPEjQ96tH7+uKneDzlpdcJLfhDzxq9jWU6F+B X-Received: by 2002:a50:8387:: with SMTP id 7mr13467601edi.131.1610372779975; Mon, 11 Jan 2021 05:46:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610372779; cv=none; d=google.com; s=arc-20160816; b=xR3A3iAbIImNC6D7+gzQhmL+EAmrNC0kcNlwwZczRVuiDSpHn0isKBJ0GrS+ouMEWf Ky83VDlV3thAYk4020PgTTI4ZalC/I56sfyWU3Pznvh4k3h9N0+FB6z1BOMP8p1jppn6 /94ok9JviyVcJpefB80bnf8CqQkE5GeSZDwVdwkjL26pZ/BhpHYYGUAYUIeveIjErxYg 1PiaNP0OPLI1m35Kw250WVvge3QShX0abCpxmr48WUGRhCtJlioRQhzzQ6dDPEQ51wlQ 76UUsq7TXmTeYxdBLRuE/xMWyMTmibg+zIBYNjZXRuWgERfkoR3DionTpok470UJWOro jVLw== 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=MUeWbjbTmCpKtxq99W2YikuB/FMGft2Xde0swQgFrmM=; b=ijH8uEC/I0Yxd+EcpRmj55vC/xU7YnjX2gmMXsjFSeLZ9XIbO6DehrbXNLytyoo9Yr hyLEmt/6l6wT+eRdwhAFJuar2aQq/rAnGFb/86MDtUpkPDjBDT0XBYzD7SrizxzkmN5p x5lCF2oHNxJscP2gTcRkJSIxOxTHuRZ1FJ9ND2Ec/prGIEg/wjghMROBe6N5ayCEPr3x 2ke6jh76VpKLHnOUqKUezROH2MAkfdDtJte5IB1uLI7lSrW2prcimdwonWCwgLnNp3Hk XwdzAegmlCUAWT9yne/yPE0TnE/rY513Vsqan081HWyPmxH2F1K4qGNQ4TTFgkWTfzXF +7qA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=YxMJkWHA; 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 a3si6831262edt.452.2021.01.11.05.45.54; Mon, 11 Jan 2021 05:46:19 -0800 (PST) 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=YxMJkWHA; 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 S1730902AbhAKNMN (ORCPT + 99 others); Mon, 11 Jan 2021 08:12:13 -0500 Received: from mail.kernel.org ([198.145.29.99]:58548 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731371AbhAKNLX (ORCPT ); Mon, 11 Jan 2021 08:11:23 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3CD35227C3; Mon, 11 Jan 2021 13:10:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1610370642; bh=z3O2d7uTqPV8mHw6kNG5G6BMybboTdu4NcYvXUMhMBM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YxMJkWHA6sE9dyoXes1TZd+Fa8BqocC2U0X/qdKu1+jNrYGg1LTU74lSRXE1UpzQm UlJf9LPEGBhJFsJjrAO7U79SwKMv1Ng6viyQDUNdUpmBFVyagF9KnU7jGTFcCn97j8 po/wULX1DJiQkH2lpWZ5gYbLejjF6yvWnBi2iFY0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Antoine Tenart , Alexander Duyck , Jakub Kicinski Subject: [PATCH 5.4 27/92] net-sysfs: take the rtnl lock when accessing xps_cpus_map and num_tc Date: Mon, 11 Jan 2021 14:01:31 +0100 Message-Id: <20210111130040.457884922@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210111130039.165470698@linuxfoundation.org> References: <20210111130039.165470698@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: Antoine Tenart [ Upstream commit fb25038586d0064123e393cadf1fadd70a9df97a ] Accesses to dev->xps_cpus_map (when using dev->num_tc) should be protected by the rtnl lock, like we do for netif_set_xps_queue. I didn't see an actual bug being triggered, but let's be safe here and take the rtnl lock while accessing the map in sysfs. Fixes: 184c449f91fe ("net: Add support for XPS with QoS via traffic classes") Signed-off-by: Antoine Tenart Reviewed-by: Alexander Duyck Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- net/core/net-sysfs.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) --- a/net/core/net-sysfs.c +++ b/net/core/net-sysfs.c @@ -1235,8 +1235,8 @@ static const struct attribute_group dql_ static ssize_t xps_cpus_show(struct netdev_queue *queue, char *buf) { + int cpu, len, ret, num_tc = 1, tc = 0; struct net_device *dev = queue->dev; - int cpu, len, num_tc = 1, tc = 0; struct xps_dev_maps *dev_maps; cpumask_var_t mask; unsigned long index; @@ -1246,22 +1246,31 @@ static ssize_t xps_cpus_show(struct netd index = get_netdev_queue_index(queue); + if (!rtnl_trylock()) + return restart_syscall(); + if (dev->num_tc) { /* Do not allow XPS on subordinate device directly */ num_tc = dev->num_tc; - if (num_tc < 0) - return -EINVAL; + if (num_tc < 0) { + ret = -EINVAL; + goto err_rtnl_unlock; + } /* If queue belongs to subordinate dev use its map */ dev = netdev_get_tx_queue(dev, index)->sb_dev ? : dev; tc = netdev_txq_to_tc(dev, index); - if (tc < 0) - return -EINVAL; + if (tc < 0) { + ret = -EINVAL; + goto err_rtnl_unlock; + } } - if (!zalloc_cpumask_var(&mask, GFP_KERNEL)) - return -ENOMEM; + if (!zalloc_cpumask_var(&mask, GFP_KERNEL)) { + ret = -ENOMEM; + goto err_rtnl_unlock; + } rcu_read_lock(); dev_maps = rcu_dereference(dev->xps_cpus_map); @@ -1284,9 +1293,15 @@ static ssize_t xps_cpus_show(struct netd } rcu_read_unlock(); + rtnl_unlock(); + len = snprintf(buf, PAGE_SIZE, "%*pb\n", cpumask_pr_args(mask)); free_cpumask_var(mask); return len < PAGE_SIZE ? len : -EINVAL; + +err_rtnl_unlock: + rtnl_unlock(); + return ret; } static ssize_t xps_cpus_store(struct netdev_queue *queue,