Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp248588ybl; Thu, 22 Aug 2019 23:49:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqz6tvq6shnnYiw6FaHTs2iFILfZqnPE6eAOqJ3N3CtHrein4jUxr03qJ3G0mBdlSq+fBhu+ X-Received: by 2002:a17:902:d70e:: with SMTP id w14mr2867569ply.339.1566542980361; Thu, 22 Aug 2019 23:49:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566542980; cv=none; d=google.com; s=arc-20160816; b=oLcEEB5+8mTMVM8AL1orO1Bbg2XsTrF7lglLoHiyWU2f6KCi2v7E6J2tTW43HvHbXz McukX4y9f6z6/rSchng3QBPDaEl/96w0K8zHGiM8qtPo5FPhOqjCLTNb21W1BGr5fhpx JBqwCb3dAOmS2dhtrXsNZKxmJLOtNydym+tJx/NzbM2c83vwOv93CF/sry24/NoyRbP1 QOMf/1b7XCmEyl7sMwJCJ/cd7C0LmJuGpVTGqBkoIxjU/SddWuWRJTqw3gQD+ZzolVFv WJG6VJf1QWz8nffyG156C2lmnjdsTSZraa5KBrIS7kfl4mma6jh1uFsaHNFc7AEr1PWZ CaTw== 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=z4tDU7yUIsRP+q/hB/hovTPQDVZk9ieoriuVOfGNqlo=; b=EpFIGeFDA//btkjO7MfPW93b17ZlNm00RKYvkfBkBxh53y9R+CwuZaYH47ZPsZfrRF MoCg0/AoGTvTjKvaHD7a09V1DuXrwrrrQ0FaVALc5Svm7YpDxIhORsmMlEZo20Amic5w /Y1rp0UBLRPAWDnygeY6Z6zjZTFwbIEksKMylIz7bygX6jm3xN8ux2IlunTn1lOQtSPu ypnELzvIipehWzEHEeQsrc2Kk7JZhpm5SyEAWB9l6HfXhJzd9AB4ap0qTXgsiRhjOQzv AVaxvxoZ8aaY1ZZrWwRqZFBwVT7URbJLtleb7Lh1lOJ4jSfGeyuTH+SUxee/1AYhkf6c 2YnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=KTKJQ6tM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t6si1543875pjv.81.2019.08.22.23.49.24; Thu, 22 Aug 2019 23:49:40 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=KTKJQ6tM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392861AbfHVRoz (ORCPT + 99 others); Thu, 22 Aug 2019 13:44:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:42712 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403869AbfHVRXN (ORCPT ); Thu, 22 Aug 2019 13:23:13 -0400 Received: from localhost (wsip-184-188-36-2.sd.sd.cox.net [184.188.36.2]) (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 4DF0F23407; Thu, 22 Aug 2019 17:23:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566494592; bh=mOYmqVCbk6H8xdyTBJlt9TLH0hGrZxWq6Vd3l7rgDeM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KTKJQ6tM4EmjuRNor6bdyB2cVNMLRa7fnh5EJueRl12NbMiHZ92kqQNBpVRvSQg3i ++atQHssv6oZTSbXOKOTn+ri4c+aI+GNTkUrV8OgPw9w8D3q1JShCTjOnrjJJ98Sg2 HJrTs/rNPLcNHra3rlczRSjR2URVsPY7Jl6tcvXA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Thomas Jarosch , Juliana Rodrigueiro , Florian Westphal , Pablo Neira Ayuso , Sasha Levin Subject: [PATCH 4.9 012/103] netfilter: nfnetlink: avoid deadlock due to synchronous request_module Date: Thu, 22 Aug 2019 10:18:00 -0700 Message-Id: <20190822171729.349583932@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190822171728.445189830@linuxfoundation.org> References: <20190822171728.445189830@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 [ Upstream commit 1b0890cd60829bd51455dc5ad689ed58c4408227 ] Thomas and Juliana report a deadlock when running: (rmmod nf_conntrack_netlink/xfrm_user) conntrack -e NEW -E & modprobe -v xfrm_user They provided following analysis: conntrack -e NEW -E netlink_bind() netlink_lock_table() -> increases "nl_table_users" nfnetlink_bind() # does not unlock the table as it's locked by netlink_bind() __request_module() call_usermodehelper_exec() This triggers "modprobe nf_conntrack_netlink" from kernel, netlink_bind() won't return until modprobe process is done. "modprobe xfrm_user": xfrm_user_init() register_pernet_subsys() -> grab pernet_ops_rwsem .. netlink_table_grab() calls schedule() as "nl_table_users" is non-zero so modprobe is blocked because netlink_bind() increased nl_table_users while also holding pernet_ops_rwsem. "modprobe nf_conntrack_netlink" runs and inits nf_conntrack_netlink: ctnetlink_init() register_pernet_subsys() -> blocks on "pernet_ops_rwsem" thanks to xfrm_user module both modprobe processes wait on one another -- neither can make progress. Switch netlink_bind() to "nowait" modprobe -- this releases the netlink table lock, which then allows both modprobe instances to complete. Reported-by: Thomas Jarosch Reported-by: Juliana Rodrigueiro Signed-off-by: Florian Westphal Signed-off-by: Pablo Neira Ayuso Signed-off-by: Sasha Levin --- net/netfilter/nfnetlink.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/netfilter/nfnetlink.c b/net/netfilter/nfnetlink.c index 2278d9ab723bf..9837a61cb3e3b 100644 --- a/net/netfilter/nfnetlink.c +++ b/net/netfilter/nfnetlink.c @@ -490,7 +490,7 @@ static int nfnetlink_bind(struct net *net, int group) ss = nfnetlink_get_subsys(type << 8); rcu_read_unlock(); if (!ss) - request_module("nfnetlink-subsys-%d", type); + request_module_nowait("nfnetlink-subsys-%d", type); return 0; } #endif -- 2.20.1