From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-by2nam03on0102.outbound.protection.outlook.com ([104.47.42.102]:30227 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S966814AbeCSQMT (ORCPT ); Mon, 19 Mar 2018 12:12:19 -0400 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: linzhang , "David S . Miller" , Sasha Levin Subject: [PATCH AUTOSEL for 3.18 031/102] net: x25: fix one potential use-after-free issue Date: Mon, 19 Mar 2018 16:12:05 +0000 Message-ID: <20180319161117.17833-31-alexander.levin@microsoft.com> References: <20180319161117.17833-1-alexander.levin@microsoft.com> In-Reply-To: <20180319161117.17833-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: linzhang [ Upstream commit 64df6d525fcff1630098db9238bfd2b3e092d5c1 ] 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 Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- include/net/x25.h | 4 ++-- net/x25/af_x25.c | 24 ++++++++++++++++-------- net/x25/sysctl_net_x25.c | 5 ++++- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/include/net/x25.h b/include/net/x25.h index c383aa4edbf0..6d30a01d281d 100644 --- a/include/net/x25.h +++ b/include/net/x25.h @@ -298,10 +298,10 @@ void x25_check_rbuf(struct sock *); =20 /* sysctl_net_x25.c */ #ifdef CONFIG_SYSCTL -void x25_register_sysctl(void); +int x25_register_sysctl(void); void x25_unregister_sysctl(void); #else -static inline void x25_register_sysctl(void) {}; +static inline int x25_register_sysctl(void) { return 0; }; static inline void x25_unregister_sysctl(void) {}; #endif /* CONFIG_SYSCTL */ =20 diff --git a/net/x25/af_x25.c b/net/x25/af_x25.c index 5ad4418ef093..7ac8d3869267 100644 --- a/net/x25/af_x25.c +++ b/net/x25/af_x25.c @@ -1796,32 +1796,40 @@ void x25_kill_by_neigh(struct x25_neigh *nb) =20 static int __init x25_init(void) { - int rc =3D proto_register(&x25_proto, 0); + int rc; =20 - if (rc !=3D 0) + rc =3D proto_register(&x25_proto, 0); + if (rc) goto out; =20 rc =3D sock_register(&x25_family_ops); - if (rc !=3D 0) + if (rc) goto out_proto; =20 dev_add_pack(&x25_packet_type); =20 rc =3D register_netdevice_notifier(&x25_dev_notifier); - if (rc !=3D 0) + if (rc) goto out_sock; =20 - pr_info("Linux Version 0.2\n"); + rc =3D x25_register_sysctl(); + if (rc) + goto out_dev; =20 - x25_register_sysctl(); rc =3D x25_proc_init(); - if (rc !=3D 0) - goto out_dev; + if (rc) + goto out_sysctl; + + pr_info("Linux Version 0.2\n"); + out: return rc; +out_sysctl: + x25_unregister_sysctl(); out_dev: unregister_netdevice_notifier(&x25_dev_notifier); out_sock: + dev_remove_pack(&x25_packet_type); sock_unregister(AF_X25); out_proto: proto_unregister(&x25_proto); diff --git a/net/x25/sysctl_net_x25.c b/net/x25/sysctl_net_x25.c index 43239527a205..703d46aae7a2 100644 --- a/net/x25/sysctl_net_x25.c +++ b/net/x25/sysctl_net_x25.c @@ -73,9 +73,12 @@ static struct ctl_table x25_table[] =3D { { 0, }, }; =20 -void __init x25_register_sysctl(void) +int __init x25_register_sysctl(void) { x25_table_header =3D register_net_sysctl(&init_net, "net/x25", x25_table)= ; + if (!x25_table_header) + return -ENOMEM; + return 0; } =20 void x25_unregister_sysctl(void) --=20 2.14.1