Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2470497imm; Mon, 28 May 2018 08:41:46 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrp89LmVQKzMcAPGCspF9+Q4oA0p0dMkFmfctOhwMnUMis1mOvLW0a92mELBCrtyt/3YL14 X-Received: by 2002:a65:4043:: with SMTP id h3-v6mr11295001pgp.333.1527522106711; Mon, 28 May 2018 08:41:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527522106; cv=none; d=google.com; s=arc-20160816; b=QtWkdj111d9CzjVg8/u5DfdqmQEOPRhkLNJK7cVi8ucjogXWdlTh+VhPwS7Ra0od8n xiPjZSxWHDd1CEnnlxHk9kth7W3SIggV+FX+RNAhVPsV0SwCgiU8h0C64E56Tf1HX1K9 3t1Auat+6eywUip8/ba5ThP5igfFiK66qvoEbSimHQE3jbGNR2LRE/ajE1XdupsjPjYY y8uYb9JNLTzTDGIHfCr9nsJ031CkrsXnJy7C3zTzSNK5HHezZfm3KEc5szWx3i5/mA38 gBDG4H9xXeGJQH6TZoh9ZCJEYQap0lgAaRzgAbpHXDYSZIHmPxkIBuhHScYbxmpSoYcn lNEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=WUeqJz585kOuBOfFZv6cgk6kHmAJUBG66R0imbbwOOs=; b=WOocPr+3LCB80CshGZIOiMU2OpNiN3t+sKU0nyqkq+rB+kc8i1tj0FeYGUiz+vVQxa RPK77sb9vFWK8na2S03o1e2/zq6uuOPwl/6VrvkfY9Nyi+fj6Lu0E0G2G5S3SVNsZ6gi c1MphszSQZrRged4OKIiOzAb85VDjqVbua69eRMv0WWnYMNBd+5ix6TjJB4rP613BCJ7 Gn7l3MkzSUdjCDcJwAD5nhAIiT9TVMUOaSwL3Qp4wf+NYCmEssOvFEY0aA4yrRuRlwFI 1dtyNNZtFuIA0wOmV6Q/9OjOP2NgnQ29lhJmKWDNsmbHrgB12CKmX88tkhYU2J9Dzfe7 XE2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dJul8oD1; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l10-v6si23958651pgn.304.2018.05.28.08.41.31; Mon, 28 May 2018 08:41:46 -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=@kernel.org header.s=default header.b=dJul8oD1; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1034715AbeE1Pkz (ORCPT + 99 others); Mon, 28 May 2018 11:40:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:37872 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030566AbeE1KRn (ORCPT ); Mon, 28 May 2018 06:17:43 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 98790208A2; Mon, 28 May 2018 10:17:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527502663; bh=ImfJYADJJ2479jhy+AbT8H0iuWDs49KjhhDqF/egXUw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dJul8oD1Ga9XFJPbF9mX6GUDj7ipldMaOtLMUdnySLc65K/gxXfPWszsorKsDVb/b b0mYxeEfY+/6BW5e5nujOAdY7J4QCXm+VmyCsp1Tex4IRR62K9pSV7RDdkta+po6GM TUh7e5VRb4irOi/kj7dWVlbz2oWyaN4ptpbb8Db0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Richard Weinberger , Jake Daryll Obina , Al Viro , Sasha Levin Subject: [PATCH 4.4 041/268] jffs2: Fix use-after-free bug in jffs2_iget()s error handling path Date: Mon, 28 May 2018 12:00:15 +0200 Message-Id: <20180528100206.685583081@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180528100202.045206534@linuxfoundation.org> References: <20180528100202.045206534@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ 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 failed for read_inode of inode 24 at physical location 0x1fc00c [ 78.178914] Unable to handle kernel paging request at virtual address 6b6b6b6b6b6b6b7b [ 78.185871] pgd = ffffffc03a567000 [ 78.188794] [6b6b6b6b6b6b6b7b] *pgd=0000000000000000, *pud=0000000000000000 [ 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 Signed-off-by: Greg Kroah-Hartman --- fs/jffs2/fs.c | 1 - 1 file changed, 1 deletion(-) --- a/fs/jffs2/fs.c +++ b/fs/jffs2/fs.c @@ -361,7 +361,6 @@ error_io: ret = -EIO; error: mutex_unlock(&f->sem); - jffs2_do_clear_inode(c, f); iget_failed(inode); return ERR_PTR(ret); }