forked from Minki/linux
9cf1cd8ee3
In order to set/get/dump, the tipc uses the generic netlink infrastructure. So, when tipc module is inserted, init function calls genl_register_family(). After genl_register_family(), set/get/dump commands are immediately allowed and these callbacks internally use the net_generic. net_generic is allocated by register_pernet_device() but this is called after genl_register_family() in the __init function. So, these callbacks would use un-initialized net_generic. Test commands: #SHELL1 while : do modprobe tipc modprobe -rv tipc done #SHELL2 while : do tipc link list done Splat looks like: [ 59.616322][ T2788] kasan: CONFIG_KASAN_INLINE enabled [ 59.617234][ T2788] kasan: GPF could be caused by NULL-ptr deref or user memory access [ 59.618398][ T2788] general protection fault: 0000 [#1] SMP DEBUG_PAGEALLOC KASAN PTI [ 59.619389][ T2788] CPU: 3 PID: 2788 Comm: tipc Not tainted 5.4.0+ #194 [ 59.620231][ T2788] Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006 [ 59.621428][ T2788] RIP: 0010:tipc_bcast_get_broadcast_mode+0x131/0x310 [tipc] [ 59.622379][ T2788] Code: c7 c6 ef 8b 38 c0 65 ff 0d 84 83 c9 3f e8 d7 a5 f2 e3 48 8d bb 38 11 00 00 48 b8 00 00 00 00 [ 59.622550][ T2780] NET: Registered protocol family 30 [ 59.624627][ T2788] RSP: 0018:ffff88804b09f578 EFLAGS: 00010202 [ 59.624630][ T2788] RAX: dffffc0000000000 RBX: 0000000000000011 RCX: 000000008bc66907 [ 59.624631][ T2788] RDX: 0000000000000229 RSI: 000000004b3cf4cc RDI: 0000000000001149 [ 59.624633][ T2788] RBP: ffff88804b09f588 R08: 0000000000000003 R09: fffffbfff4fb3df1 [ 59.624635][ T2788] R10: fffffbfff50318f8 R11: ffff888066cadc18 R12: ffffffffa6cc2f40 [ 59.624637][ T2788] R13: 1ffff11009613eba R14: ffff8880662e9328 R15: ffff8880662e9328 [ 59.624639][ T2788] FS: 00007f57d8f7b740(0000) GS:ffff88806cc00000(0000) knlGS:0000000000000000 [ 59.624645][ T2788] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 59.625875][ T2780] tipc: Started in single node mode [ 59.626128][ T2788] CR2: 00007f57d887a8c0 CR3: 000000004b140002 CR4: 00000000000606e0 [ 59.633991][ T2788] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [ 59.635195][ T2788] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 [ 59.636478][ T2788] Call Trace: [ 59.637025][ T2788] tipc_nl_add_bc_link+0x179/0x1470 [tipc] [ 59.638219][ T2788] ? lock_downgrade+0x6e0/0x6e0 [ 59.638923][ T2788] ? __tipc_nl_add_link+0xf90/0xf90 [tipc] [ 59.639533][ T2788] ? tipc_nl_node_dump_link+0x318/0xa50 [tipc] [ 59.640160][ T2788] ? mutex_lock_io_nested+0x1380/0x1380 [ 59.640746][ T2788] tipc_nl_node_dump_link+0x4fd/0xa50 [tipc] [ 59.641356][ T2788] ? tipc_nl_node_reset_link_stats+0x340/0x340 [tipc] [ 59.642088][ T2788] ? __skb_ext_del+0x270/0x270 [ 59.642594][ T2788] genl_lock_dumpit+0x85/0xb0 [ 59.643050][ T2788] netlink_dump+0x49c/0xed0 [ 59.643529][ T2788] ? __netlink_sendskb+0xc0/0xc0 [ 59.644044][ T2788] ? __netlink_dump_start+0x190/0x800 [ 59.644617][ T2788] ? __mutex_unlock_slowpath+0xd0/0x670 [ 59.645177][ T2788] __netlink_dump_start+0x5a0/0x800 [ 59.645692][ T2788] genl_rcv_msg+0xa75/0xe90 [ 59.646144][ T2788] ? __lock_acquire+0xdfe/0x3de0 [ 59.646692][ T2788] ? genl_family_rcv_msg_attrs_parse+0x320/0x320 [ 59.647340][ T2788] ? genl_lock_dumpit+0xb0/0xb0 [ 59.647821][ T2788] ? genl_unlock+0x20/0x20 [ 59.648290][ T2788] ? genl_parallel_done+0xe0/0xe0 [ 59.648787][ T2788] ? find_held_lock+0x39/0x1d0 [ 59.649276][ T2788] ? genl_rcv+0x15/0x40 [ 59.649722][ T2788] ? lock_contended+0xcd0/0xcd0 [ 59.650296][ T2788] netlink_rcv_skb+0x121/0x350 [ 59.650828][ T2788] ? genl_family_rcv_msg_attrs_parse+0x320/0x320 [ 59.651491][ T2788] ? netlink_ack+0x940/0x940 [ 59.651953][ T2788] ? lock_acquire+0x164/0x3b0 [ 59.652449][ T2788] genl_rcv+0x24/0x40 [ 59.652841][ T2788] netlink_unicast+0x421/0x600 [ ... ] Fixes:7e43690578
("tipc: fix a slab object leak") Fixes:a62fbccecd
("tipc: make subscriber server support net namespace") Signed-off-by: Taehee Yoo <ap420073@gmail.com> Acked-by: Jon Maloy <jon.maloy@ericsson.com> Signed-off-by: David S. Miller <davem@davemloft.net>
225 lines
5.7 KiB
C
225 lines
5.7 KiB
C
/*
|
|
* net/tipc/core.c: TIPC module code
|
|
*
|
|
* Copyright (c) 2003-2006, 2013, Ericsson AB
|
|
* Copyright (c) 2005-2006, 2010-2013, Wind River Systems
|
|
* All rights reserved.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions are met:
|
|
*
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
* notice, this list of conditions and the following disclaimer.
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
* documentation and/or other materials provided with the distribution.
|
|
* 3. Neither the names of the copyright holders nor the names of its
|
|
* contributors may be used to endorse or promote products derived from
|
|
* this software without specific prior written permission.
|
|
*
|
|
* Alternatively, this software may be distributed under the terms of the
|
|
* GNU General Public License ("GPL") version 2 as published by the Free
|
|
* Software Foundation.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
*/
|
|
|
|
#include "core.h"
|
|
#include "name_table.h"
|
|
#include "subscr.h"
|
|
#include "bearer.h"
|
|
#include "net.h"
|
|
#include "socket.h"
|
|
#include "bcast.h"
|
|
#include "node.h"
|
|
#include "crypto.h"
|
|
|
|
#include <linux/module.h>
|
|
|
|
/* configurable TIPC parameters */
|
|
unsigned int tipc_net_id __read_mostly;
|
|
int sysctl_tipc_rmem[3] __read_mostly; /* min/default/max */
|
|
|
|
static int __net_init tipc_init_net(struct net *net)
|
|
{
|
|
struct tipc_net *tn = net_generic(net, tipc_net_id);
|
|
int err;
|
|
|
|
tn->net_id = 4711;
|
|
tn->node_addr = 0;
|
|
tn->trial_addr = 0;
|
|
tn->addr_trial_end = 0;
|
|
tn->capabilities = TIPC_NODE_CAPABILITIES;
|
|
memset(tn->node_id, 0, sizeof(tn->node_id));
|
|
memset(tn->node_id_string, 0, sizeof(tn->node_id_string));
|
|
tn->mon_threshold = TIPC_DEF_MON_THRESHOLD;
|
|
get_random_bytes(&tn->random, sizeof(int));
|
|
INIT_LIST_HEAD(&tn->node_list);
|
|
spin_lock_init(&tn->node_list_lock);
|
|
|
|
#ifdef CONFIG_TIPC_CRYPTO
|
|
err = tipc_crypto_start(&tn->crypto_tx, net, NULL);
|
|
if (err)
|
|
goto out_crypto;
|
|
#endif
|
|
err = tipc_sk_rht_init(net);
|
|
if (err)
|
|
goto out_sk_rht;
|
|
|
|
err = tipc_nametbl_init(net);
|
|
if (err)
|
|
goto out_nametbl;
|
|
|
|
INIT_LIST_HEAD(&tn->dist_queue);
|
|
|
|
err = tipc_bcast_init(net);
|
|
if (err)
|
|
goto out_bclink;
|
|
|
|
err = tipc_attach_loopback(net);
|
|
if (err)
|
|
goto out_bclink;
|
|
|
|
return 0;
|
|
|
|
out_bclink:
|
|
tipc_nametbl_stop(net);
|
|
out_nametbl:
|
|
tipc_sk_rht_destroy(net);
|
|
out_sk_rht:
|
|
|
|
#ifdef CONFIG_TIPC_CRYPTO
|
|
tipc_crypto_stop(&tn->crypto_tx);
|
|
out_crypto:
|
|
#endif
|
|
return err;
|
|
}
|
|
|
|
static void __net_exit tipc_exit_net(struct net *net)
|
|
{
|
|
tipc_detach_loopback(net);
|
|
tipc_net_stop(net);
|
|
tipc_bcast_stop(net);
|
|
tipc_nametbl_stop(net);
|
|
tipc_sk_rht_destroy(net);
|
|
#ifdef CONFIG_TIPC_CRYPTO
|
|
tipc_crypto_stop(&tipc_net(net)->crypto_tx);
|
|
#endif
|
|
}
|
|
|
|
static void __net_exit tipc_pernet_pre_exit(struct net *net)
|
|
{
|
|
tipc_node_pre_cleanup_net(net);
|
|
}
|
|
|
|
static struct pernet_operations tipc_pernet_pre_exit_ops = {
|
|
.pre_exit = tipc_pernet_pre_exit,
|
|
};
|
|
|
|
static struct pernet_operations tipc_net_ops = {
|
|
.init = tipc_init_net,
|
|
.exit = tipc_exit_net,
|
|
.id = &tipc_net_id,
|
|
.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;
|
|
|
|
pr_info("Activated (version " TIPC_MOD_VER ")\n");
|
|
|
|
sysctl_tipc_rmem[0] = RCVBUF_MIN;
|
|
sysctl_tipc_rmem[1] = RCVBUF_DEF;
|
|
sysctl_tipc_rmem[2] = RCVBUF_MAX;
|
|
|
|
err = tipc_register_sysctl();
|
|
if (err)
|
|
goto out_sysctl;
|
|
|
|
err = register_pernet_device(&tipc_net_ops);
|
|
if (err)
|
|
goto out_pernet;
|
|
|
|
err = tipc_socket_init();
|
|
if (err)
|
|
goto out_socket;
|
|
|
|
err = register_pernet_device(&tipc_topsrv_net_ops);
|
|
if (err)
|
|
goto out_pernet_topsrv;
|
|
|
|
err = register_pernet_subsys(&tipc_pernet_pre_exit_ops);
|
|
if (err)
|
|
goto out_register_pernet_subsys;
|
|
|
|
err = tipc_bearer_setup();
|
|
if (err)
|
|
goto out_bearer;
|
|
|
|
err = tipc_netlink_start();
|
|
if (err)
|
|
goto out_netlink;
|
|
|
|
err = tipc_netlink_compat_start();
|
|
if (err)
|
|
goto out_netlink_compat;
|
|
|
|
pr_info("Started in single node mode\n");
|
|
return 0;
|
|
|
|
out_netlink_compat:
|
|
tipc_netlink_stop();
|
|
out_netlink:
|
|
tipc_bearer_cleanup();
|
|
out_bearer:
|
|
unregister_pernet_subsys(&tipc_pernet_pre_exit_ops);
|
|
out_register_pernet_subsys:
|
|
unregister_pernet_device(&tipc_topsrv_net_ops);
|
|
out_pernet_topsrv:
|
|
tipc_socket_stop();
|
|
out_socket:
|
|
unregister_pernet_device(&tipc_net_ops);
|
|
out_pernet:
|
|
tipc_unregister_sysctl();
|
|
out_sysctl:
|
|
pr_err("Unable to start in single node mode\n");
|
|
return err;
|
|
}
|
|
|
|
static void __exit tipc_exit(void)
|
|
{
|
|
tipc_netlink_compat_stop();
|
|
tipc_netlink_stop();
|
|
tipc_bearer_cleanup();
|
|
unregister_pernet_subsys(&tipc_pernet_pre_exit_ops);
|
|
unregister_pernet_device(&tipc_topsrv_net_ops);
|
|
tipc_socket_stop();
|
|
unregister_pernet_device(&tipc_net_ops);
|
|
tipc_unregister_sysctl();
|
|
|
|
pr_info("Deactivated\n");
|
|
}
|
|
|
|
module_init(tipc_init);
|
|
module_exit(tipc_exit);
|
|
|
|
MODULE_DESCRIPTION("TIPC: Transparent Inter Process Communication");
|
|
MODULE_LICENSE("Dual BSD/GPL");
|
|
MODULE_VERSION(TIPC_MOD_VER);
|