Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp348225ybi; Fri, 7 Jun 2019 09:02:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqzFmbxDL/VUiwFyThxrWH3gZKKr0XvUP6aPJ3YZYGRpAT8lE3JeLW0NJ0Kk94fOg6QsvX6J X-Received: by 2002:a62:ce07:: with SMTP id y7mr31869394pfg.12.1559923333880; Fri, 07 Jun 2019 09:02:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559923333; cv=none; d=google.com; s=arc-20160816; b=vl/YDXKTqmu1+UgxKI2pxYXRZqLjnrQKKqSXblU5/H/+5Uy3vt9a7ZBEzf+2979yH0 PW5/yYxtHrGdm8rZMQsrIPS25G8DH95yhysT6ctTRUZukLvKguuxtHUfygF3z6b12Gem HC75KVPaHjlLRVn4VmNRUYV6v0WQR5gZL43PppJW6NwDee8XcOKzZc0RAyAHAVQdA2Kq sh3GI0W5FH5Wh/W/DZIm39ITC7WW9668Cpk6+BzWdGohiCH6KB5ukqDqu/kSKriq3sFA +t0qpxocYFkNWBKE6eLMoAhBkxI6CZsQ5wcOoZ3rXEOoDBwmSlrFb5tDHBiHlxGmxuLj rYEw== 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=8B56RF1JYKcJE0ExAyHqO47MAaaW51FaKFA+gvisQ/k=; b=eZ/ubAfTD1tdDQgJSqw0kM1vL/jv+l9HCsf1fxhGVVzj7seGAbqanfRhN2VKnFy8zO uYzCcRksx6au0p4i8Z/H7y7VcwBfgKKn2WvRjEWOMbqRdyMTNFouR7qZGCKhurrUX6SH MowHViEwyyACJx/+mlih2FH7RUJVKEoP+iaqXUBnPWOSd5BScnw2SG4euMHWS2Wo3cBH u1SqHy+HbCAgxYtIBBCXWyMkpjUJ2F/cRSNfz0iCk0qvXHhZ3ncZsAislz6bA6zxodP9 V7xZtBC+BTRKAPQ79Hg9fOgRJgYGAlR/K+e3hxQQSSJtqj+xgD3Z3lmXq9BItYGfTw3z Y1rQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="EUqBSv+/"; 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 u1si2084129pls.194.2019.06.07.09.01.56; Fri, 07 Jun 2019 09:02:13 -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="EUqBSv+/"; 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 S1730165AbfFGPkz (ORCPT + 99 others); Fri, 7 Jun 2019 11:40:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:50312 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730135AbfFGPky (ORCPT ); Fri, 7 Jun 2019 11:40:54 -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 2AA182133D; Fri, 7 Jun 2019 15:40:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1559922052; bh=5NxK3QZ4xXv0053/H9qoIGNYWfFSdPg+TupU4k+I13s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EUqBSv+/ro2oenqXmWnE3iALsxmBZyzQ7xhyocVtP5024dlWyj9Nb4o4bIjU9E/kt oHXrRN1DIhWKQvQ5sI85oT1pWWkeJOmouAJd+O0S2VrpKQoIlJoScueZ9543Pr8CTH KrPubBaqtE7UcuYFAw5PynZ46K+oWUylOJmnOGRw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Junwei Hu , Wang Wang , syzbot+1e8114b61079bfe9cbc5@syzkaller.appspotmail.com, Kang Zhou , Suanming Mou , "David S. Miller" Subject: [PATCH 4.14 20/69] tipc: fix modprobe tipc failed after switch order of device registration Date: Fri, 7 Jun 2019 17:39:01 +0200 Message-Id: <20190607153850.851689067@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190607153848.271562617@linuxfoundation.org> References: <20190607153848.271562617@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: Junwei Hu commit 526f5b851a96566803ee4bee60d0a34df56c77f8 upstream. Error message printed: modprobe: ERROR: could not insert 'tipc': Address family not supported by protocol. when modprobe tipc after the following patch: switch order of device registration, commit 7e27e8d6130c ("tipc: switch order of device registration to fix a crash") Because sock_create_kern(net, AF_TIPC, ...) called by tipc_topsrv_create_listener() in the initialization process of tipc_init_net(), so tipc_socket_init() must be execute before that. Meanwhile, tipc_net_id need to be initialized when sock_create() called, and tipc_socket_init() is no need to be called for each namespace. I add a variable tipc_topsrv_net_ops, and split the register_pernet_subsys() of tipc into two parts, and split tipc_socket_init() with initialization of pernet params. By the way, I fixed resources rollback error when tipc_bcast_init() failed in tipc_init_net(). Fixes: 7e27e8d6130c ("tipc: switch order of device registration to fix a crash") Signed-off-by: Junwei Hu Reported-by: Wang Wang Reported-by: syzbot+1e8114b61079bfe9cbc5@syzkaller.appspotmail.com Reviewed-by: Kang Zhou Reviewed-by: Suanming Mou Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/tipc/core.c | 18 ++++++++++++------ net/tipc/subscr.c | 14 ++++++++++++-- net/tipc/subscr.h | 5 +++-- 3 files changed, 27 insertions(+), 10 deletions(-) --- a/net/tipc/core.c +++ b/net/tipc/core.c @@ -71,9 +71,6 @@ static int __net_init tipc_init_net(stru goto out_nametbl; INIT_LIST_HEAD(&tn->dist_queue); - err = tipc_topsrv_start(net); - if (err) - goto out_subscr; err = tipc_bcast_init(net); if (err) @@ -82,8 +79,6 @@ static int __net_init tipc_init_net(stru return 0; out_bclink: - tipc_bcast_stop(net); -out_subscr: tipc_nametbl_stop(net); out_nametbl: tipc_sk_rht_destroy(net); @@ -93,7 +88,6 @@ out_sk_rht: static void __net_exit tipc_exit_net(struct net *net) { - tipc_topsrv_stop(net); tipc_net_stop(net); tipc_bcast_stop(net); tipc_nametbl_stop(net); @@ -107,6 +101,11 @@ static struct pernet_operations tipc_net .size = sizeof(struct tipc_net), }; +static struct pernet_operations tipc_topsrv_net_ops = { + .init = tipc_topsrv_init_net, + .exit = tipc_topsrv_exit_net, +}; + static int __init tipc_init(void) { int err; @@ -137,6 +136,10 @@ static int __init tipc_init(void) if (err) goto out_socket; + err = register_pernet_subsys(&tipc_topsrv_net_ops); + if (err) + goto out_pernet_topsrv; + err = tipc_bearer_setup(); if (err) goto out_bearer; @@ -144,6 +147,8 @@ static int __init tipc_init(void) pr_info("Started in single node mode\n"); return 0; out_bearer: + unregister_pernet_subsys(&tipc_topsrv_net_ops); +out_pernet_topsrv: tipc_socket_stop(); out_socket: unregister_pernet_subsys(&tipc_net_ops); @@ -161,6 +166,7 @@ out_netlink: static void __exit tipc_exit(void) { tipc_bearer_cleanup(); + unregister_pernet_subsys(&tipc_topsrv_net_ops); tipc_socket_stop(); unregister_pernet_subsys(&tipc_net_ops); tipc_netlink_stop(); --- a/net/tipc/subscr.c +++ b/net/tipc/subscr.c @@ -344,7 +344,7 @@ static void *tipc_subscrb_connect_cb(int return (void *)tipc_subscrb_create(conid); } -int tipc_topsrv_start(struct net *net) +static int tipc_topsrv_start(struct net *net) { struct tipc_net *tn = net_generic(net, tipc_net_id); const char name[] = "topology_server"; @@ -382,7 +382,7 @@ int tipc_topsrv_start(struct net *net) return tipc_server_start(topsrv); } -void tipc_topsrv_stop(struct net *net) +static void tipc_topsrv_stop(struct net *net) { struct tipc_net *tn = net_generic(net, tipc_net_id); struct tipc_server *topsrv = tn->topsrv; @@ -391,3 +391,13 @@ void tipc_topsrv_stop(struct net *net) kfree(topsrv->saddr); kfree(topsrv); } + +int __net_init tipc_topsrv_init_net(struct net *net) +{ + return tipc_topsrv_start(net); +} + +void __net_exit tipc_topsrv_exit_net(struct net *net) +{ + tipc_topsrv_stop(net); +} --- a/net/tipc/subscr.h +++ b/net/tipc/subscr.h @@ -75,8 +75,9 @@ void tipc_subscrp_report_overlap(struct void tipc_subscrp_convert_seq(struct tipc_name_seq *in, int swap, struct tipc_name_seq *out); u32 tipc_subscrp_convert_seq_type(u32 type, int swap); -int tipc_topsrv_start(struct net *net); -void tipc_topsrv_stop(struct net *net); + +int __net_init tipc_topsrv_init_net(struct net *net); +void __net_exit tipc_topsrv_exit_net(struct net *net); void tipc_subscrp_put(struct tipc_subscription *subscription); void tipc_subscrp_get(struct tipc_subscription *subscription);