From patchwork Thu Sep 21 16:00:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jake Daryll Obina X-Patchwork-Id: 816992 X-Patchwork-Delegate: dwmw2@infradead.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=65.50.211.133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="neNKvImp"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="RKSz8ySf"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xyhDy33lzz9t42 for ; Fri, 22 Sep 2017 02:01:38 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=SBK8YaP6MOhXiwPymV0hU9C0fMwveT6PKIKcn4z9Kkk=; b=neN KvImptJJJcf8eePKV6/kOnsQO2QiPhSGbfxjbYH084ZYcHNETpRGhYXgNWnOiUMGUev2p3dqgO2qo EYYs4X05KUVDBFhbMjXIgDS59KQzxSW/jNNolbMpZy7Vhvj84AhZnQfFkNGsIAT/buC2+u4RLAXGW +Q/ZP47zqe028Vek6/i6sUTYR7onTEynnG02R0hNexbLGeM4I47TtVJmv3thYuZXsKrYUMDbW7ahy GyuLl9i+p/Q+bwVYXdLrB+8nUX5LTVqKB5h0zDU/q7uGo6kgQmhAq8HuGQ77YjEQWnDOgmO/EQgPd ZZ0yAGYigdh5DpjxhZDp7PbM0aqn1Jg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dv3ur-0001aq-6e; Thu, 21 Sep 2017 16:01:29 +0000 Received: from mail-pg0-x244.google.com ([2607:f8b0:400e:c05::244]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dv3uQ-0001X3-Q1 for linux-mtd@lists.infradead.org; Thu, 21 Sep 2017 16:01:05 +0000 Received: by mail-pg0-x244.google.com with SMTP id j16so3655222pga.2 for ; Thu, 21 Sep 2017 09:00:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=PqDuCJZSfIAN2VrRhOVCn2jA32DlZnJsUSStLrp2Cso=; b=RKSz8ySfT8e1RDUzJblU7EK82+fHc51z7LzhEA4EjvRyHw+BwfuH8ub76rbrvFmrqw wETx2KVvTPrwYT2TlSFwDtglEFzoXH30SXYg6jbYhAFp5XiHkZqoNK3cFrEg+cMbbrwB 2zDVIQhaUfH189wToxq50Y89EckDrMPZ4qakXjMFpdyAP6sXNl08kCjqLedbg/pa9ht2 QYoxamGGkLo9LBmX2XPXuGHVFXXpnA7Hw4hQ6VmgcaYXElMCAF2mDhdQ9edi49i8h/7k BQi+2M7VvgpbcRtBFx1DUDnsTo62QkFGQT3lM13XSq79GmENCPss5MKMrdrdL7g+xPaU a81g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=PqDuCJZSfIAN2VrRhOVCn2jA32DlZnJsUSStLrp2Cso=; b=E/WNngHn/diRhRCcQnDLG+1CNdtVNFcyCuIE7B27FWYt9LmdKwQpBCmH4lR5ANUQBx Nip1kEWYWepyIEi5dnEu4CK73n0MVIIoeiqGlkgiO7JPgajdVpfWeyBDhFDUTxolYMCP HLQf5LK35StdfpFE1xv6AuE+HOT/qK2mbKwF0W1RX+bsrEBRO71zG7B5aWJgpXnC8SOX pDdXypMPaPxFIugJyr4AzvOrffTSxAp4BARSwDXlw92CXh6gz2LzLrofdDGC+dGiaIls +jYO6liSrb4MTAaOcEgBuPKHBA40eGTm0rVkeNwrFeMZCZ0jJ6hgK90lYywYzbpsLIol xrWw== X-Gm-Message-State: AHPjjUgPe6QAW7ljx28psA+zyMhL1qlfguiXEh9qASqmK93yjpJIKuDL 4a24lO9fy/VcvcAMwdmgMth8wZtd X-Google-Smtp-Source: AOwi7QAVgzQ9W5JVUIJC9t7xSZch4peloMxRJTm/6FsCpAsDzYWXdUhZB9aPWLKzdAgBUGMsl1aHSQ== X-Received: by 10.84.129.7 with SMTP id 7mr6021726plb.40.1506009640983; Thu, 21 Sep 2017 09:00:40 -0700 (PDT) Received: from localhost.localdomain ([180.190.173.38]) by smtp.gmail.com with ESMTPSA id p1sm4568935pfb.53.2017.09.21.09.00.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 21 Sep 2017 09:00:40 -0700 (PDT) From: Jake Daryll Obina To: linux-mtd@lists.infradead.org Subject: [PATCH] jffs2: Fix use-after-free bug in jffs2_iget()'s error handling path Date: Fri, 22 Sep 2017 00:00:14 +0800 Message-Id: <1506009614-3277-1-git-send-email-jake.obina@gmail.com> X-Mailer: git-send-email 2.7.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170921_090102_980400_A11D3654 X-CRM114-Status: GOOD ( 11.16 ) X-Spam-Score: -2.0 (--) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-2.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [2607:f8b0:400e:c05:0:0:0:244 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (jake.obina[at]gmail.com) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jake Daryll Obina , dwmw2@infradead.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org 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. Signed-off-by: Jake Daryll Obina Reviewed-by: Richard Weinberger --- fs/jffs2/fs.c | 1 - 1 file changed, 1 deletion(-) diff --git a/fs/jffs2/fs.c b/fs/jffs2/fs.c index e96c6b0..3c96f4b 100644 --- a/fs/jffs2/fs.c +++ b/fs/jffs2/fs.c @@ -362,7 +362,6 @@ struct inode *jffs2_iget(struct super_block *sb, unsigned long ino) ret = -EIO; error: mutex_unlock(&f->sem); - jffs2_do_clear_inode(c, f); iget_failed(inode); return ERR_PTR(ret); }