Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp2274634pxb; Mon, 11 Jan 2021 05:48:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJxXkavyOCcD4ZGYnbJY2MayRQeq+wqL5xWzKBQxQAB0z0Wga1HASP/QwEDDZbchpuEU6GSh X-Received: by 2002:a05:6402:5112:: with SMTP id m18mr14457678edd.129.1610372891307; Mon, 11 Jan 2021 05:48:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610372891; cv=none; d=google.com; s=arc-20160816; b=m0M+AMGXu9QmBucMnJl8612FTlP9nU2sqZklnzI4ZV/+7ocATPGKHaG2w1Pxm0wNiZ qNAIHGKbXykN/Bxz1N1nIjVj+7gDHs7TYuAbM74iDlrr3ItGRjyeoM9lpHhsjHm07G4q ACJnUBr4TScjjfBDrGGFgiDO1TqYzyQ7fXmossUV9zEKbGaUjlKcgLA/FpdAlDM/yfZL 7vMHP56idbivpu/qHwAMnNRA08tOaOJSB6kvn07ROPRCbLXd/3GcLMPGSpWnwOk9Nxqc F6Wn72B9djMIGjs0HgffArzwJK6ntUVg/UQKZ1XN1cLxnGuTiEmhN/vKHz4coom7CD6N 0ylA== 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=+Nyf4DL38zx8CzF5lJVCYOEUTBCSn01d/znSc4sSz84=; b=O0rxPZQxksLqv5ikEUPlORBKF0shaaHWlMWj6luuZC5X5zUpESj3KRMqrZe7mVcVtL cIOf+UlWLl3vmf+T+UzhdNNHw8oTRVYgMsvT5oCgMB9P6bFKjwYN5IWjmHS805af0PCL p1kxFI3qp0cY29zeR52SAIx5iFnf6Q/s3C34Lqp6LKUn74QttlMiw8aTcvZUaT/ZZt6z MTEcRRyFTd3dXV9Swd3ZKarOTXuQJzkw3LhdxRgxuz35BS2fXKuN4j2AIdlmnLJcUsHg XB8IihfxU7mFNvE5cy7TWWtSVPzHUutM8VabQoQ2uEj/6O8jetUsKGc8hxIKKEdPuBbR 34DA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=IbaoD0My; 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 w11si5446509ejc.31.2021.01.11.05.47.47; Mon, 11 Jan 2021 05:48:11 -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=IbaoD0My; 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 S1732996AbhAKNo5 (ORCPT + 99 others); Mon, 11 Jan 2021 08:44:57 -0500 Received: from mail.kernel.org ([198.145.29.99]:58310 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731463AbhAKNLs (ORCPT ); Mon, 11 Jan 2021 08:11:48 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 458B321973; Mon, 11 Jan 2021 13:11:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1610370692; bh=D5joDTXCEwsc1YcQpwst7EBaHD/zetgkUZdTBzGhZd0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IbaoD0Myib9xtcF3I/Fqelr7Hhu3LC0w/7WNySru4cVsZdGQU09gwlA7VJSMUTGZ4 KM6I/3O7NBghZ/QOWHRbdmxt5sRQVLt5F01N/yogciHTXHJ0D+WHhq/Byb9+F86yP3 lQ3KYmwGjF46b6V77aTbI2l6kyiZA00bgus0mEks= 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 29/92] net-sysfs: take the rtnl lock when accessing xps_rxqs_map and num_tc Date: Mon, 11 Jan 2021 14:01:33 +0100 Message-Id: <20210111130040.549493795@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 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 @@ -1347,22 +1347,29 @@ 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 = bitmap_zalloc(dev->num_rx_queues, 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); @@ -1388,10 +1395,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); bitmap_free(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,