Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp2674499pxb; Mon, 11 Jan 2021 16:50:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJy9Lj2zqMz4sNz277WO3ct07uJaW1ZQfqZMYku9SAalXSYO29Wv7lr8X/xq0wOj1IfA7z+F X-Received: by 2002:a17:906:369a:: with SMTP id a26mr1336886ejc.276.1610412641890; Mon, 11 Jan 2021 16:50:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610412641; cv=none; d=google.com; s=arc-20160816; b=iCiGqvJy38FVIdZyfNgaNBSAEFLk511giLjTgOA38GiaBbE8E8gMbzIlL0knt9TuoT hx1KHoiid4n8JioA83ahmxhqfgBPXTjo1Y5kO5MGehPJ88opnUSJeNdx+rTag/w5uTOm 8JxLgbq/AEDlKf97oYjD2do2WOvlxoaxzcXIIx4tdJZhkCZaiXIsbNDGsLl1VJQK1m63 kUqi+Jb80FulKCE1jAIyd9yrmWd+ZixVSk4I6rpt4FRnAlS729CPBM5eYNg7KQ7JmUau h7iZunG/Rf5J9j9poNzfPoLxPEBHopEZHv7tsMxC54axilx0oklzLIDxwCMTosN0ddAC rx3w== 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=yhOVJVqNy1X3Oeg7I9vCcG4eZl4IDi6YxpfWtKRTy24=; b=en2FLAM552/h0plycSm1/n8dsKH5c6VhQI8zKoXdEgsdUJ1m3XJC5F9hwnbqb7juDu 0o/rzPwhzYBQTD+SE8ZqMOrOr8bam4CZPn0Hs6NRsAtPbfH0Ap/OO2kHbmKl9yTi/2ke uUyTXYdH159gyz6gs1SI1WUIA9l/sqJb7JnF7SVxZpLT4SjGnSEE/TE0t4yXx5aidLVR SuThs2r1apmCS+As85sm6UT7rCmLfao/GfKkOfBGk9jH44iYyBnt+lYNce5feJ3H9FS8 q+eW3Wv2TPhqSb5lDCFXan+uEKk4Id7Ky5rKS8YLoxwypYZEWkSLnTa9nkgWB2l3DcFp EwRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qsH3nXaJ; 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 17si413088ejt.596.2021.01.11.16.50.17; Mon, 11 Jan 2021 16:50:41 -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=qsH3nXaJ; 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 S1730670AbhAKNI5 (ORCPT + 99 others); Mon, 11 Jan 2021 08:08:57 -0500 Received: from mail.kernel.org ([198.145.29.99]:54966 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730713AbhAKNIH (ORCPT ); Mon, 11 Jan 2021 08:08:07 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id CB2D422AAD; Mon, 11 Jan 2021 13:07:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1610370471; bh=jzGQHfeDByFgMo6EFOsbrBwo6331JUoc89XKDcaV7h4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qsH3nXaJ0hceGHyxfidbyz9/wFf9s1LtcDniJ2uUHkzpJ+/93XkpokX7QQo8FaQgE Y0q5NHNWcR2gooheP9ov8Y1/9OOqRScAEoK6YoOzEH7UjwgLx+8w9MkmrvahgYIY2U 31DJ7UD0jVI8dsVVOstccBgN1wkdv3Y73KFpMLVg= 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 4.19 37/77] net-sysfs: take the rtnl lock when accessing xps_rxqs_map and num_tc Date: Mon, 11 Jan 2021 14:01:46 +0100 Message-Id: <20210111130038.192159818@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210111130036.414620026@linuxfoundation.org> References: <20210111130036.414620026@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 4ae2bb81649dc03dfc95875f02126b14b773f7ab ] Accesses to dev->xps_rxqs_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: 8af2c06ff4b1 ("net-sysfs: Add interface for Rx queue(s) map per Tx queue") 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 | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) --- a/net/core/net-sysfs.c +++ b/net/core/net-sysfs.c @@ -1356,23 +1356,30 @@ static struct netdev_queue_attribute xps static ssize_t xps_rxqs_show(struct netdev_queue *queue, char *buf) { + int j, len, ret, num_tc = 1, tc = 0; struct net_device *dev = queue->dev; struct xps_dev_maps *dev_maps; unsigned long *mask, index; - int j, len, num_tc = 1, tc = 0; index = get_netdev_queue_index(queue); + if (!rtnl_trylock()) + return restart_syscall(); + if (dev->num_tc) { num_tc = dev->num_tc; tc = netdev_txq_to_tc(dev, index); - if (tc < 0) - return -EINVAL; + if (tc < 0) { + ret = -EINVAL; + goto err_rtnl_unlock; + } } mask = kcalloc(BITS_TO_LONGS(dev->num_rx_queues), sizeof(long), GFP_KERNEL); - if (!mask) - return -ENOMEM; + if (!mask) { + ret = -ENOMEM; + goto err_rtnl_unlock; + } rcu_read_lock(); dev_maps = rcu_dereference(dev->xps_rxqs_map); @@ -1398,10 +1405,16 @@ static ssize_t xps_rxqs_show(struct netd out_no_maps: rcu_read_unlock(); + rtnl_unlock(); + len = bitmap_print_to_pagebuf(false, buf, mask, dev->num_rx_queues); kfree(mask); return len < PAGE_SIZE ? len : -EINVAL; + +err_rtnl_unlock: + rtnl_unlock(); + return ret; } static ssize_t xps_rxqs_store(struct netdev_queue *queue, const char *buf,