Commit 9b1b4c00 authored by David S. Miller's avatar David S. Miller

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: default avatarDavid S. Miller <davem@davemloft.net>
parents 084e5bb1 6377f787
...@@ -158,7 +158,7 @@ extern int sysctl_aarp_retransmit_limit; ...@@ -158,7 +158,7 @@ extern int sysctl_aarp_retransmit_limit;
extern int sysctl_aarp_resolve_time; extern int sysctl_aarp_resolve_time;
#ifdef CONFIG_SYSCTL #ifdef CONFIG_SYSCTL
extern void atalk_register_sysctl(void); extern int atalk_register_sysctl(void);
extern void atalk_unregister_sysctl(void); extern void atalk_unregister_sysctl(void);
#else #else
#define atalk_register_sysctl() do { } while(0) #define atalk_register_sysctl() do { } while(0)
......
...@@ -210,56 +210,34 @@ static const struct seq_operations atalk_seq_socket_ops = { ...@@ -210,56 +210,34 @@ static const struct seq_operations atalk_seq_socket_ops = {
.show = atalk_seq_socket_show, .show = atalk_seq_socket_show,
}; };
static struct proc_dir_entry *atalk_proc_dir;
int __init atalk_proc_init(void) int __init atalk_proc_init(void)
{ {
struct proc_dir_entry *p; if (!proc_mkdir("atalk", init_net.proc_net))
int rc = -ENOMEM; return -ENOMEM;
atalk_proc_dir = proc_mkdir("atalk", init_net.proc_net); if (!proc_create_seq("atalk/interface", 0444, init_net.proc_net,
if (!atalk_proc_dir) &atalk_seq_interface_ops))
goto out; goto out;
p = proc_create_seq("interface", 0444, atalk_proc_dir, if (!proc_create_seq("atalk/route", 0444, init_net.proc_net,
&atalk_seq_interface_ops); &atalk_seq_route_ops))
if (!p) goto out;
goto out_interface;
p = proc_create_seq("route", 0444, atalk_proc_dir,
&atalk_seq_route_ops);
if (!p)
goto out_route;
p = proc_create_seq("socket", 0444, atalk_proc_dir, if (!proc_create_seq("atalk/socket", 0444, init_net.proc_net,
&atalk_seq_socket_ops); &atalk_seq_socket_ops))
if (!p) goto out;
goto out_socket;
p = proc_create_seq_private("arp", 0444, atalk_proc_dir, &aarp_seq_ops, if (!proc_create_seq_private("atalk/arp", 0444, init_net.proc_net,
sizeof(struct aarp_iter_state), NULL); &aarp_seq_ops,
if (!p) sizeof(struct aarp_iter_state), NULL))
goto out_arp; goto out;
rc = 0;
out: out:
return rc; remove_proc_subtree("atalk", init_net.proc_net);
out_arp: return -ENOMEM;
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;
} }
void __exit atalk_proc_exit(void) void atalk_proc_exit(void)
{ {
remove_proc_entry("interface", atalk_proc_dir); remove_proc_subtree("atalk", init_net.proc_net);
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);
} }
...@@ -1910,12 +1910,16 @@ static const char atalk_err_snap[] __initconst = ...@@ -1910,12 +1910,16 @@ static const char atalk_err_snap[] __initconst =
/* Called by proto.c on kernel start up */ /* Called by proto.c on kernel start up */
static int __init atalk_init(void) 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; 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); ddp_dl = register_snap_client(ddp_snap_id, atalk_rcv);
if (!ddp_dl) if (!ddp_dl)
printk(atalk_err_snap); printk(atalk_err_snap);
...@@ -1923,12 +1927,33 @@ static int __init atalk_init(void) ...@@ -1923,12 +1927,33 @@ static int __init atalk_init(void)
dev_add_pack(&ltalk_packet_type); dev_add_pack(&ltalk_packet_type);
dev_add_pack(&ppptalk_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(); aarp_proto_init();
atalk_proc_init(); rc = atalk_proc_init();
atalk_register_sysctl(); if (rc)
goto out_aarp;
rc = atalk_register_sysctl();
if (rc)
goto out_proc;
out: out:
return rc; 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); module_init(atalk_init);
......
...@@ -45,9 +45,12 @@ static struct ctl_table atalk_table[] = { ...@@ -45,9 +45,12 @@ static struct ctl_table atalk_table[] = {
static struct ctl_table_header *atalk_table_header; 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); 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) void atalk_unregister_sysctl(void)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment