Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp5849490ybn; Sun, 29 Sep 2019 07:03:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqzUsh/584c8FC7NZAb13TeQLVIXTYKAIxO3N3UlkiwQxIWPcJvOygC+0gzEsRoabN6v+vpl X-Received: by 2002:a17:906:7802:: with SMTP id u2mr6237704ejm.3.1569765797723; Sun, 29 Sep 2019 07:03:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569765797; cv=none; d=google.com; s=arc-20160816; b=wL+fzmtUb71VTv+rf4SfUpLLOFtByi+Q+Uck3o0ZkIYRUQ7OnoUznchhrZ4vfWqMSL XvmhSH6ZH7QNBWcyaqXFnkJW4fO0rkRW2UVu5owr26WYDCoCi4hzMSbfQaWLIpqAuBIu 2HiOxx0dl+FAWhcc6W/GiuhnPtdG/1jzxWCG6MtZMEn6UPkdYk7Tw3F/tvSD15D8GGf/ AMD6QrGLF2d9jVgRHLyPSfugZuIluIrW76smp2v/g1CZbpHXLA6VKGg9kTk260YTUWqo I00igQdg7o6Tu6kj0XI7VAAPuBRWAMfZEL/iZPqMPjU/DlaxB36p88WzznJof3CCMWbs 0jOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Lz3kcAdwdU6ZZi4ZtJLMK/x5cThW9d+aFEZqqmU3fFc=; b=uhgsGNmBh3LhW2Re5w4YTQQHSxBIiHt1WomMQ4GnFWs+A8snQa+8cpfn01kGy6n7GF VMSE6HBM/4heJqCfJHg67xS9tfbYAbVJo0v6OMbSTAUS9MlDqUsokUOG7xh2iYaWEGTc H6Rja2fgV408Ik6Dn+ISJJaqnCW4Jithvh19HQghBhSHb/xg76oKPdam3LWr4GKCU8NM yPIi2uoF/qP2j9Bu2eGHP7qblcHqS1fz2GNosphsQqOE2G9BxZi222qPsM0eX6RYedMN 6pVaOkeSdWf5W1faYA+ldCYOuApOs52RTFupgApt0B6oe72dav5XdeRleJTlOeZJMTrt QCsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=veP+XsK6; 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 q25si5474939edb.159.2019.09.29.07.02.53; Sun, 29 Sep 2019 07:03:17 -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=veP+XsK6; 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 S1729869AbfI2OAK (ORCPT + 99 others); Sun, 29 Sep 2019 10:00:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:41742 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729861AbfI2OAI (ORCPT ); Sun, 29 Sep 2019 10:00:08 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 ACD212082F; Sun, 29 Sep 2019 14:00:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1569765607; bh=tKpXY8ElDAeEgxlJooPgCw+vML5MxqS6+d5E+GHMPlI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=veP+XsK6J0AdLybrVqeHZNm0SWp1QJHWbI0ooz2V5IPmoyGc7jpNkayqBeeZPG2H3 1drR4qLsSwH+lKPFV/GG1JqKBok+LP5A/wBxKJH0zP481NlLsssH6aOfm/qjWsaDYd lbT8x74XFg2NFhTjxaFy6VkpYpoBMZyusyFumvIc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zorro Lang , "Darrick J. Wong" , Bill ODonnell , Sasha Levin Subject: [PATCH 4.19 59/63] xfs: dont crash on null attr fork xfs_bmapi_read Date: Sun, 29 Sep 2019 15:54:32 +0200 Message-Id: <20190929135041.113693934@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190929135031.382429403@linuxfoundation.org> References: <20190929135031.382429403@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Darrick J. Wong [ Upstream commit 8612de3f7ba6e900465e340516b8313806d27b2d ] Zorro Lang reported a crash in generic/475 if we try to inactivate a corrupt inode with a NULL attr fork (stack trace shortened somewhat): RIP: 0010:xfs_bmapi_read+0x311/0xb00 [xfs] RSP: 0018:ffff888047f9ed68 EFLAGS: 00010202 RAX: dffffc0000000000 RBX: ffff888047f9f038 RCX: 1ffffffff5f99f51 RDX: 0000000000000002 RSI: 0000000000000008 RDI: 0000000000000012 RBP: ffff888002a41f00 R08: ffffed10005483f0 R09: ffffed10005483ef R10: ffffed10005483ef R11: ffff888002a41f7f R12: 0000000000000004 R13: ffffe8fff53b5768 R14: 0000000000000005 R15: 0000000000000001 FS: 00007f11d44b5b80(0000) GS:ffff888114200000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000000000ef6000 CR3: 000000002e176003 CR4: 00000000001606e0 Call Trace: xfs_dabuf_map.constprop.18+0x696/0xe50 [xfs] xfs_da_read_buf+0xf5/0x2c0 [xfs] xfs_da3_node_read+0x1d/0x230 [xfs] xfs_attr_inactive+0x3cc/0x5e0 [xfs] xfs_inactive+0x4c8/0x5b0 [xfs] xfs_fs_destroy_inode+0x31b/0x8e0 [xfs] destroy_inode+0xbc/0x190 xfs_bulkstat_one_int+0xa8c/0x1200 [xfs] xfs_bulkstat_one+0x16/0x20 [xfs] xfs_bulkstat+0x6fa/0xf20 [xfs] xfs_ioc_bulkstat+0x182/0x2b0 [xfs] xfs_file_ioctl+0xee0/0x12a0 [xfs] do_vfs_ioctl+0x193/0x1000 ksys_ioctl+0x60/0x90 __x64_sys_ioctl+0x6f/0xb0 do_syscall_64+0x9f/0x4d0 entry_SYSCALL_64_after_hwframe+0x49/0xbe RIP: 0033:0x7f11d39a3e5b The "obvious" cause is that the attr ifork is null despite the inode claiming an attr fork having at least one extent, but it's not so obvious why we ended up with an inode in that state. Reported-by: Zorro Lang Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=204031 Signed-off-by: Darrick J. Wong Reviewed-by: Bill O'Donnell Signed-off-by: Sasha Levin --- fs/xfs/libxfs/xfs_bmap.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index 06a7da8dbda5c..38dc0b43c3665 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -3841,15 +3841,28 @@ xfs_bmapi_read( XFS_STATS_INC(mp, xs_blk_mapr); ifp = XFS_IFORK_PTR(ip, whichfork); + if (!ifp) { + /* No CoW fork? Return a hole. */ + if (whichfork == XFS_COW_FORK) { + mval->br_startoff = bno; + mval->br_startblock = HOLESTARTBLOCK; + mval->br_blockcount = len; + mval->br_state = XFS_EXT_NORM; + *nmap = 1; + return 0; + } - /* No CoW fork? Return a hole. */ - if (whichfork == XFS_COW_FORK && !ifp) { - mval->br_startoff = bno; - mval->br_startblock = HOLESTARTBLOCK; - mval->br_blockcount = len; - mval->br_state = XFS_EXT_NORM; - *nmap = 1; - return 0; + /* + * A missing attr ifork implies that the inode says we're in + * extents or btree format but failed to pass the inode fork + * verifier while trying to load it. Treat that as a file + * corruption too. + */ +#ifdef DEBUG + xfs_alert(mp, "%s: inode %llu missing fork %d", + __func__, ip->i_ino, whichfork); +#endif /* DEBUG */ + return -EFSCORRUPTED; } if (!(ifp->if_flags & XFS_IFEXTENTS)) { -- 2.20.1