Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp2816571pxb; Mon, 11 Jan 2021 22:06:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJw4NSaYoG7WMOsfy2rPY9mZ7KRa2gmrPA9LA/H6sZNThNy8KExTZvuOWWldrJf2HEd49m2w X-Received: by 2002:aa7:d5d2:: with SMTP id d18mr2190821eds.126.1610431594093; Mon, 11 Jan 2021 22:06:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610431594; cv=none; d=google.com; s=arc-20160816; b=yK3wKrRpofeqsGJly7KHqUW85fJmDafUhGWxvieRFmfkXpV/A/RIEVv5NDzDUJoWDG SK9N+GWU4JOzkFntUVEjlclE6gZl1x6gA8xc/b/CH5AAK93iuE9rEDQ7PWfNCMI1Bp9p Uqm/I3kl4pSc0hwz6H/jGcE8H3bFbZ3WU8N+6CsoOxzdmZTANPXWxhDa2CXbIUJ7j90e 3Ta6eyMzqsXJ8FK1FWcmgzdeLAoZJmlVeMsqzexXCnceLKj3MvU7qdpZCF4C1w4UYs2z nBNpwOfwZQ6C8+LhMOFK+t3Bc1G9mbb9C1l+gt+yoai1mj9kD5YQ//qhHlYCUvb7uTiL 6hlA== 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=F52ibZBtimO/g/Oy4UFYHULTYJGK5/lFQRyoQpH1OrE=; b=LLm4lOI/PP2Pz22eacG0MWIStPoQn+MhkeaNZFZ+spftWarU1/i7uGSsxw9SBhhtPe LBfOMhnqPstXnOPNIXjrw15N5CsRgvbRHABF54UeNtLHh0bufNtaWvHUJ7DLuyjSt0H3 9mBB1LFJAsjHC5SOb48AaC4d3LZ5J6omD9efb091BmQIMCw6Zdkh8uOn0JPhi2tweILw 2Oy/QCRwjkU+/jorIBb3fnDiMkYjadY6WFHJGTEH/7Oqd6uLpg9nlaP6hY6Rav9wCML4 BphQcpAnxlGyhn/mHXM9Vf6GVTRqhQuLLiAWjKyLke9dvqRhGYfPgkFHhyqgptoiBlaK 6BPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qjLsPGQ8; 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 v26si696056ejg.723.2021.01.11.22.06.10; Mon, 11 Jan 2021 22:06:34 -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=qjLsPGQ8; 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 S2387657AbhAKNov (ORCPT + 99 others); Mon, 11 Jan 2021 08:44:51 -0500 Received: from mail.kernel.org ([198.145.29.99]:58956 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731460AbhAKNLs (ORCPT ); Mon, 11 Jan 2021 08:11:48 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id E5D98229CA; Mon, 11 Jan 2021 13:11:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1610370667; bh=C+E7F5LkPS1WIed50+mngHIy0XJXZvqjWr+eh+lqivQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qjLsPGQ8OVDJFqi1kqHUDCgKS2kYpKm64vI5ZSVQePV82xegQQfzsDJPgS1iyT3V/ 9InSD3FDAZ3F6XXP20Z2KExLXdiZRxZFRT0c3Ll1r0Yj5OlOrh+ZkFJfytZYpddW72 ejCfno3hS0GCyRune1PHcsRTRri6XGNqjG2EHXQ0= 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 28/92] net-sysfs: take the rtnl lock when storing xps_rxqs Date: Mon, 11 Jan 2021 14:01:32 +0100 Message-Id: <20210111130040.500605721@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 2d57b4f142e0b03e854612b8e28978935414bced ] Two race conditions can be triggered when storing xps rxqs, resulting in various oops and invalid memory accesses: 1. Calling netdev_set_num_tc while netif_set_xps_queue: - netif_set_xps_queue uses dev->tc_num as one of the parameters to compute the size of new_dev_maps when allocating it. dev->tc_num is also used to access the map, and the compiler may generate code to retrieve this field multiple times in the function. - netdev_set_num_tc sets dev->tc_num. If new_dev_maps is allocated using dev->tc_num and then dev->tc_num is set to a higher value through netdev_set_num_tc, later accesses to new_dev_maps in netif_set_xps_queue could lead to accessing memory outside of new_dev_maps; triggering an oops. 2. Calling netif_set_xps_queue while netdev_set_num_tc is running: 2.1. netdev_set_num_tc starts by resetting the xps queues, dev->tc_num isn't updated yet. 2.2. netif_set_xps_queue is called, setting up the map with the *old* dev->num_tc. 2.3. netdev_set_num_tc updates dev->tc_num. 2.4. Later accesses to the map lead to out of bound accesses and oops. A similar issue can be found with netdev_reset_tc. One way of triggering this is to set an iface up (for which the driver uses netdev_set_num_tc in the open path, such as bnx2x) and writing to xps_rxqs in a concurrent thread. With the right timing an oops is triggered. Both issues have the same fix: netif_set_xps_queue, netdev_set_num_tc and netdev_reset_tc should be mutually exclusive. We do that by taking the rtnl lock in xps_rxqs_store. 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 | 7 +++++++ 1 file changed, 7 insertions(+) --- a/net/core/net-sysfs.c +++ b/net/core/net-sysfs.c @@ -1417,10 +1417,17 @@ static ssize_t xps_rxqs_store(struct net return err; } + if (!rtnl_trylock()) { + bitmap_free(mask); + return restart_syscall(); + } + cpus_read_lock(); err = __netif_set_xps_queue(dev, mask, index, true); cpus_read_unlock(); + rtnl_unlock(); + bitmap_free(mask); return err ? : len; }