Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1069245ybl; Wed, 14 Aug 2019 10:12:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqzwGjWKnMd9hLoGCvHQfr+/OmjQz6pmGclA3w6KWeePKxgKp3/ElfJxoL477gWH/+5b7RyX X-Received: by 2002:a63:184b:: with SMTP id 11mr237746pgy.112.1565802725600; Wed, 14 Aug 2019 10:12:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565802725; cv=none; d=google.com; s=arc-20160816; b=u3DeRP0sBAhACcVrcLFJjSBOSMB2NBm0zI51ycuucj4LSwj/Nf8xn6YPLMrdJGb1U4 zdH3gEHDSUL+t21j1OOPn8ZWrjmpKuLxoHcp5UkQzj2K547mp3fDwLoMlo0+jl7XyY64 NgtqHf4PASyKXQc6Y37l0s4zPkplMxgg3nUemZwJW546lW6IyyOO6fdrQKw9LKJ7+tfa XdL5/bejBkcgbvullh6mvxtvloru/zNn5mSP0/pojeweaAwxJFOiCSfzSKyrIVX+4v04 CapeynP+T/PoJslu9cIeilw0iM7QCPO6axQ3+zkik2IA7i0UUbVgxeXJb8LUSQvfURDx L/UA== 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=jKy13uKSmcFG6wqU9XCtNHzjWt7L3g9W5/nFzIKu2AU=; b=N26hs60KAXk20ihJIgS6IefZPIH4Qv6jZfuixTFc09GjVHnN0GT9rhpRVmk/q9I3Zt V+0aj998TH/Ri1CbLGwO7BjVkPn6m9/e1Pvy9MPhHWIeKmqBV4Jjz3ouFlu1FuiCS1Hz Eof182h+BHMrX8oqknUK+JEyNZGy1fLr/veGpBzvKIPnyKwtgjBCTl/u8Yzn5divY1eC BeFP3ULRtSnhWOTNrRZ4WWwIjPL06GxPUqIolJJe/xiwGknm2YqDnPqS3bDiD26EM3at zreSNfgRBKfSfhovLlqTaTUTRmzFRFVBWADE16y2iuozxnEoxfKwDj617EwEgdX749nS jt7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=YR5BW4yl; 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 69si184457pgc.40.2019.08.14.10.11.49; Wed, 14 Aug 2019 10:12:05 -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=YR5BW4yl; 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 S1730358AbfHNRJh (ORCPT + 99 others); Wed, 14 Aug 2019 13:09:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:60028 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730346AbfHNRJf (ORCPT ); Wed, 14 Aug 2019 13:09:35 -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 4A8C52184B; Wed, 14 Aug 2019 17:09:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565802574; bh=YlXoIY1IQSrfXbN+Vgyq2nQzH2ojU50DFZ1Vung4uQI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YR5BW4yl2YXa3ngSlWByMbtFUwwQtuEx7GmeQieoyXODzmQWNHa1cXulSLRyt7mvs sgNbfDIE9p/f/kxks+JRZqMyDh6ehD33l5fIv7QNiD4WH7PbBd76Fjt1YuLAY3r62D 5s7ljjb9Z/hca0rWBNIs6fPCo9q3f0OrPgDxC1yQ= 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.19 33/91] netfilter: nfnetlink: avoid deadlock due to synchronous request_module Date: Wed, 14 Aug 2019 19:00:56 +0200 Message-Id: <20190814165751.105852602@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190814165748.991235624@linuxfoundation.org> References: <20190814165748.991235624@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 916913454624f..7f2c1915763f8 100644 --- a/net/netfilter/nfnetlink.c +++ b/net/netfilter/nfnetlink.c @@ -575,7 +575,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