From patchwork Mon Dec 21 19:36:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antoine Tenart X-Patchwork-Id: 346936 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.0 required=3.0 tests=BAYES_00,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 40B62C433DB for ; Mon, 21 Dec 2020 19:37:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0205022CB1 for ; Mon, 21 Dec 2020 19:37:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726155AbgLUTh2 (ORCPT ); Mon, 21 Dec 2020 14:37:28 -0500 Received: from mail.kernel.org ([198.145.29.99]:59554 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725902AbgLUTh2 (ORCPT ); Mon, 21 Dec 2020 14:37:28 -0500 From: Antoine Tenart Authentication-Results: mail.kernel.org; dkim=permerror (bad message/signature format) To: davem@davemloft.net, kuba@kernel.org, alexander.duyck@gmail.com Cc: Antoine Tenart , netdev@vger.kernel.org, pabeni@redhat.com Subject: [PATCH net v2 0/3] net-sysfs: fix race conditions in the xps code Date: Mon, 21 Dec 2020 20:36:41 +0100 Message-Id: <20201221193644.1296933-1-atenart@kernel.org> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Hello all, This series fixes race conditions in the xps code, where out of bound accesses can occur when dev->num_tc is updated, triggering oops. The root cause is linked to lock issues. An explanation is given in each of the commit logs. Reviews in v1 suggested to use the xps_map_mutex to protect the maps and their related parameters instead of the rtnl lock. We followed this path in v2 as it seems a better compromise than taking the rtnl lock. As a result, patch 1 turned out to be less straight forward as some of the locking logic in net/core/dev.c related to xps_map_mutex had to be changed. Patches 2 and 3 are also larger in v2 as code had to be moved from net/core/net-sysfs.c to net/core/dev.c to take the xps_map_mutex (however maintainability is improved). Also, while working on the v2 I stumbled upon another race condition. I debugged it and the fix is the same as patch 1. I updated its commit log to describe both races. Thanks! Antoine Antoine Tenart (3): net: fix race conditions in xps by locking the maps and dev->tc_num net: move the xps cpus retrieval out of net-sysfs net: move the xps rxqs retrieval out of net-sysfs include/linux/netdevice.h | 9 ++ net/core/dev.c | 186 +++++++++++++++++++++++++++++--------- net/core/net-sysfs.c | 89 ++++-------------- 3 files changed, 171 insertions(+), 113 deletions(-)