From patchwork Mon Jul 11 06:43:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: kernel@kyup.com X-Patchwork-Id: 9222929 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 46EED60572 for ; Mon, 11 Jul 2016 06:43:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3423D279E0 for ; Mon, 11 Jul 2016 06:43:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 25B9027BFC; Mon, 11 Jul 2016 06:43:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9DC24279E0 for ; Mon, 11 Jul 2016 06:43:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757877AbcGKGnT (ORCPT ); Mon, 11 Jul 2016 02:43:19 -0400 Received: from mail-wm0-f41.google.com ([74.125.82.41]:38803 "EHLO mail-wm0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757749AbcGKGnS (ORCPT ); Mon, 11 Jul 2016 02:43:18 -0400 Received: by mail-wm0-f41.google.com with SMTP id o80so36375435wme.1 for ; Sun, 10 Jul 2016 23:43:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=HuQDyBYJgNvKdOeLN0venQgE0Q93VX2fEkttbyXU6DI=; b=iB7h5MzOVB72v6kEr8t0v8ah/l6Heb/uCusefC7aIoRdF2jQhuzsBZRSK5W+ImSOMK aL7lXqby60MKnhU2mXxq9cEcLjnOJ0tnFQnE7b1dOLncRyPh7uEv4Q6PPJsJI4ybDpiv o1lQGLaGbKUEDwQebtxJKvTo/qF9NGkY5v0aGSzXxE8QeWkC6ywGxRKrAapLozyXDDrQ ShWQ/ftSgFawNxSgwu25UOZIwvrSLtnzotEgrdjM0SkHC7HpMjnR8nJsVzZI7wsg6vdv t1r/HNfrsbZA4AuMMBtEv1coicXYJ00h0Q1/pa/MJp0oqn1hDaliyPGGfnyFkmJ/sOU4 O1ag== X-Gm-Message-State: ALyK8tI3BWp1wgU+4KPOq8muFaNU8OxkS8+/8m6jrXRVNjIbwp8olm9bTc79UJLTj9oZ0ThX X-Received: by 10.28.132.15 with SMTP id g15mr17697782wmd.67.1468219396555; Sun, 10 Jul 2016 23:43:16 -0700 (PDT) Received: from localhost.localdomain (admins.1h.com. [82.118.240.130]) by smtp.gmail.com with ESMTPSA id d8sm3968556wmi.0.2016.07.10.23.43.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 10 Jul 2016 23:43:15 -0700 (PDT) From: Nikolay Borisov To: clm@fb.com Cc: linux-btrfs@vger.kernel.org, Nikolay Borisov Subject: [RESEND PATCH] btrfs: Handle uninitialised inode eviction Date: Mon, 11 Jul 2016 09:43:09 +0300 Message-Id: <1468219389-28736-1-git-send-email-kernel@kyup.com> X-Mailer: git-send-email 1.7.1 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The code flow in btrfs_new_inode allows for btrfs_evict_inode to be called with not fully initialised inode (e.g. ->root member not being set). This can happen when btrfs_set_inode_index in btrfs_new_inode fails, which in turn would call iput for the newly allocated inode. This in turn leads to vfs calling into btrfs_evict_inode. This leads to null pointer dereference. To handle this situation check whether the passed inode has root set and just free it in case it doesn't. Signed-off-by: Nikolay Borisov Reviewed-by: Josef Bacik --- fs/btrfs/inode.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) Hello, I belive this is fixes the issue reported in http://thread.gmane.org/gmane.comp.file-systems.btrfs/57809 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 4421954720b8..b51723811d01 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -5159,11 +5159,18 @@ void btrfs_evict_inode(struct inode *inode) struct btrfs_root *root = BTRFS_I(inode)->root; struct btrfs_block_rsv *rsv, *global_rsv; int steal_from_global = 0; - u64 min_size = btrfs_calc_trunc_metadata_size(root, 1); + u64 min_size; int ret; trace_btrfs_inode_evict(inode); + if (!root) { + kmem_cache_free(btrfs_inode_cachep, BTRFS_I(inode)); + return; + } + + min_size = btrfs_calc_trunc_metadata_size(root, 1); + evict_inode_truncate_pages(inode); if (inode->i_nlink &&