Received: by 10.213.65.68 with SMTP id h4csp2122259imn; Sun, 8 Apr 2018 20:15:08 -0700 (PDT) X-Google-Smtp-Source: AIpwx49xDDZHk+HzVqsRMaNgcFq7HbAMuR1GhrYfoqHDXVae4qtLZnoDv3H5X4FILJJfx1l5f1LC X-Received: by 10.98.68.135 with SMTP id m7mr27853250pfi.57.1523243708654; Sun, 08 Apr 2018 20:15:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523243708; cv=none; d=google.com; s=arc-20160816; b=iVKO/5P8aKN67+B9/ld1zQW1zYJvaU26eg+5zWWB2aAONke2gB9x/8ahQ7kQkXrYM3 PtOq+qcxmW/HW1V5HO0ewXZ88nUt7rMmX4MQD9RBX6WzzDPG8b5oqTVa7fNOpbvvqI/F lRsNWq1ETWL17e4IoFX7IirETSLP7kOv0PYMD15m488e0SewOPG1CNozJ0EevEPWjbnl ALQ5rbehYiXIWI951nZsBbzx6yphW/oHxP6edD5m1OEm23mneCbnWxFtl3ueekm5eVXd DjiTJnPFeqy0VxsifVLoVXOiCBoIdKV+PdlaiVLC0R7VOznCcao8DXhrnRZsmlW4P3ty vqig== 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=+EHpwUA+oZ8DLInGTVsghGa4VYEYRW/sE8GP+uhQ+0Q=; b=iVrVXKd9Kgakl4lHNMHHv9jYqwKg1go3U4/1NVBmo9MbdajVjYku1iYlbEa86KIpJR dGcIuQ2iW7LNLHfuTMR+Aouv02M+iU5RpeKluWBCtXMJvUdQqT86D54hHsBYop+cTH7k hKNVjp6YzGaJ5EEJrbY3cor9jM7tAASroYA9BKnxlsW5NmxbwUN1pL3VgvdD6+IBj8eH NQxlDrxugxGsHB83iilv3v+dKFt4uyCOaIKTeKFJqmwsVpYbq+6NJdItHujHOcWanxXX uahIyNZigDFUtqMb8g1LZ+9QL+dX2ebDrR9dWVknxR71nmqIXSicj9WwInmf/mBWMzgG yaUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=nRrCfKtD; 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 i81si12278588pfd.261.2018.04.08.20.14.31; Sun, 08 Apr 2018 20:15:08 -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=nRrCfKtD; 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 S1755192AbeDIDLm (ORCPT + 99 others); Sun, 8 Apr 2018 23:11:42 -0400 Received: from mail-dm3nam03on0092.outbound.protection.outlook.com ([104.47.41.92]:13920 "EHLO NAM03-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754916AbeDIAX5 (ORCPT ); Sun, 8 Apr 2018 20:23:57 -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=+EHpwUA+oZ8DLInGTVsghGa4VYEYRW/sE8GP+uhQ+0Q=; b=nRrCfKtDOfyTd4KUz2nz/VRQj2BuuaxNpP4UGFV+lBZ1X2nyrDjyPCbd9X8hCMW8N//6e/OzM/714WKx9aeSlgDJZRhUf4QAdbEeV3V0ooqnQJy/vpqO1TZM+4Wwg28GBM/tHY/plyrEkleV1b4od32YSK4QyqBYSDAfNJtQGP0= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0984.namprd21.prod.outlook.com (52.132.133.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.696.0; Mon, 9 Apr 2018 00:23:54 +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:23:54 +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.14 080/161] jffs2: Fix use-after-free bug in jffs2_iget()'s error handling path Thread-Topic: [PATCH AUTOSEL for 4.14 080/161] jffs2: Fix use-after-free bug in jffs2_iget()'s error handling path Thread-Index: AQHTz5ieK3IS5/C8Lki1Af4FFClV2A== Date: Mon, 9 Apr 2018 00:20:51 +0000 Message-ID: <20180409001936.162706-80-alexander.levin@microsoft.com> References: <20180409001936.162706-1-alexander.levin@microsoft.com> In-Reply-To: <20180409001936.162706-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;DM5PR2101MB0984;7:KtmNDQRFWkMOyjhuD6bdWScAl30BE/RmbsC4R6d5xYvYWZjT74QhmVgnmg7N7UUds7vXv6LjANQqno7cMFClhVhlke7m64Ix5vCS/yJxvLsVCXO1rH62ZzyGoBbQRHREM4yTf0ZT28muFuE9xZDy0RcCEt+wWXymvrMd9BAq1pz1/JKoqE0ZE3mNUnq1IGopXJPGoHVsKlUwdfATMwsFfxE9bf+tCPVcUbdQVHSCO60HpGYQgrSeHQQ9WmHzUCbt;20:z3oCuVaPOe9hUJBRShrep4LJouxUO1R/A6ndgxLPsX+bq+OKi72l6z+u8efjroywN4ptTwzga0HkaQFROXu33WzcgM8xY+uR+p7gDPcFw/Mz4i1fUnlZErWJbtA6PuNpUWoSKV4slAeOx+dCH+mgg8r5a6yhR5EellrVsEYRPHM= x-ms-office365-filtering-ht: Tenant X-MS-Office365-Filtering-Correlation-Id: 800e7620-b1a6-49c7-0871-08d59db02d6d x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB0984; x-ms-traffictypediagnostic: DM5PR2101MB0984: 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)(3231221)(944501327)(52105095)(3002001)(10201501046)(6055026)(61426038)(61427038)(6041310)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123564045)(20161123560045)(6072148)(201708071742011);SRVR:DM5PR2101MB0984;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB0984; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39380400002)(346002)(376002)(366004)(39860400002)(396003)(189003)(199004)(5250100002)(2501003)(110136005)(54906003)(6116002)(6436002)(11346002)(39060400002)(1076002)(486006)(25786009)(105586002)(2900100001)(102836004)(86612001)(3846002)(68736007)(107886003)(316002)(10290500003)(5660300001)(86362001)(2616005)(305945005)(4326008)(446003)(6486002)(22452003)(7736002)(575784001)(476003)(8676002)(81156014)(81166006)(8936002)(6512007)(10090500001)(186003)(3280700002)(106356001)(76176011)(2906002)(99286004)(26005)(97736004)(59450400001)(14454004)(6666003)(478600001)(53936002)(6506007)(36756003)(72206003)(66066001)(3660700001)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB0984;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: TnKjZ5KD3V9OHrDaxkBLViaOy8EEZQmxuCaAbxu92XteSL7iEbsqIpTCtsE8FF1cmGTt01AZ4myXs2Ycangw0QdWbgmGx3piPGLPnDLRurQy9sSqszwkOJoNmxfyi0yCwHhTV825ImCKfVSizEgK7wxebFo3L81XyFUccsWsYI7PerLy5rGuGDJz9o1932O2K5DQPzUri/CCm/LWXOvVt0h2rVO6XsNvf7cNiqXi/OQ+uh6ESfOkD/lQPSW3CEbW4ES09xFkLMlhIO2VS/0WG5SyABXs6C6GumKODGos6FNZUGR85IFGdQkeu8EcKqy4qhwrxfocWNT6qGe0OjXNu9cPTpyo8g9T0/jHRBojJpnQxSUsAemb6NVwnH6W+bqW1xK84Ib/t282N6vkENsfVsW0NqNl3pkvW/vuZx/nSv0= 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: 800e7620-b1a6-49c7-0871-08d59db02d6d X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:20:51.7846 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0984 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 e96c6b05e43e..3c96f4bdc549 100644 --- a/fs/jffs2/fs.c +++ b/fs/jffs2/fs.c @@ -362,7 +362,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