* [PATCH v2 0/1] net: Fix use of proc_fs @ 2020-12-14 20:25 Yonatan Linik 2020-12-14 20:25 ` [PATCH v2 1/1] " Yonatan Linik 0 siblings, 1 reply; 3+ messages in thread From: Yonatan Linik @ 2020-12-14 20:25 UTC (permalink / raw) To: davem, kuba Cc: ast, daniel, kafai, songliubraving, yhs, andriin, john.fastabend, kpsingh, willemb, john.ogness, arnd, maowenan, colin.king, orcohen, netdev, linux-kernel, bpf, Yonatan Linik This patch fixes the failure of af_packet module initialization when CONFIG_PROC_FS=n. The commit message itself has a pretty thorough explanation. I will just add that I made sure this fixes the problem, both by using socket from userspace and by looking at kernel logs. This also fixes a similar error in tls_proc.c, found by Jakub Kicinski. Yonatan Linik (1): net: Fix use of proc_fs net/packet/af_packet.c | 2 ++ net/tls/tls_proc.c | 3 +++ 2 files changed, 5 insertions(+) base-commit: bbf5c979011a099af5dc76498918ed7df445635b -- 2.25.1 ^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH v2 1/1] net: Fix use of proc_fs 2020-12-14 20:25 [PATCH v2 0/1] net: Fix use of proc_fs Yonatan Linik @ 2020-12-14 20:25 ` Yonatan Linik 2020-12-15 3:41 ` Jakub Kicinski 0 siblings, 1 reply; 3+ messages in thread From: Yonatan Linik @ 2020-12-14 20:25 UTC (permalink / raw) To: davem, kuba Cc: ast, daniel, kafai, songliubraving, yhs, andriin, john.fastabend, kpsingh, willemb, john.ogness, arnd, maowenan, colin.king, orcohen, netdev, linux-kernel, bpf, Yonatan Linik 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 36096f2f4fa0 ("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. Signed-off-by: Yonatan Linik <yonatanlinik@gmail.com> --- net/packet/af_packet.c | 2 ++ net/tls/tls_proc.c | 3 +++ 2 files changed, 5 insertions(+) diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c index 2b33e977a905..031f2b593720 100644 --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c @@ -4612,9 +4612,11 @@ static int __net_init packet_net_init(struct net *net) mutex_init(&net->packet.sklist_lock); INIT_HLIST_HEAD(&net->packet.sklist); +#ifdef CONFIG_PROC_FS if (!proc_create_net("packet", 0, net->proc_net, &packet_seq_ops, sizeof(struct seq_net_private))) return -ENOMEM; +#endif /* CONFIG_PROC_FS */ return 0; } diff --git a/net/tls/tls_proc.c b/net/tls/tls_proc.c index 3a5dd1e07233..feeceb0e4cb4 100644 --- a/net/tls/tls_proc.c +++ b/net/tls/tls_proc.c @@ -37,9 +37,12 @@ static int tls_statistics_seq_show(struct seq_file *seq, void *v) int __net_init tls_proc_init(struct net *net) { +#ifdef CONFIG_PROC_FS if (!proc_create_net_single("tls_stat", 0444, net->proc_net, tls_statistics_seq_show, NULL)) return -ENOMEM; +#endif /* CONFIG_PROC_FS */ + return 0; } -- 2.25.1 ^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2 1/1] net: Fix use of proc_fs 2020-12-14 20:25 ` [PATCH v2 1/1] " Yonatan Linik @ 2020-12-15 3:41 ` Jakub Kicinski 0 siblings, 0 replies; 3+ messages in thread From: Jakub Kicinski @ 2020-12-15 3:41 UTC (permalink / raw) To: Yonatan Linik Cc: davem, ast, daniel, kafai, songliubraving, yhs, andriin, john.fastabend, kpsingh, willemb, john.ogness, arnd, maowenan, colin.king, orcohen, netdev, linux-kernel, bpf On Mon, 14 Dec 2020 22:25:50 +0200 Yonatan Linik wrote: > 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 36096f2f4fa0 ("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. > > Signed-off-by: Yonatan Linik <yonatanlinik@gmail.com> Applied, and queued for stable, thanks! ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-12-15 3:42 UTC | newest] Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2020-12-14 20:25 [PATCH v2 0/1] net: Fix use of proc_fs Yonatan Linik 2020-12-14 20:25 ` [PATCH v2 1/1] " Yonatan Linik 2020-12-15 3:41 ` Jakub Kicinski
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).