Received: by 10.213.65.68 with SMTP id h4csp1630718imn; Mon, 19 Mar 2018 09:10:58 -0700 (PDT) X-Google-Smtp-Source: AG47ELuaUqls6qVTFZIpsJgAIiQE3XRYuSyJaofG+dAavJQmclEbCaywbvhr6Il9Tr+0dWTWIalv X-Received: by 10.99.174.67 with SMTP id e3mr9151424pgp.139.1521475858300; Mon, 19 Mar 2018 09:10:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521475858; cv=none; d=google.com; s=arc-20160816; b=pffEojHSdq28OoH5SEv+HDY3OXCfW3/f7Ij4Xi9A4dC3OhE7agMSW2UQ4M3hhBx49i UdjPBabmB4rv4PSiU/gAY36m3Hy6atVHe+a+x4hslHaVii2/wa3h4/2iqbTrKCPhr76V 2eBQB7Jfm/Z0/ZHKXvoo7pd5QApxwWbthBVkFk+5iLLSfS/OLm8qO23ooTM+nRQLT7+g HmQmEuk3y0owBdFaDn7bYoa7CAFu7jsbeqSYQ6OanuTyjoWh5hxiWpepB5vtQYQVDFGC uOYlNZw622oMmYOrHwjUCMKCDP9OmMz9b8dTQ00HAuOr3uXe+59gxpjf766KMvLHizFj 1Oqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=vudxyKYzBK9mBknP4OcJMclTmBxtAgQlnY2V6UgP+Nw=; b=LtOvAKc9UWD4iwRUwgzozJOxNmt84QydC8vNOADSURkj7wxLJ/L8uWlnrYtkJ97jIG 8S8dj9Sf3e1tvd2DWbG0zN5SixzvQfxruj5ekKTHj4rxCQqMsOMsaKwYSO0Hc64FS0io sxMFvao9ES5sTi2R0tiWHAU+T+9UUUqJ0VW/DhPl49z8RHc1E9yt/6rKxOrW23GoVKu8 1YjuBmfdJyhTlsPBRsy0meqzJSJUUj2ddNR8/0vjdbGnVfd0qHimejUUIHFG7Mzv2Pt2 EidlOKzl/SB4vKueItAzn+aps7NaRLa+0TgUOZsmTSUz6v77s5uyHttkda6zYLJNHh62 Fk6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=XiVfLRQ/; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u10si156353pgb.669.2018.03.19.09.10.43; Mon, 19 Mar 2018 09:10:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=XiVfLRQ/; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966356AbeCSQIr (ORCPT + 99 others); Mon, 19 Mar 2018 12:08:47 -0400 Received: from mail-dm3nam03on0131.outbound.protection.outlook.com ([104.47.41.131]:49502 "EHLO NAM03-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S966279AbeCSQIS (ORCPT ); Mon, 19 Mar 2018 12:08:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=vudxyKYzBK9mBknP4OcJMclTmBxtAgQlnY2V6UgP+Nw=; b=XiVfLRQ/gyQ6ouaZEZpbGtobJ+12BcRIpg7o77gzCnoGbmP0Ae/hV8T9KqkSocdoB32/Qcaqtg2zl06pWiCizzyC55JD6pERoY6+enu0gBnCyK57WC+eI5hRQvp/xOB2iBBBSNmY9CAtKP4mn3umuZNGHHQNj/3IsYW7kDarmk0= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0805.namprd21.prod.outlook.com (10.167.105.149) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.631.2; Mon, 19 Mar 2018 16:08:12 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::3d9b:79e7:94eb:5d62]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::3d9b:79e7:94eb:5d62%5]) with mapi id 15.20.0631.004; Mon, 19 Mar 2018 16:08:12 +0000 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: linzhang , "David S . Miller" , Sasha Levin Subject: [PATCH AUTOSEL for 4.4 046/167] net: x25: fix one potential use-after-free issue Thread-Topic: [PATCH AUTOSEL for 4.4 046/167] net: x25: fix one potential use-after-free issue Thread-Index: AQHTv5w33Ri4WjXE30O/EDm2CG76/g== Date: Mon, 19 Mar 2018 16:06:18 +0000 Message-ID: <20180319160513.16384-46-alexander.levin@microsoft.com> References: <20180319160513.16384-1-alexander.levin@microsoft.com> In-Reply-To: <20180319160513.16384-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB0805;7:q8ZCEjUHlG7i3OGx29Tf2XvOxBcBvvygqBfpIdmCR3sQZz5yqv8TjZk+S78KTraCerjC1eRZ/Rffl91flFSR+HrDnGwWRd9CwO28xFusaoVK7g9kYJECu6QlesVycS+SROPzfPmqSgDCP/TKrLIbbHflfiij13QDMMJ7gHYnAuvRO1JGnYhS6gB7IYRXuKHJLbg29/PGtb2X3RhVeckIU7STd3QGogG9CluIfVypD19ruKjIIQOXrC04ggdSLCpG;20:rhV7dUC87gwFDBbfhP3C4cUez569McaiwRF9mKKdFKri+X3634i+LhHUGVIJGiZoK0Z8p14lHtQ8nMCReb25m9fpMPi0B6DjcHEGLPIai3utgCHVQCaYVq10W/55iDhxsADkyiHFjKR4znsPrfx0dyWeTITpGv69KUJyhGRIZmk= x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: 5dfefdec-3288-42ef-be75-08d58db39db0 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB0805; x-ms-traffictypediagnostic: DM5PR2101MB0805: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171)(85827821059158); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040522)(2401047)(8121501046)(5005006)(93006095)(93001095)(10201501046)(3231221)(944501300)(52105095)(3002001)(6055026)(61426038)(61427038)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123562045)(20161123558120)(20161123560045)(6072148)(201708071742011);SRVR:DM5PR2101MB0805;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB0805; x-forefront-prvs: 06167FAD59 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39380400002)(376002)(346002)(366004)(396003)(39860400002)(199004)(189003)(2950100002)(305945005)(186003)(86362001)(6506007)(3660700001)(5660300001)(6116002)(8936002)(3846002)(1076002)(26005)(7736002)(6486002)(2900100001)(6436002)(2906002)(86612001)(68736007)(81166006)(81156014)(10090500001)(102836004)(59450400001)(8676002)(14454004)(105586002)(107886003)(25786009)(478600001)(39060400002)(2501003)(5250100002)(53936002)(3280700002)(316002)(54906003)(4326008)(6512007)(72206003)(66066001)(22452003)(10290500003)(99286004)(76176011)(36756003)(97736004)(106356001)(110136005)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB0805;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: hx325I1+53FemepzzqkjAk/zdMqu2qcTgQB5ZVXRFgTYd+m6eM0cUSBIwHznT1Xda6kRStzmBUbQJh+rnwQucvm+UCg6L7chNdLYjFBki+vqViQL/Fsr2jva+RONZz8V5paVdNAqDzLDlUvVOW/2/LWkKSR+lsBCPJxwy2Gs3FMqfxcYX1Krd+juP9LGaBT9Tbwh26RqqmvjXsS7+sDkW25WjlDVFKyH12pJXmwqMc8f8QWiPBW2bT1KR4EOFc7TFeDJylyiFFtfrC5tGCpF3kKYosT9MOD701Tai2WRTG9qgAT7tE87cvOdcqp0HI3okUm+1ahsuvQV5qUxJwTnMQ== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5dfefdec-3288-42ef-be75-08d58db39db0 X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Mar 2018 16:06:18.7894 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0805 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 a750f330b8dd..c6ab4da4b8e2 100644 --- a/net/x25/af_x25.c +++ b/net/x25/af_x25.c @@ -1794,32 +1794,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