Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp545209ybl; Fri, 23 Aug 2019 04:58:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqzY8grSPAypvdR1n1xk3pIF642SjhxOdVZWgOteOOccKZffXqCQZSLrCw9TtGpli7Tal0Z0 X-Received: by 2002:a63:3006:: with SMTP id w6mr3676548pgw.440.1566561538785; Fri, 23 Aug 2019 04:58:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566561538; cv=none; d=google.com; s=arc-20160816; b=PcuPgOrpqat/7BB20DR89CxqKfdlYZByT+oQhzY9l0dDP2fnbYxQRvxOhOAh+fQ/DZ +qyfH6H39RHncvs34fie2mq9Q3b7TnDy8URnI0i1R9uEnVT/G5AXbG3zpX9+ntPWlz38 cPZrtcHNQZ5tImEPEzasxHrQOSFprfF89MkQ6KgL6VL8tXnW6yM7zYXwYZFKPAHvEMP6 CJTZvDwBJJKU48VIlDOHsMy2nVvjxd8CE0wq8Cn98Oc3MtpmO27CANNpy8eCaTt3wAo/ Ly70+nYhoiJZviufD1WyANzPDfX94a/R2XOcZh4eaHhxdwrvIfAgNqUj0zkImxPjjvKd BIQg== 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=fSGPuxxNY9FOJ6Z2Yj49D97iskBXtZLk+nseMkda5oY=; b=PxP+b7HVC7eZL+1/kWNk8l8QyoJchvt2UUCxheSv6v8XeGZxKV4T0rC/SdsEUIja9X H8J0EF4Z0xoA05YEQIfbiGXYuh8nBYd9PeMBPLGMoG/KeL4wa3qbPoxQXjILTALvD8qJ qIgXWBkUUEu4x56D0yFqi6hY27o7qaPl1eTlDLDFDufkeGD6OOnJ8/40hNVAZiKF1cIn /UZ+CBTzUoMyJ5iTdx7joUcr3mXRlEkLAl/8/PaI6CXKTLl/xYgmfO13NDUFtDMpOTJV d1dOW1b8wdqFOIbbOtnj3+cswG6VoR/exmw/jhOc2RjBWhqKPOP7cmL4+9sL33JWznIU I9xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=DTYtSXrD; 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 l6si1794529pgg.489.2019.08.23.04.58.42; Fri, 23 Aug 2019 04:58:58 -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=DTYtSXrD; 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 S2393424AbfHVRsF (ORCPT + 99 others); Thu, 22 Aug 2019 13:48:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:40818 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391356AbfHVRWd (ORCPT ); Thu, 22 Aug 2019 13:22:33 -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 4479D21743; Thu, 22 Aug 2019 17:22:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566494553; bh=SjlbYIDq9G0CebwODxm4/BZhdOniFDbdZN/Rfjxiv8M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DTYtSXrDNOPrjp+4mrzJRvm5mEzxa83kEmqkHhXLutDSfe/B0/WcSrGMbqyj+FRDR PeutdcLra9eyPPUOlJYaoIwO0GqVGzx7Gc0XgEj/taCcKKlis6vUoVpSwDNegZtDTW r+Jm6CBApZYar5ma9n7KxCrDlxnSZW0FqHDBbVyI= 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.4 09/78] netfilter: nfnetlink: avoid deadlock due to synchronous request_module Date: Thu, 22 Aug 2019 10:18:13 -0700 Message-Id: <20190822171832.313288206@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190822171832.012773482@linuxfoundation.org> References: <20190822171832.012773482@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 9adedba78eeac..044559c10e98e 100644 --- a/net/netfilter/nfnetlink.c +++ b/net/netfilter/nfnetlink.c @@ -495,7 +495,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