Received: by 10.213.65.68 with SMTP id h4csp2114238imn; Sun, 8 Apr 2018 20:04:26 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+jnEi/mo2dLcKlQOmWL5AtlECbV/MTD0eqIiOFB0g3zSr+/0rzmiLHUra2b2bGCVLkX8dN X-Received: by 10.99.164.18 with SMTP id c18mr23854607pgf.85.1523243066441; Sun, 08 Apr 2018 20:04:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523243066; cv=none; d=google.com; s=arc-20160816; b=RJ2Q420i6+N1x8+wFzkKiiQupGbqTg6HxNoXxWm1Rpb3fh3Oxq021xwkdnaXXyxAZ0 h+fv8bfCfIGtu9U/9j5E3HyjXscwb1DUmuQ3wqClfG6Rf2JHPt4kLa5GUlCenEhBu4v8 R2pb7IGlK/AntaxkrQOiKxnXH+w9WKnyXa4mUa7ge21/srdW009cOZrqMuzz0rTCd/TW 2LgxRRDu3gocLQ6yr0BAqrbpPDK/g9Nyzw1sdCs9eZZxa4mnAvtYoXSBW/cM9hrfMl2y MmIExRV5ydIL+r5eaBAwdePCBqlVOi39KOZBpkd5NHlYSvfdM0XXLFo73vc60MHVDy/S 5ujw== 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=qu+E9dsBSQIyfZfLwoj6n9xauytTJJsFQ+NJJSM0ZXo=; b=Y/wLMU3fdEIJAZXqE7jwR/Wm5xk29UoBX7N6WvK0SUKj2V5Zk1woOG0a1U7kQdtzu9 x/QCi6h4RaGlZg++8WONkTMqXXJnlEeKMEf7GwiTHLjrMQRuYsioYhMTgsjPuA07X7jB IwF3WoyxUj/ZaVL6VIq1qoAnXvVjAccIxdwFIH0pU7uTT3FlO9rKPR5H/TmGJ3oX/Ns0 EGPwrXBZqZPYhVOeQYclAhhQTK8Jru+G2xpcmLHQbHjhxFfU7dxmOTfGbGMoTPQpg4+5 Q+woFTuCeAI1KiVGsE7+OToJKEzixVdiYedbDLr9KUpL7rbAO/aoIIY9ly5ARo0d8z+z YCfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=RmcgHSYK; 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 m83si11881116pfk.171.2018.04.08.20.03.49; Sun, 08 Apr 2018 20:04:26 -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=RmcgHSYK; 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 S932351AbeDIAdw (ORCPT + 99 others); Sun, 8 Apr 2018 20:33:52 -0400 Received: from mail-by2nam01on0111.outbound.protection.outlook.com ([104.47.34.111]:45024 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932313AbeDIAdr (ORCPT ); Sun, 8 Apr 2018 20:33:47 -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=qu+E9dsBSQIyfZfLwoj6n9xauytTJJsFQ+NJJSM0ZXo=; b=RmcgHSYKtaqJAHcxkvReLsEiaopeG5KAEnJup3p21rwzqq4RnslIQBXwSkCzCas6F2IwIsIjVtjjaQB/E3/qxnqFJvm/kut8IqdvMUTNhNEUblWVxsBbDS0a0rkz9K4eAm6HrDuEnpICPBBENGTIMy/9tnzxpcD9gUBMXcFCAOc= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0998.namprd21.prod.outlook.com (52.132.133.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.696.0; Mon, 9 Apr 2018 00:33:44 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059%2]) with mapi id 15.20.0696.003; Mon, 9 Apr 2018 00:33:44 +0000 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Jake Daryll Obina , Al Viro , Sasha Levin Subject: [PATCH AUTOSEL for 4.9 246/293] jffs2: Fix use-after-free bug in jffs2_iget()'s error handling path Thread-Topic: [PATCH AUTOSEL for 4.9 246/293] jffs2: Fix use-after-free bug in jffs2_iget()'s error handling path Thread-Index: AQHTz5lYTa1mh12+2EuIfVXZl70nCw== Date: Mon, 9 Apr 2018 00:26:04 +0000 Message-ID: <20180409002239.163177-246-alexander.levin@microsoft.com> References: <20180409002239.163177-1-alexander.levin@microsoft.com> In-Reply-To: <20180409002239.163177-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;DM5PR2101MB0998;7:lRJDb5Ue2uqwIjIgb8Xyy5soxcaW8spFh8lq9Hb8oPZaXWWapeuo+QX4Db+n1vgw0jCqYdF3OPfzVpaqD34R6+Nhms34XHPdl1B7cmZAuWkgh3fl2LbRwuzxXTpNNKd0hnx8cpKM9kiduqX9TFbuvQsbe3mfwGhoPjNCwy8NhyFzIMugmM/Xzulc6GwdSQBOP6rvdJ3NbXJRc1MQDzcV/EJpBqXpnC3EI0RUVx37n/MVPGbpdkFTBgQUg0I7e6MM;20:eL5BSKIZss/rsNjjcOD20FU8qFWVth5wjC74vvijCU+tyIyAtBjsXcpwzL41+OXjJMJLVo24qjydNntuPiol6GEpIJ0B2FJKXgpeA+KS3zJqVJRqG+D8vpIdShv3ouePnH/40MooQ7hvKZvCdMtwzlYzmWLzDHSkO1+zoxxwBK4= x-ms-office365-filtering-ht: Tenant X-MS-Office365-Filtering-Correlation-Id: 9f49ef26-7bf1-40d8-1027-08d59db18cde x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB0998; x-ms-traffictypediagnostic: DM5PR2101MB0998: 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)(5005006)(8121501046)(93006095)(93001095)(3231221)(944501327)(52105095)(3002001)(10201501046)(6055026)(61426038)(61427038)(6041310)(20161123558120)(20161123562045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(6072148)(201708071742011);SRVR:DM5PR2101MB0998;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB0998; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(346002)(39380400002)(376002)(396003)(366004)(39860400002)(189003)(199004)(25786009)(59450400001)(105586002)(14454004)(76176011)(68736007)(2906002)(316002)(97736004)(8676002)(39060400002)(86612001)(3660700001)(3280700002)(102836004)(6116002)(4326008)(8936002)(36756003)(22452003)(81166006)(81156014)(54906003)(6506007)(10090500001)(2501003)(6512007)(186003)(6666003)(3846002)(486006)(5660300001)(26005)(7736002)(5250100002)(305945005)(99286004)(2900100001)(110136005)(1076002)(6436002)(53936002)(106356001)(575784001)(107886003)(72206003)(86362001)(476003)(446003)(66066001)(11346002)(478600001)(10290500003)(2616005)(6486002)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB0998;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: hlXsCHgs9r2BTx3gyVHfN8fmw/7S7E0tvA3FNJHTo+9axqHEVHL00Bkv0f1bI6LGHC3qLgVDFjZWEnA3Cij+WGxD5BgjPTAiqYiGU6Vcvf3yUJl5U3XDcZm/TW5GN35h2qj3N8J7p+6vNrUNEUxbRZxX4pi9XBgH83DhblXg4lUdFPUSlRFVLwqyCoEXeAX5jvrnw5qI7Xn2k6OTbS/dj5+LHXDaKTmQY0IvKSI1OLynMc74a75MNsi/ZVHtbuKfAw9vA1FYvAexqHF/Ftwa3oMo1r0HyQ9Io8z0XB4pscjCHB6CPKFB3H619TtSPoGLd6Q08mgc4hOPnQ1VtR7ZVB3rG+P2Ygb5QoCU2IIU8mAlAnPt/PxhC4td2CvnpIp5z9NBUKjlh8LBiISMz9QZz+bx0FMMwZgZUgH4LuOwjxo= 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: 9f49ef26-7bf1-40d8-1027-08d59db18cde X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:26:04.8318 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0998 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jake Daryll Obina [ Upstream commit 5bdd0c6f89fba430e18d636493398389dadc3b17 ] If jffs2_iget() fails for a newly-allocated inode, jffs2_do_clear_inode() can get called twice in the error handling path, the first call in jffs2_iget() itself and the second through iget_failed(). This can result to a use-after-free error in the second jffs2_do_clear_inode() call, such as shown by the oops below wherein the second jffs2_do_clear_inode() call was trying to free node fragments that were already freed in the first jffs2_do_clear_inode() call. [ 78.178860] jffs2: error: (1904) jffs2_do_read_inode_internal: CRC faile= d for read_inode of inode 24 at physical location 0x1fc00c [ 78.178914] Unable to handle kernel paging request at virtual address 6b= 6b6b6b6b6b6b7b [ 78.185871] pgd =3D ffffffc03a567000 [ 78.188794] [6b6b6b6b6b6b6b7b] *pgd=3D0000000000000000, *pud=3D000000000= 0000000 [ 78.194968] Internal error: Oops: 96000004 [#1] PREEMPT SMP ... [ 78.513147] PC is at rb_first_postorder+0xc/0x28 [ 78.516503] LR is at jffs2_kill_fragtree+0x28/0x90 [jffs2] [ 78.520672] pc : [] lr : [] pstate: = 60000105 [ 78.526757] sp : ffffff800cea38f0 [ 78.528753] x29: ffffff800cea38f0 x28: ffffffc01f3f8e80 [ 78.532754] x27: 0000000000000000 x26: ffffff800cea3c70 [ 78.536756] x25: 00000000dc67c8ae x24: ffffffc033d6945d [ 78.540759] x23: ffffffc036811740 x22: ffffff800891a5b8 [ 78.544760] x21: 0000000000000000 x20: 0000000000000000 [ 78.548762] x19: ffffffc037d48910 x18: ffffff800891a588 [ 78.552764] x17: 0000000000000800 x16: 0000000000000c00 [ 78.556766] x15: 0000000000000010 x14: 6f2065646f6e695f [ 78.560767] x13: 6461657220726f66 x12: 2064656c69616620 [ 78.564769] x11: 435243203a6c616e x10: 7265746e695f6564 [ 78.568771] x9 : 6f6e695f64616572 x8 : ffffffc037974038 [ 78.572774] x7 : bbbbbbbbbbbbbbbb x6 : 0000000000000008 [ 78.576775] x5 : 002f91d85bd44a2f x4 : 0000000000000000 [ 78.580777] x3 : 0000000000000000 x2 : 000000403755e000 [ 78.584779] x1 : 6b6b6b6b6b6b6b6b x0 : 6b6b6b6b6b6b6b6b ... [ 79.038551] [] rb_first_postorder+0xc/0x28 [ 79.042962] [] jffs2_do_clear_inode+0x88/0x100 [jffs2] [ 79.048395] [] jffs2_evict_inode+0x3c/0x48 [jffs2] [ 79.053443] [] evict+0xb0/0x168 [ 79.056835] [] iput+0x1c0/0x200 [ 79.060228] [] iget_failed+0x30/0x3c [ 79.064097] [] jffs2_iget+0x2d8/0x360 [jffs2] [ 79.068740] [] jffs2_lookup+0xe8/0x130 [jffs2] [ 79.073434] [] lookup_slow+0x118/0x190 [ 79.077435] [] walk_component+0xfc/0x28c [ 79.081610] [] path_lookupat+0x84/0x108 [ 79.085699] [] filename_lookup+0x88/0x100 [ 79.089960] [] user_path_at_empty+0x58/0x6c [ 79.094396] [] vfs_statx+0xa4/0x114 [ 79.098138] [] SyS_newfstatat+0x58/0x98 [ 79.102227] [] __sys_trace_return+0x0/0x4 [ 79.106489] Code: d65f03c0 f9400001 b40000e1 aa0103e0 (f9400821) The jffs2_do_clear_inode() call in jffs2_iget() is unnecessary since iget_failed() will eventually call jffs2_do_clear_inode() if needed, so just remove it. Fixes: 5451f79f5f81 ("iget: stop JFFS2 from using iget() and read_inode()") Reviewed-by: Richard Weinberger Signed-off-by: Jake Daryll Obina Signed-off-by: Al Viro Signed-off-by: Sasha Levin --- fs/jffs2/fs.c | 1 - 1 file changed, 1 deletion(-) diff --git a/fs/jffs2/fs.c b/fs/jffs2/fs.c index 567653f7c0ce..c9c47d03a690 100644 --- a/fs/jffs2/fs.c +++ b/fs/jffs2/fs.c @@ -361,7 +361,6 @@ error_io: ret =3D -EIO; error: mutex_unlock(&f->sem); - jffs2_do_clear_inode(c, f); iget_failed(inode); return ERR_PTR(ret); } --=20 2.15.1