Skip to content

Commit 2ca794e

Browse files
ebiedermdavem330
authored andcommitted
net sysctl: Initialize the network sysctls sooner to avoid problems.
If the netfilter code is modified to use register_net_sysctl_table the kernel fails to boot because the per net sysctl infrasturce is not setup soon enough. So to avoid races call net_sysctl_init from sock_init(). Signed-off-by: Eric W. Biederman <ebiederm@xmission.com> Acked-by: Pavel Emelyanov <xemul@parallels.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent bc8a369 commit 2ca794e

3 files changed

Lines changed: 12 additions & 2 deletions

File tree

‎include/net/net_namespace.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,11 @@ struct ctl_path;
283283
struct ctl_table;
284284
struct ctl_table_header;
285285

286+
#ifdef CONFIG_SYSCTL
287+
extern int net_sysctl_init(void);
288+
#else
289+
static inline int net_sysctl_init(void) { return 0; }
290+
#endif
286291
extern struct ctl_table_header *register_net_sysctl_table(struct net *net,
287292
const struct ctl_path *path, struct ctl_table *table);
288293
extern struct ctl_table_header *register_net_sysctl_rotable(

‎net/socket.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2524,6 +2524,12 @@ EXPORT_SYMBOL(sock_unregister);
25242524
static int __init sock_init(void)
25252525
{
25262526
int err;
2527+
/*
2528+
* Initialize the network sysctl infrastructure.
2529+
*/
2530+
err = net_sysctl_init();
2531+
if (err)
2532+
goto out;
25272533

25282534
/*
25292535
* Initialize sock SLAB cache.

‎net/sysctl_net.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ static struct pernet_operations sysctl_pernet_ops = {
8989
};
9090

9191
static struct ctl_table_header *net_header;
92-
static __init int net_sysctl_init(void)
92+
__init int net_sysctl_init(void)
9393
{
9494
static struct ctl_table empty[1];
9595
int ret = -ENOMEM;
@@ -109,7 +109,6 @@ static __init int net_sysctl_init(void)
109109
out:
110110
return ret;
111111
}
112-
subsys_initcall(net_sysctl_init);
113112

114113
struct ctl_table_header *register_net_sysctl_table(struct net *net,
115114
const struct ctl_path *path, struct ctl_table *table)

0 commit comments

Comments
 (0)