From mboxrd@z Thu Jan 1 00:00:00 1970 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=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 BAD9CC4724C for ; Fri, 1 May 2020 13:25:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 93D5E2166E for ; Fri, 1 May 2020 13:25:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588339531; bh=JKQ6wz+eGWo5hdvREwLll1q2jrhw56Idnov0rBRloPM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=j4rOXyXfiZKqyNs2OlsYmvGuQbd2ADy/Gf6/Aubs8lL0fjVtPD8dETCOylbzNSVHv nzYHOU/nVsL3F3AxDiu3k0bT5wMkYDaU2T4JBxzR82n2ohVSeYoVD4yxtJe33ei1Kk CsMOzi1fZOJilRRMpjBXd1+sz36pMaEqIIGoXUII= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729032AbgEANZa (ORCPT ); Fri, 1 May 2020 09:25:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:46232 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728979AbgEANZW (ORCPT ); Fri, 1 May 2020 09:25:22 -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 999682166E; Fri, 1 May 2020 13:25:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588339522; bh=JKQ6wz+eGWo5hdvREwLll1q2jrhw56Idnov0rBRloPM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Yb+6MVoS5vynx6bU5r5SMelNVDLIaP4ogOq+TNOkCsI27vC2ns8hp49jTAde8o4DS gcmrVs6KMSkojCZHCYUtpXJdZvIKZPCkofhSLkQnAJRJp0BtGlabU1geCIwuS4DR+D qZEPq6yR51WRLeteAoNT8FHqEp9T1KWKrpc3YeT4= 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.4 23/70] team: fix hang in team_mode_get() Date: Fri, 1 May 2020 15:21:11 +0200 Message-Id: <20200501131521.510712054@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200501131513.302599262@linuxfoundation.org> References: <20200501131513.302599262@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 @@ -466,6 +466,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) { @@ -481,6 +484,7 @@ static const struct team_mode *team_mode } spin_unlock(&mode_list_lock); + module_put(THIS_MODULE); return mode; }