Merge branch 'appletalk-small-cleanup-and-bugfix'

Yue Haibing says:

====================
appletalk: small cleanup and bugfix

v2:
- Add cover letter log

This patch series mainly fix a use-after-free bug in atalk_proc_exit.
patch 1 use remove_proc_subtree helper to simplify atalk_proc fs code,
also some other cleanup.
patch 2 add proper error cleanup path in atalk_init to fix the issue, which
based on the patch 1 because of the change of atalk_proc_exit context.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
David S. Miller 2019-03-03 13:01:49 -08:00
Родитель 084e5bb16b 6377f787ae
Коммит 9b1b4c0037
4 изменённых файлов: 54 добавлений и 48 удалений

Просмотреть файл

@ -158,7 +158,7 @@ extern int sysctl_aarp_retransmit_limit;
extern int sysctl_aarp_resolve_time;
#ifdef CONFIG_SYSCTL
extern void atalk_register_sysctl(void);
extern int atalk_register_sysctl(void);
extern void atalk_unregister_sysctl(void);
#else
#define atalk_register_sysctl() do { } while(0)

Просмотреть файл

@ -210,56 +210,34 @@ static const struct seq_operations atalk_seq_socket_ops = {
.show = atalk_seq_socket_show,
};
static struct proc_dir_entry *atalk_proc_dir;
int __init atalk_proc_init(void)
{
struct proc_dir_entry *p;
int rc = -ENOMEM;
if (!proc_mkdir("atalk", init_net.proc_net))
return -ENOMEM;
atalk_proc_dir = proc_mkdir("atalk", init_net.proc_net);
if (!atalk_proc_dir)
if (!proc_create_seq("atalk/interface", 0444, init_net.proc_net,
&atalk_seq_interface_ops))
goto out;
p = proc_create_seq("interface", 0444, atalk_proc_dir,
&atalk_seq_interface_ops);
if (!p)
goto out_interface;
if (!proc_create_seq("atalk/route", 0444, init_net.proc_net,
&atalk_seq_route_ops))
goto out;
p = proc_create_seq("route", 0444, atalk_proc_dir,
&atalk_seq_route_ops);
if (!p)
goto out_route;
if (!proc_create_seq("atalk/socket", 0444, init_net.proc_net,
&atalk_seq_socket_ops))
goto out;
p = proc_create_seq("socket", 0444, atalk_proc_dir,
&atalk_seq_socket_ops);
if (!p)
goto out_socket;
if (!proc_create_seq_private("atalk/arp", 0444, init_net.proc_net,
&aarp_seq_ops,
sizeof(struct aarp_iter_state), NULL))
goto out;
p = proc_create_seq_private("arp", 0444, atalk_proc_dir, &aarp_seq_ops,
sizeof(struct aarp_iter_state), NULL);
if (!p)
goto out_arp;
rc = 0;
out:
return rc;
out_arp:
remove_proc_entry("socket", atalk_proc_dir);
out_socket:
remove_proc_entry("route", atalk_proc_dir);
out_route:
remove_proc_entry("interface", atalk_proc_dir);
out_interface:
remove_proc_entry("atalk", init_net.proc_net);
goto out;
remove_proc_subtree("atalk", init_net.proc_net);
return -ENOMEM;
}
void __exit atalk_proc_exit(void)
void atalk_proc_exit(void)
{
remove_proc_entry("interface", atalk_proc_dir);
remove_proc_entry("route", atalk_proc_dir);
remove_proc_entry("socket", atalk_proc_dir);
remove_proc_entry("arp", atalk_proc_dir);
remove_proc_entry("atalk", init_net.proc_net);
remove_proc_subtree("atalk", init_net.proc_net);
}

Просмотреть файл

@ -1910,12 +1910,16 @@ static const char atalk_err_snap[] __initconst =
/* Called by proto.c on kernel start up */
static int __init atalk_init(void)
{
int rc = proto_register(&ddp_proto, 0);
int rc;
if (rc != 0)
rc = proto_register(&ddp_proto, 0);
if (rc)
goto out;
(void)sock_register(&atalk_family_ops);
rc = sock_register(&atalk_family_ops);
if (rc)
goto out_proto;
ddp_dl = register_snap_client(ddp_snap_id, atalk_rcv);
if (!ddp_dl)
printk(atalk_err_snap);
@ -1923,12 +1927,33 @@ static int __init atalk_init(void)
dev_add_pack(&ltalk_packet_type);
dev_add_pack(&ppptalk_packet_type);
register_netdevice_notifier(&ddp_notifier);
rc = register_netdevice_notifier(&ddp_notifier);
if (rc)
goto out_sock;
aarp_proto_init();
atalk_proc_init();
atalk_register_sysctl();
rc = atalk_proc_init();
if (rc)
goto out_aarp;
rc = atalk_register_sysctl();
if (rc)
goto out_proc;
out:
return rc;
out_proc:
atalk_proc_exit();
out_aarp:
aarp_cleanup_module();
unregister_netdevice_notifier(&ddp_notifier);
out_sock:
dev_remove_pack(&ppptalk_packet_type);
dev_remove_pack(&ltalk_packet_type);
unregister_snap_client(ddp_dl);
sock_unregister(PF_APPLETALK);
out_proto:
proto_unregister(&ddp_proto);
goto out;
}
module_init(atalk_init);

Просмотреть файл

@ -45,9 +45,12 @@ static struct ctl_table atalk_table[] = {
static struct ctl_table_header *atalk_table_header;
void atalk_register_sysctl(void)
int __init atalk_register_sysctl(void)
{
atalk_table_header = register_net_sysctl(&init_net, "net/appletalk", atalk_table);
if (!atalk_table_header)
return -ENOMEM;
return 0;
}
void atalk_unregister_sysctl(void)