Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3027288ybt; Mon, 29 Jun 2020 13:16:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxbFaPskyaGP9SE0bSqcCz9e3Kgp+WmB/pISK+w3abOdMezmVcGufeBP3eCKUnztWFEhVvK X-Received: by 2002:aa7:d457:: with SMTP id q23mr16580414edr.376.1593461800705; Mon, 29 Jun 2020 13:16:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593461800; cv=none; d=google.com; s=arc-20160816; b=NC/4MKvRgK7spjq0lDK0fFX49bHumNQ7c6Iv8ryOHxQSSR+mpaDttaKrkC6rJOSYaf XpMCsVkmqAA91JeVfyG3uFtWHgYi/KhhQS+zzaCGYa4OBfzEWjktIGEiwJPplEbxXHNQ 0X/Z0TCfFWWRqpWDSs98ByZBMTP1FNWZhzmxPPTAw0I0/73qRN/8h+Zgq8ol/h0uDnzx a95KmwVMNi1QGphOTxyQ2qwXV8JEIXyo3g9bCGJhDu1aXXxOchzWmpawlXrFdD2yhRyy sUsbsV87khhKrZ9X/ws7Onfz+zyh+HXH5zPzLVyqogSvDudGgjjk6RTOJ6c8KA1aFdFZ vY2Q== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=LkVn+uVhAW0KqF/unpIbsARl0hjHDt/HU2Ji6iOFyW4=; b=lmO0fK4nc4iFPqkg+f81IKzJomrH1xhvfl4eaTCJeAqM6zFZTYgimVPfRJIUU8r/6g kcqDWv51EWhKbJojUs6RHLf46p8bgHc+X46RC1UheOZbd8fXT+pFlhGFFI0LAnVIpXlJ LxNaY8OJ2FxXVycKmDut2g/USKkbrAvSqmUoMoVVr9T3mgjcWLrRl54mmEMFEV/EfRxV N2qmm9srmUDXALx85CMPyKOhknun5pQkS2+3gY7PWBqHimVAiWG87Hz3/b/BF3wQnfMC /TPvP88Vyo+c0kyqRwrqt44K0QhI4MKLXmtTu9MftTqTyDIRfScbtChDkl/Zn6w32PJB ln7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=pQLu5WU7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e17si322484ejk.740.2020.06.29.13.16.17; Mon, 29 Jun 2020 13:16:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=pQLu5WU7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730933AbgF2UNB (ORCPT + 99 others); Mon, 29 Jun 2020 16:13:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:40566 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732864AbgF2TaU (ORCPT ); Mon, 29 Jun 2020 15:30:20 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6AFA0252C2; Mon, 29 Jun 2020 15:37:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593445033; bh=ggQCab5KnLpw64gdJWdLsmih1qKl8lrZLrqWHjsEGhA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pQLu5WU7uuZUS0JRZpOYLDykua5YJElDatFH3CQHIoPLJO+/+xt65cwJwYvmLHAX2 t4W03Ac/WY1Me8PzuUaH8gypEn37Bk+jFMyLa6gCRImqdNspFr2kCU7CgizgyOLxEe 5G7528clDttXd75kZVjLKeeL4X2xXKa2BF6BXi3E= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Zheng Bin , Ren Xudong , "Darrick J . Wong" , Sasha Levin Subject: [PATCH 4.19 130/131] xfs: add agf freeblocks verify in xfs_agf_verify Date: Mon, 29 Jun 2020 11:35:01 -0400 Message-Id: <20200629153502.2494656-131-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200629153502.2494656-1-sashal@kernel.org> References: <20200629153502.2494656-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v4.x/stable-review/patch-4.19.131-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-4.19.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 4.19.131-rc1 X-KernelTest-Deadline: 2020-07-01T15:34+00:00 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zheng Bin [ Upstream commit d0c7feaf87678371c2c09b3709400be416b2dc62 ] We recently used fuzz(hydra) to test XFS and automatically generate tmp.img(XFS v5 format, but some metadata is wrong) xfs_repair information(just one AG): agf_freeblks 0, counted 3224 in ag 0 agf_longest 536874136, counted 3224 in ag 0 sb_fdblocks 613, counted 3228 Test as follows: mount tmp.img tmpdir cp file1M tmpdir sync In 4.19-stable, sync will stuck, the reason is: xfs_mountfs xfs_check_summary_counts if ((!xfs_sb_version_haslazysbcount(&mp->m_sb) || XFS_LAST_UNMOUNT_WAS_CLEAN(mp)) && !xfs_fs_has_sickness(mp, XFS_SICK_FS_COUNTERS)) return 0; -->just return, incore sb_fdblocks still be 613 xfs_initialize_perag_data cp file1M tmpdir -->ok(write file to pagecache) sync -->stuck(write pagecache to disk) xfs_map_blocks xfs_iomap_write_allocate while (count_fsb != 0) { nimaps = 0; while (nimaps == 0) { --> endless loop nimaps = 1; xfs_bmapi_write(..., &nimaps) --> nimaps becomes 0 again xfs_bmapi_write xfs_bmap_alloc xfs_bmap_btalloc xfs_alloc_vextent xfs_alloc_fix_freelist xfs_alloc_space_available -->fail(agf_freeblks is 0) In linux-next, sync not stuck, cause commit c2b3164320b5 ("xfs: use the latest extent at writeback delalloc conversion time") remove the above while, dmesg is as follows: [ 55.250114] XFS (loop0): page discard on page ffffea0008bc7380, inode 0x1b0c, offset 0. Users do not know why this page is discard, the better soultion is: 1. Like xfs_repair, make sure sb_fdblocks is equal to counted (xfs_initialize_perag_data did this, who is not called at this mount) 2. Add agf verify, if fail, will tell users to repair This patch use the second soultion. Signed-off-by: Zheng Bin Signed-off-by: Ren Xudong Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Signed-off-by: Sasha Levin --- fs/xfs/libxfs/xfs_alloc.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/fs/xfs/libxfs/xfs_alloc.c b/fs/xfs/libxfs/xfs_alloc.c index e1c0c0d2f1b05..1eb7933dac83e 100644 --- a/fs/xfs/libxfs/xfs_alloc.c +++ b/fs/xfs/libxfs/xfs_alloc.c @@ -2596,6 +2596,13 @@ xfs_agf_verify( be32_to_cpu(agf->agf_flcount) <= xfs_agfl_size(mp))) return __this_address; + if (be32_to_cpu(agf->agf_length) > mp->m_sb.sb_dblocks) + return __this_address; + + if (be32_to_cpu(agf->agf_freeblks) < be32_to_cpu(agf->agf_longest) || + be32_to_cpu(agf->agf_freeblks) > be32_to_cpu(agf->agf_length)) + return __this_address; + if (be32_to_cpu(agf->agf_levels[XFS_BTNUM_BNO]) < 1 || be32_to_cpu(agf->agf_levels[XFS_BTNUM_CNT]) < 1 || be32_to_cpu(agf->agf_levels[XFS_BTNUM_BNO]) > XFS_BTREE_MAXLEVELS || @@ -2607,6 +2614,10 @@ xfs_agf_verify( be32_to_cpu(agf->agf_levels[XFS_BTNUM_RMAP]) > XFS_BTREE_MAXLEVELS)) return __this_address; + if (xfs_sb_version_hasrmapbt(&mp->m_sb) && + be32_to_cpu(agf->agf_rmap_blocks) > be32_to_cpu(agf->agf_length)) + return __this_address; + /* * during growfs operations, the perag is not fully initialised, * so we can't use it for any useful checking. growfs ensures we can't @@ -2620,6 +2631,11 @@ xfs_agf_verify( be32_to_cpu(agf->agf_btreeblks) > be32_to_cpu(agf->agf_length)) return __this_address; + if (xfs_sb_version_hasreflink(&mp->m_sb) && + be32_to_cpu(agf->agf_refcount_blocks) > + be32_to_cpu(agf->agf_length)) + return __this_address; + if (xfs_sb_version_hasreflink(&mp->m_sb) && (be32_to_cpu(agf->agf_refcount_level) < 1 || be32_to_cpu(agf->agf_refcount_level) > XFS_BTREE_MAXLEVELS)) -- 2.25.1