Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp669698ybz; Fri, 1 May 2020 06:32:01 -0700 (PDT) X-Google-Smtp-Source: APiQypKrxWsvtwDu5jDZqoHRIjvW82CmD6+buRltsyKKJBbESLbrk4l25itQSReuekjrbv76NNGa X-Received: by 2002:a17:907:2107:: with SMTP id qn7mr3263362ejb.316.1588339921131; Fri, 01 May 2020 06:32:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588339921; cv=none; d=google.com; s=arc-20160816; b=OKeKd5WB/S4AE9ftr/I4SNbd0wjvtuDVrz9cmKahvbqViF85jFjlvZrDB+A4Mb9Hdn rxuXtm150l6oLsLj4OJ/wmdUKrLp7ZH+83VOZcXlNp621KmlSm/Ia+8xUKX0F+vjy4hz z7gERQrvYHkEw7Vh6g7yYxdaCz2QcHuqCjfbMX3BKaVtUZOX/3pVxtJrNQCR/dkhLnPk X+rUTY6TxeVUCL4wwqUWenlw4hLVujCxnw9O0YzuNbyqCz91PewSlPidI/1iPmnXaC6R /AJYbldTuV7cVLN5OqNpAsAttUpKeVnQVPKddXHo7SkFTKZrc8xzp8AeADJ5bljylOUu TR/Q== 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=4l31H6EzzDKzd9kz9CEj9Ugnu7DsWVGtNNB/0cLDoTg=; b=CR5qe0HUwU4KbM8Pr9Y/WuE9220FfEie5vau28qyyb93pjHnU54HvfNt6TEVGEb/hu LO4qp5FjiNxABORd3+yJGNqVJHqxk6m5KjxM16QEJWHl3xwgtZHSiKODQB8It2FWkDgz oDZrLww+XxVDoWPQYjXoKuPdeVHIwH3/HUdg2vRYp9e1DPf1s73Gv6WPeen+SFfB2pt+ hMfVHigxNHF1bVdzL82KYzO7uCr9zLzeSAaqp3/0dk3RABcbMDM0MTGOEKWHNTXKbb6Q g3eq1/gjmqeRIcJE1BrpejmzxScWNma2Z/zwd70cuBEKErhKb0k4syaVYQjmCFjlkiP6 co2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=uX+coHU7; 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 30si1756765edr.255.2020.05.01.06.31.37; Fri, 01 May 2020 06:32:01 -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=uX+coHU7; 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 S1729729AbgEAN3B (ORCPT + 99 others); Fri, 1 May 2020 09:29:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:52326 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729720AbgEAN27 (ORCPT ); Fri, 1 May 2020 09:28:59 -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 52DD92166E; Fri, 1 May 2020 13:28:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588339738; bh=sxF3p7Zg0IrREZE4/Q9IA6NEcnxSI01vA+H+g75AhZw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uX+coHU7E1Df43Wsi/5nPNRYoefi1jjbR7SJQcKTeXhouVTOgyxuFR0sv7Vtn4dIF a9dpUPE1AHL/HYvW3egCOax5JZcoCPuUQYSgFxp0wwLPsYOcvJ30L3rNPns1S4zexu d6Lna4SktXmsAZ10GqwLgkl/Hyc0nzx6EIGT3mpU= 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 4.9 26/80] team: fix hang in team_mode_get() Date: Fri, 1 May 2020 15:21:20 +0200 Message-Id: <20200501131522.995674764@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200501131513.810761598@linuxfoundation.org> References: <20200501131513.810761598@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 @@ -480,6 +480,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) { @@ -495,6 +498,7 @@ static const struct team_mode *team_mode } spin_unlock(&mode_list_lock); + module_put(THIS_MODULE); return mode; }