Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1061356ybl; Wed, 14 Aug 2019 10:05:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqxwCr5MRB7DxcWekxVnd5WOlhcqrhj+bAv7mpVRarh2ZMCOcTjkGSbzVJitJkTjQrE6fthN X-Received: by 2002:a17:902:4623:: with SMTP id o32mr415464pld.112.1565802347735; Wed, 14 Aug 2019 10:05:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565802347; cv=none; d=google.com; s=arc-20160816; b=0J0K97F1kjSNEK/Z2rgmEBIhrQMb6wtXnpL7i0x/eOX3v0gfoWcpgmoFQOCWGYs1Ya 96SBVRFahVWL9MVV4RxYpFa+SOoCWarjsS0GbzCFXllpCnWl21gIpvmPROdFkHxWBO0Z QdAa8rbwUKz/BLlqQ3ASXN/zeynU6Jkd1qDhCaXSCV8GX1l582g9/BAaOUTlbatc3InK rv3WTLk6lNDmMuUNZ8qgQmpN5Cc5QwgB8KmVPTosyoe75ULpExcU0XssI/idQI4uDMTd ggYVYLZ/VpKSjIJHm8tObxRNP6eEaVRF86Xg8vzKontPPfhd9m4YMdSSes9ruNEnI9z1 S2Fw== 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=XTIs61RX7Pnh+psXUcU0JBzSEbCtVB4WAmlRoEDFMPQ=; b=ITNt9PNZ7UpT5tRDLcj1BNqfoRTObr9+/oNzytrCnoC+X7zsW6Os9y8u2zAsDlJWgc Th9szp/ssxFw5OOwnGr7uR5PsjfEPoKTgak/nmJld3SBr5pnDyuWtpWKNI78hfvm8UOD sQ7OQ1SO63Ni6sRNpjo2Z8fXdzxhL3ga/L6cvwttWZClDpaeErpN5SAUdpMejO7hueqr rYd4xYpOQoyrdD48UcjFQlhE5eaI5V2FFMrtUAVLTJC/oOmjlDd3KSyiZ0KJGLcCQ3NV Y85TEx7nDUhyUO/n8mNCg3YtQ3eQFx2xBN3mO1671Co6Bp5D4rR9BCakmIGRJMgpEj6M tu/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ckNYV4Zf; 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 15si180149pgu.98.2019.08.14.10.05.31; Wed, 14 Aug 2019 10:05:47 -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=ckNYV4Zf; 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 S1729154AbfHNREM (ORCPT + 99 others); Wed, 14 Aug 2019 13:04:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:52902 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729112AbfHNREG (ORCPT ); Wed, 14 Aug 2019 13:04:06 -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 3BD092084D; Wed, 14 Aug 2019 17:04:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565802245; bh=mkd3jcm/2eaT88z+vZH8zv8REeNY7nMjafvMO45SvGA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ckNYV4ZfF/gD2/Fc3MAtcmgPbljkBN83ekYoKqYCV48biEuEw+U4kU44fxdOrQvFN wwqVZTfNi8xnTcrlYWEAKdKQKuihuS9kmeYOlSs8x4shD7EO1LKrl0ygA8uotOAyKM ZkjQzuQIG/pi6KidOlgPWYVodg8rmnZJPXj3sNtg= 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 5.2 050/144] netfilter: nfnetlink: avoid deadlock due to synchronous request_module Date: Wed, 14 Aug 2019 19:00:06 +0200 Message-Id: <20190814165801.921500244@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190814165759.466811854@linuxfoundation.org> References: <20190814165759.466811854@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 92077d4591090..4abbb452cf6c6 100644 --- a/net/netfilter/nfnetlink.c +++ b/net/netfilter/nfnetlink.c @@ -578,7 +578,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