net: x25: fix one potential use-after-free issue
The function x25_init is not properly unregister related resources on error handler.It is will result in kernel oops if x25_init init failed, so add properly unregister call on error handler. Also, i adjust the coding style and make x25_register_sysctl properly return failure. Signed-off-by: linzhang <xiaolou4617@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
3c2ce60bdd
commit
64df6d525f
|
@ -298,10 +298,10 @@ void x25_check_rbuf(struct sock *);
|
||||||
|
|
||||||
/* sysctl_net_x25.c */
|
/* sysctl_net_x25.c */
|
||||||
#ifdef CONFIG_SYSCTL
|
#ifdef CONFIG_SYSCTL
|
||||||
void x25_register_sysctl(void);
|
int x25_register_sysctl(void);
|
||||||
void x25_unregister_sysctl(void);
|
void x25_unregister_sysctl(void);
|
||||||
#else
|
#else
|
||||||
static inline void x25_register_sysctl(void) {};
|
static inline int x25_register_sysctl(void) { return 0; };
|
||||||
static inline void x25_unregister_sysctl(void) {};
|
static inline void x25_unregister_sysctl(void) {};
|
||||||
#endif /* CONFIG_SYSCTL */
|
#endif /* CONFIG_SYSCTL */
|
||||||
|
|
||||||
|
|
|
@ -1791,32 +1791,40 @@ void x25_kill_by_neigh(struct x25_neigh *nb)
|
||||||
|
|
||||||
static int __init x25_init(void)
|
static int __init x25_init(void)
|
||||||
{
|
{
|
||||||
int rc = proto_register(&x25_proto, 0);
|
int rc;
|
||||||
|
|
||||||
if (rc != 0)
|
rc = proto_register(&x25_proto, 0);
|
||||||
|
if (rc)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
rc = sock_register(&x25_family_ops);
|
rc = sock_register(&x25_family_ops);
|
||||||
if (rc != 0)
|
if (rc)
|
||||||
goto out_proto;
|
goto out_proto;
|
||||||
|
|
||||||
dev_add_pack(&x25_packet_type);
|
dev_add_pack(&x25_packet_type);
|
||||||
|
|
||||||
rc = register_netdevice_notifier(&x25_dev_notifier);
|
rc = register_netdevice_notifier(&x25_dev_notifier);
|
||||||
if (rc != 0)
|
if (rc)
|
||||||
goto out_sock;
|
goto out_sock;
|
||||||
|
|
||||||
|
rc = x25_register_sysctl();
|
||||||
|
if (rc)
|
||||||
|
goto out_dev;
|
||||||
|
|
||||||
|
rc = x25_proc_init();
|
||||||
|
if (rc)
|
||||||
|
goto out_sysctl;
|
||||||
|
|
||||||
pr_info("Linux Version 0.2\n");
|
pr_info("Linux Version 0.2\n");
|
||||||
|
|
||||||
x25_register_sysctl();
|
|
||||||
rc = x25_proc_init();
|
|
||||||
if (rc != 0)
|
|
||||||
goto out_dev;
|
|
||||||
out:
|
out:
|
||||||
return rc;
|
return rc;
|
||||||
|
out_sysctl:
|
||||||
|
x25_unregister_sysctl();
|
||||||
out_dev:
|
out_dev:
|
||||||
unregister_netdevice_notifier(&x25_dev_notifier);
|
unregister_netdevice_notifier(&x25_dev_notifier);
|
||||||
out_sock:
|
out_sock:
|
||||||
|
dev_remove_pack(&x25_packet_type);
|
||||||
sock_unregister(AF_X25);
|
sock_unregister(AF_X25);
|
||||||
out_proto:
|
out_proto:
|
||||||
proto_unregister(&x25_proto);
|
proto_unregister(&x25_proto);
|
||||||
|
|
|
@ -73,9 +73,12 @@ static struct ctl_table x25_table[] = {
|
||||||
{ },
|
{ },
|
||||||
};
|
};
|
||||||
|
|
||||||
void __init x25_register_sysctl(void)
|
int __init x25_register_sysctl(void)
|
||||||
{
|
{
|
||||||
x25_table_header = register_net_sysctl(&init_net, "net/x25", x25_table);
|
x25_table_header = register_net_sysctl(&init_net, "net/x25", x25_table);
|
||||||
|
if (!x25_table_header)
|
||||||
|
return -ENOMEM;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void x25_unregister_sysctl(void)
|
void x25_unregister_sysctl(void)
|
||||||
|
|
Loading…
Reference in New Issue