Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp725611pxb; Tue, 2 Feb 2021 16:48:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJza/L/+xW9LlgIAun6A9CaALG+Q7Vun54V7MSptLBQkuXl2UDYYk0OVbXTAQkdUp+QmkNMj X-Received: by 2002:a05:6402:c92:: with SMTP id cm18mr635934edb.367.1612313334720; Tue, 02 Feb 2021 16:48:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612313334; cv=none; d=google.com; s=arc-20160816; b=pZudaN58345pZe5ggI8a9YVEYZ/DMqO+aULRCvkaAi0Cni6QjTp4KFWc3ObrKXAt8v nNHhJ4XqISFO5Vz1nrMD3gVZGCo1clSlbdJtrxzXvX+NXTNuQbFxduMgMjaFoXjS+CmW WTgCqjrBINT9KEUIr45bJ1qnmd42/qdUEr7JSL2DLoWIydK+jXjunctVfzX0KeLdQ1T9 n8SmE5UW6J+We2QAYAlPUyMHf5yuAs5T8LiPsaahtafkYJUSojh25i+nuAQVzZ/aoq+c bMkREdDsdN2pidn/Kzv40K+6Y7VcTmD5ki7H/N+SQ44D9/827hl5WiU/o8bWRtl44EMu nmCA== 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=buBJUfeNxlj1ErJaYIs4hXrdD2uEqrj8K4+wxQZXUA0=; b=egNMzC80twizQsAqvaozqYtd/GJxGYLddrU4WIGoxKLCp9IC4FJo1/maCEHq6VqSUy 6WC02LxobGjKENklv3MMhpAPjKWspk9b/1dP3yJQMDXzzDm0zd5Ir9B3/D3l85FEHNbh oOcjaSxAyddF0YIHj6kn8oyZ597Nj1Qlkp8l5A97IJ2i4sXSC7zz6gVVVD8suaWr/BtS FfES1OiTAyIn+eE3AbBxMBYiGnc7iPj06W0LZlJxLbpuOTpgXLAXiCliybFeQusF5421 y1++SmIMfwTKd8s61v6oESz+n3zwUL62VTrleGQ6UMDJsHM6pNPr9hp6tfTFJNMWz+8Y 4Q6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=XwT57QEt; 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 a12si222205edn.568.2021.02.02.16.48.30; Tue, 02 Feb 2021 16:48:54 -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=XwT57QEt; 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 S233411AbhBBTeM (ORCPT + 99 others); Tue, 2 Feb 2021 14:34:12 -0500 Received: from mail.kernel.org ([198.145.29.99]:42642 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233251AbhBBN4v (ORCPT ); Tue, 2 Feb 2021 08:56:51 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5B8B864FE2; Tue, 2 Feb 2021 13:45:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1612273532; bh=kbJxtOjn4Z6L1J5YkTSukPXznYzMC0E9oCCCHaaCVFg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XwT57QEtGxzz5bNdwMxyTBFe5Rv6eBOMbOAqyQkKZDgd/KC14yGXYjJNaQhU+DcbP 1o07u9M0mrukeprj8ZqdmU2k9Hhwl4nLrsG24FFuILQMy8tY8Pi/JcLP5+znxHd+vP kl7ILZqDs2Fsy7kuVKoVL74xz5mwncfuqPJLR8x8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Saeed Mahameed , Ivan Vecera , Cong Wang , Jiri Pirko , Jakub Kicinski Subject: [PATCH 5.10 140/142] team: protect features update by RCU to avoid deadlock Date: Tue, 2 Feb 2021 14:38:23 +0100 Message-Id: <20210202133003.468601405@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210202132957.692094111@linuxfoundation.org> References: <20210202132957.692094111@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: Ivan Vecera commit f0947d0d21b219e03940b9be6628a43445c0de7a upstream. Function __team_compute_features() is protected by team->lock mutex when it is called from team_compute_features() used when features of an underlying device is changed. This causes a deadlock when NETDEV_FEAT_CHANGE notifier for underlying device is fired due to change propagated from team driver (e.g. MTU change). It's because callbacks like team_change_mtu() or team_vlan_rx_{add,del}_vid() protect their port list traversal by team->lock mutex. Example (r8169 case where this driver disables TSO for certain MTU values): ... [ 6391.348202] __mutex_lock.isra.6+0x2d0/0x4a0 [ 6391.358602] team_device_event+0x9d/0x160 [team] [ 6391.363756] notifier_call_chain+0x47/0x70 [ 6391.368329] netdev_update_features+0x56/0x60 [ 6391.373207] rtl8169_change_mtu+0x14/0x50 [r8169] [ 6391.378457] dev_set_mtu_ext+0xe1/0x1d0 [ 6391.387022] dev_set_mtu+0x52/0x90 [ 6391.390820] team_change_mtu+0x64/0xf0 [team] [ 6391.395683] dev_set_mtu_ext+0xe1/0x1d0 [ 6391.399963] do_setlink+0x231/0xf50 ... In fact team_compute_features() called from team_device_event() does not need to be protected by team->lock mutex and rcu_read_lock() is sufficient there for port list traversal. Fixes: 3d249d4ca7d0 ("net: introduce ethernet teaming device") Cc: Saeed Mahameed Signed-off-by: Ivan Vecera Reviewed-by: Cong Wang Reviewed-by: Jiri Pirko Link: https://lore.kernel.org/r/20210125074416.4056484-1-ivecera@redhat.com Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- drivers/net/team/team.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/drivers/net/team/team.c +++ b/drivers/net/team/team.c @@ -991,7 +991,8 @@ static void __team_compute_features(stru unsigned int dst_release_flag = IFF_XMIT_DST_RELEASE | IFF_XMIT_DST_RELEASE_PERM; - list_for_each_entry(port, &team->port_list, list) { + rcu_read_lock(); + list_for_each_entry_rcu(port, &team->port_list, list) { vlan_features = netdev_increment_features(vlan_features, port->dev->vlan_features, TEAM_VLAN_FEATURES); @@ -1005,6 +1006,7 @@ static void __team_compute_features(stru if (port->dev->hard_header_len > max_hard_header_len) max_hard_header_len = port->dev->hard_header_len; } + rcu_read_unlock(); team->dev->vlan_features = vlan_features; team->dev->hw_enc_features = enc_features | NETIF_F_GSO_ENCAP_ALL | @@ -1020,9 +1022,7 @@ static void __team_compute_features(stru static void team_compute_features(struct team *team) { - mutex_lock(&team->lock); __team_compute_features(team); - mutex_unlock(&team->lock); netdev_change_features(team->dev); }