Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp4472415ybz; Tue, 28 Apr 2020 11:53:07 -0700 (PDT) X-Google-Smtp-Source: APiQypJvOe2m8ZNo1LHRI8xNLPRCabBBXu9zglIRU9P9WoQITInnOoq9LkVQcIDveC6gnr+/0wQ7 X-Received: by 2002:a17:906:8286:: with SMTP id h6mr17890311ejx.28.1588099986981; Tue, 28 Apr 2020 11:53:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588099986; cv=none; d=google.com; s=arc-20160816; b=Exn+vQg3qA61DerJGTorpTDMiiUKBOeAIGMNbg2S8w4joa8BE7YjtlA6qS93JAavn7 A8JzY2X5Sm1fiHcJBWlyzjMTrRMfWz9cAIH+W8wAlP2VjqUENHLPXrRP9/IuqdUxLXmo UlMCRbnFPyBjq6yf4tAwlcQOQae8cbnxs2LcI26cZWz5eaoRQyeMLZbTmyOgHbDOTWXU F0fowJcYvF/s+NhxQ3KW5rCNdU0o6tXf9gRL6d5g/OLQwI7zg8myoMdAhZEpgXr+qKZp 3f0oAkgB5+sSEe1gr+PZhR7gX/gGPv7ZmUATnjG00mYaB43n+UjyTcQz+NotKSyB9c+J wDJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=9FefaNg/6pZsttucfWqFUsADZQJ3zJ2CzwblH/DUHuM=; b=rZ/n9Sw32yXcKli9/KJIm8T5GJ+2LFIKy7MlL8+3LhKHHMlJ/aEqkA6Jm0CQhc1JO7 0ASnRUogt/qIKJ8aevZKrVlzPaHTPHwUkU+rGSlb/w8qawAdqMi9z4eT2//UcAKRieXo /oKrVLuO6WwTdhbfOMNt2erBiJjfgOF1+qzUEm++lX7gfxmmDbUuC7vAbCN9RZNMeEoN 8Kt5jGU84c4hg2Gv4Oi8F4HlHLlXNFFG40Cqp+g5krC49MlZ03LZxQ9NlQzhMR3PzZQg B+NEEcELB/ObaRAnOMfHKGyBpvbYLZ13jAYPNNllARuvbQCEk0fa+Acof5EjFAGUPe05 /nSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=IakRQ2TM; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l9si2186518ejc.237.2020.04.28.11.52.43; Tue, 28 Apr 2020 11:53:06 -0700 (PDT) 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=@kernel.org header.s=default header.b=IakRQ2TM; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730887AbgD1SkH (ORCPT + 99 others); Tue, 28 Apr 2020 14:40:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:59018 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730113AbgD1SkD (ORCPT ); Tue, 28 Apr 2020 14:40:03 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8B86F20730; Tue, 28 Apr 2020 18:39:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588099200; bh=stN9rP4HgKIFrPN1xz/O73Hsp6NVHW7nqXAQ5WzJH24=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IakRQ2TMoY39nP2oSmWEhb9/fsGsOx5Zek/q0hbjasKEl5BhrdwBNGXcRjpqFQZSb tqF5k1ncR9EUcvgm0PEL0S/YBk1cIuf2/htDmzoHO1nn82t9J/Ot9ipoAZ5E+uKDay 5Svidt6p2xPmoPifgX6bCYsEU95fXKWl/iXgZgVk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Taehee Yoo , Jiri Pirko , "David S. Miller" Subject: [PATCH 5.4 072/168] team: fix hang in team_mode_get() Date: Tue, 28 Apr 2020 20:24:06 +0200 Message-Id: <20200428182241.153327566@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200428182231.704304409@linuxfoundation.org> References: <20200428182231.704304409@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Taehee Yoo [ Upstream commit 1c30fbc76b8f0c07c92a8ca4cd7c456612e17eb5 ] When team mode is changed or set, the team_mode_get() is called to check whether the mode module is inserted or not. If the mode module is not inserted, it calls the request_module(). In the request_module(), it creates a child process, which is the "modprobe" process and waits for the done of the child process. At this point, the following locks were used. down_read(&cb_lock()); by genl_rcv() genl_lock(); by genl_rcv_msc() rtnl_lock(); by team_nl_cmd_options_set() mutex_lock(&team->lock); by team_nl_team_get() Concurrently, the team module could be removed by rmmod or "modprobe -r" The __exit function of team module is team_module_exit(), which calls team_nl_fini() and it tries to acquire following locks. down_write(&cb_lock); genl_lock(); Because of the genl_lock() and cb_lock, this process can't be finished earlier than request_module() routine. The problem secenario. CPU0 CPU1 team_mode_get request_module() modprobe -r team_mode_roundrobin team <--(B) modprobe team <--(A) team_mode_roundrobin By request_module(), the "modprobe team_mode_roundrobin" command will be executed. At this point, the modprobe process will decide that the team module should be inserted before team_mode_roundrobin. Because the team module is being removed. By the module infrastructure, the same module insert/remove operations can't be executed concurrently. So, (A) waits for (B) but (B) also waits for (A) because of locks. So that the hang occurs at this point. Test commands: while : do teamd -d & killall teamd & modprobe -rv team_mode_roundrobin & done The approach of this patch is to hold the reference count of the team module if the team module is compiled as a module. If the reference count of the team module is not zero while request_module() is being called, the team module will not be removed at that moment. So that the above scenario could not occur. Fixes: 3d249d4ca7d0 ("net: introduce ethernet teaming device") Signed-off-by: Taehee Yoo Reviewed-by: Jiri Pirko Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/team/team.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/drivers/net/team/team.c +++ b/drivers/net/team/team.c @@ -468,6 +468,9 @@ static const struct team_mode *team_mode struct team_mode_item *mitem; const struct team_mode *mode = NULL; + if (!try_module_get(THIS_MODULE)) + return NULL; + spin_lock(&mode_list_lock); mitem = __find_mode(kind); if (!mitem) { @@ -483,6 +486,7 @@ static const struct team_mode *team_mode } spin_unlock(&mode_list_lock); + module_put(THIS_MODULE); return mode; }