Skip to content

Commit 06ab1e6

Browse files
yonatan-linikgregkh
authored andcommitted
net: fix proc_fs init handling in af_packet and tls
[ Upstream commit a268e0f ] proc_fs was used, in af_packet, without a surrounding #ifdef, although there is no hard dependency on proc_fs. That caused the initialization of the af_packet module to fail when CONFIG_PROC_FS=n. Specifically, proc_create_net() was used in af_packet.c, and when it fails, packet_net_init() returns -ENOMEM. It will always fail when the kernel is compiled without proc_fs, because, proc_create_net() for example always returns NULL. The calling order that starts in af_packet.c is as follows: packet_init() register_pernet_subsys() register_pernet_operations() __register_pernet_operations() ops_init() ops->init() (packet_net_ops.init=packet_net_init()) proc_create_net() It worked in the past because register_pernet_subsys()'s return value wasn't checked before this Commit 36096f2 ("packet: Fix error path in packet_init."). It always returned an error, but was not checked before, so everything was working even when CONFIG_PROC_FS=n. The fix here is simply to add the necessary #ifdef. This also fixes a similar error in tls_proc.c, that was found by Jakub Kicinski. Fixes: d26b698 ("net/tls: add skeleton of MIB statistics") Fixes: 36096f2 ("packet: Fix error path in packet_init") Signed-off-by: Yonatan Linik <yonatanlinik@gmail.com> Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent ba2582c commit 06ab1e6

2 files changed

Lines changed: 5 additions & 0 deletions

File tree

‎net/packet/af_packet.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4615,9 +4615,11 @@ static int __net_init packet_net_init(struct net *net)
46154615
mutex_init(&net->packet.sklist_lock);
46164616
INIT_HLIST_HEAD(&net->packet.sklist);
46174617

4618+
#ifdef CONFIG_PROC_FS
46184619
if (!proc_create_net("packet", 0, net->proc_net, &packet_seq_ops,
46194620
sizeof(struct seq_net_private)))
46204621
return -ENOMEM;
4622+
#endif /* CONFIG_PROC_FS */
46214623

46224624
return 0;
46234625
}

‎net/tls/tls_proc.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,12 @@ static int tls_statistics_seq_show(struct seq_file *seq, void *v)
3737

3838
int __net_init tls_proc_init(struct net *net)
3939
{
40+
#ifdef CONFIG_PROC_FS
4041
if (!proc_create_net_single("tls_stat", 0444, net->proc_net,
4142
tls_statistics_seq_show, NULL))
4243
return -ENOMEM;
44+
#endif /* CONFIG_PROC_FS */
45+
4346
return 0;
4447
}
4548

0 commit comments

Comments
 (0)