From patchwork Tue Sep 29 11:00:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 263375 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B8836C4727C for ; Tue, 29 Sep 2020 11:09:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 55263221E7 for ; Tue, 29 Sep 2020 11:09:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601377768; bh=sBa5jtK4Ogcxf59q+B0NA+czpwQc2U756MZkaPFr8UQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=Tfbu9d3sHTnsyotXWHzjPiTce4heGgwrEsL2yl7eGAmvUqEXNaBCmne2uoP5iHc9K 52c/TfP8M3L0RE83zV1TWXsquASSEPj60fuMsGEM4iCKiDXgP3b8R9G9kT/wGmOoeg n/oylBfIOe/CMo802HNKV/8+4sWHv11WYETFa5TE= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729063AbgI2LJQ (ORCPT ); Tue, 29 Sep 2020 07:09:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:49414 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728757AbgI2LJP (ORCPT ); Tue, 29 Sep 2020 07:09:15 -0400 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 6A42C21D46; Tue, 29 Sep 2020 11:09:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601377755; bh=sBa5jtK4Ogcxf59q+B0NA+czpwQc2U756MZkaPFr8UQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=w5QJkffLqfEu4ZDELPiLoS7ZUiFzjrnQdB0wn6wZ59oifg7i2VQyXPh+PSSRB8Q89 5Z7eIbxB48qSIrhPpm3sygC1rUQcEjRTb2krG2FmdS6UVtO1YTXcXB3FQ9GeC/sHaK DczjX2cvl90nvF9Cbyd1YCyCyeWQvRieXOMc7jz4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Darrick J. Wong" , Dave Chinner , Sasha Levin Subject: [PATCH 4.9 061/121] xfs: dont ever return a stale pointer from __xfs_dir3_free_read Date: Tue, 29 Sep 2020 13:00:05 +0200 Message-Id: <20200929105933.197599878@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200929105930.172747117@linuxfoundation.org> References: <20200929105930.172747117@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Darrick J. Wong [ Upstream commit 1cb5deb5bc095c070c09a4540c45f9c9ba24be43 ] If we decide that a directory free block is corrupt, we must take care not to leak a buffer pointer to the caller. After xfs_trans_brelse returns, the buffer can be freed or reused, which means that we have to set *bpp back to NULL. Callers are supposed to notice the nonzero return value and not use the buffer pointer, but we should code more defensively, even if all current callers handle this situation correctly. Fixes: de14c5f541e7 ("xfs: verify free block header fields") Signed-off-by: Darrick J. Wong Reviewed-by: Dave Chinner Signed-off-by: Sasha Levin --- fs/xfs/libxfs/xfs_dir2_node.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/xfs/libxfs/xfs_dir2_node.c b/fs/xfs/libxfs/xfs_dir2_node.c index bbd1238852b3c..df7f33e60a4f6 100644 --- a/fs/xfs/libxfs/xfs_dir2_node.c +++ b/fs/xfs/libxfs/xfs_dir2_node.c @@ -212,6 +212,7 @@ __xfs_dir3_free_read( xfs_buf_ioerror(*bpp, -EFSCORRUPTED); xfs_verifier_error(*bpp); xfs_trans_brelse(tp, *bpp); + *bpp = NULL; return -EFSCORRUPTED; }