Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1327486pxu; Mon, 23 Nov 2020 18:41:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJxNjLrAzmrI12TxWHvgdHaOX193aZKyhl9mdWOWqGNh5eICq29+2bpk0pDSOmLpHJaAq3Gq X-Received: by 2002:a17:906:6896:: with SMTP id n22mr2467154ejr.56.1606185708311; Mon, 23 Nov 2020 18:41:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606185708; cv=none; d=google.com; s=arc-20160816; b=OehAFZTJhGLS3VGQsybYpDpeH1ZkehjbhhGqNFQyyh7ysKw9/tKsopLRBM9Xg4MT/N 4L+mhw86kYwLPfKOXndrNfEQ17AbyEJqwIzX29bcoWFdmzHfGuNKdRYU+qkcBPgbo/WM 9dGMm/+ftpm8TB2GQoI07VnltnC/Ihudu/N0iv9qiAxMy5o/alC+Ce33/j2sELx2rWXr q5yCLL8IrqRFbAo3Y+1KefVu6rD8XZTGPbwizO5q9rUGmKSlRucKox7pgPqhzg8DuhlO ILJiwCpM4E9L5DCcudM9ZGNKEpDWHPTVgqGq8aN8R2Uc846Us9kbV0te07kVIA3Hcx39 UA4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=3ZWG64QxxO6aS88l5pmFvyg4e5MI+vXt84DGkkg2GvU=; b=JBg7ODTZ5ZxaBUpVyIGuOvYeZI1Wv2pk+m060X/+MRhN1bI31QkX+0obK2IrXFocT2 xez8mti6+RzMdbfv+QqEq4Lnn9SFuLeJ5VVXHRjpbPH4yg7NNYm+f9gDdVnH33ooD6RV W50JHyd2WRqg91g2rEeI4dpgvXr/1AgiC5JiDRoplSV7B+CZMcidL6pZRxem0c5rmd3g vvSzReTuYJBqdcL+A5bojTDCLJ4VO7Q35pPOKX+J3Pi8xderkYRytk/qnYcAsrs0ldgY E+si3CZRdiRJCGRBw0phIrmsgOxfb/em252Oc5n/le67e9RnM3Fhv8SEPFFT0jzMhkjO ZQiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=l6CmjQdl; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j6si7642741edn.551.2020.11.23.18.41.25; Mon, 23 Nov 2020 18:41:48 -0800 (PST) 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=@linuxfoundation.org header.s=korg header.b=l6CmjQdl; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387671AbgKWNJq (ORCPT + 99 others); Mon, 23 Nov 2020 08:09:46 -0500 Received: from mail.kernel.org ([198.145.29.99]:33634 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732833AbgKWMsk (ORCPT ); Mon, 23 Nov 2020 07:48:40 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 8CEDA21741; Mon, 23 Nov 2020 12:48:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1606135694; bh=q0QIVCw7tDMrcy/bO5wyJr/RaP70CkiRD/Zl1SwA028=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=l6CmjQdlKzT8IP/EuBQO/C10br1WadZOaK562Bxu9dVCkkqYSmJzQ2+cdAg2uXxjy oXGbrDhCTI7atJZANJ7sLsGQulmNIXQnSFy9xfSTg1OD9vcrN/aa56XN0hASwojFza vgNIy/540MAMFp6guk0k5TdqQRraenYC5V+wPss8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Darrick J. Wong" , Chandan Babu R , Christoph Hellwig , Sasha Levin Subject: [PATCH 5.9 162/252] xfs: directory scrub should check the null bestfree entries too Date: Mon, 23 Nov 2020 13:21:52 +0100 Message-Id: <20201123121843.409030494@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201123121835.580259631@linuxfoundation.org> References: <20201123121835.580259631@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Darrick J. Wong [ Upstream commit 6b48e5b8a20f653b7d64ccf99a498f2523bff752 ] Teach the directory scrubber to check all the bestfree entries, including the null ones. We want to be able to detect the case where the entry is null but there actually /is/ a directory data block. Found by fuzzing lbests[0] = ones in xfs/391. Fixes: df481968f33b ("xfs: scrub directory freespace") Signed-off-by: Darrick J. Wong Reviewed-by: Chandan Babu R Reviewed-by: Christoph Hellwig Signed-off-by: Sasha Levin --- fs/xfs/scrub/dir.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/fs/xfs/scrub/dir.c b/fs/xfs/scrub/dir.c index 7c432997edade..b045e95c2ea73 100644 --- a/fs/xfs/scrub/dir.c +++ b/fs/xfs/scrub/dir.c @@ -558,14 +558,27 @@ xchk_directory_leaf1_bestfree( /* Check all the bestfree entries. */ for (i = 0; i < bestcount; i++, bestp++) { best = be16_to_cpu(*bestp); - if (best == NULLDATAOFF) - continue; error = xfs_dir3_data_read(sc->tp, sc->ip, - i * args->geo->fsbcount, 0, &dbp); + xfs_dir2_db_to_da(args->geo, i), + XFS_DABUF_MAP_HOLE_OK, + &dbp); if (!xchk_fblock_process_error(sc, XFS_DATA_FORK, lblk, &error)) break; - xchk_directory_check_freesp(sc, lblk, dbp, best); + + if (!dbp) { + if (best != NULLDATAOFF) { + xchk_fblock_set_corrupt(sc, XFS_DATA_FORK, + lblk); + break; + } + continue; + } + + if (best == NULLDATAOFF) + xchk_fblock_set_corrupt(sc, XFS_DATA_FORK, lblk); + else + xchk_directory_check_freesp(sc, lblk, dbp, best); xfs_trans_brelse(sc->tp, dbp); if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT) break; -- 2.27.0