From patchwork Mon Nov 20 18:31:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13461856 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EC7A5C2BB3F for ; Mon, 20 Nov 2023 18:31:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230229AbjKTSbn (ORCPT ); Mon, 20 Nov 2023 13:31:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48748 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229497AbjKTSbm (ORCPT ); Mon, 20 Nov 2023 13:31:42 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0207CD for ; Mon, 20 Nov 2023 10:31:39 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6220FC433C7; Mon, 20 Nov 2023 18:31:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700505099; bh=LWGYxjl7IvPfAnPTQ+tP0ChwxVYMjuKVLgOEtHJ7M1c=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=QuFFtFDb0wrjVZMQphIumTYsjBftphR3xQwUPEmFdyN5O7iKkBEWmBeT2JYwGFNu2 ZAo7ZxLt06qOKzNpXQOCuSMvhud1J0NA5ncc9pggUNsz9kJEcD2lQARSAzFAXDTDk+ J9wucEvPwzBG/8clOlbx6kjwflSTDA+54Jx+fzY+2Z2ZE71P7CG+iMXhaZqMOI2hOc v7hPm2gaGDOQfNpnzfrSaaWyEZDn/LtyL9YBSexA04gCObLT1AX00eO5xiqNIOfMMs Bwk4ReQiKXqHLmbKXCNtn4W4r6rxB8zM27+ElJqfI+rvEhAcTh41k+dACkjIOtsb2T oHCs0SAPja/ag== Subject: [PATCH 1/2] xfs: clean up dqblk extraction From: "Darrick J. Wong" To: david@fromorbit.com, djwong@kernel.org, chandanbabu@kernel.org Cc: linux-xfs@vger.kernel.org Date: Mon, 20 Nov 2023 10:31:38 -0800 Message-ID: <170050509891.475996.3583155500177528277.stgit@frogsfrogsfrogs> In-Reply-To: <170050509316.475996.582959032103929936.stgit@frogsfrogsfrogs> References: <170050509316.475996.582959032103929936.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Since the introduction of xfs_dqblk in V5, xfs really ought to find the dqblk pointer from the dquot buffer, then compute the xfs_disk_dquot pointer from the dqblk pointer. Fix the open-coded xfs_buf_offset calls and do the type checking in the correct order. Note that this has made no practical difference since the start of the xfs_disk_dquot is coincident with the start of the xfs_dqblk. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Reviewed-by: Dave Chinner --- fs/xfs/xfs_dquot.c | 5 +++-- fs/xfs/xfs_dquot_item_recover.c | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/fs/xfs/xfs_dquot.c b/fs/xfs/xfs_dquot.c index ac6ba646624d..a013b87ab8d5 100644 --- a/fs/xfs/xfs_dquot.c +++ b/fs/xfs/xfs_dquot.c @@ -562,7 +562,8 @@ xfs_dquot_from_disk( struct xfs_dquot *dqp, struct xfs_buf *bp) { - struct xfs_disk_dquot *ddqp = bp->b_addr + dqp->q_bufoffset; + struct xfs_dqblk *dqb = xfs_buf_offset(bp, dqp->q_bufoffset); + struct xfs_disk_dquot *ddqp = &dqb->dd_diskdq; /* * Ensure that we got the type and ID we were looking for. @@ -1250,7 +1251,7 @@ xfs_qm_dqflush( } /* Flush the incore dquot to the ondisk buffer. */ - dqblk = bp->b_addr + dqp->q_bufoffset; + dqblk = xfs_buf_offset(bp, dqp->q_bufoffset); xfs_dquot_to_disk(&dqblk->dd_diskdq, dqp); /* diff --git a/fs/xfs/xfs_dquot_item_recover.c b/fs/xfs/xfs_dquot_item_recover.c index 8966ba842395..db2cb5e4197b 100644 --- a/fs/xfs/xfs_dquot_item_recover.c +++ b/fs/xfs/xfs_dquot_item_recover.c @@ -65,6 +65,7 @@ xlog_recover_dquot_commit_pass2( { struct xfs_mount *mp = log->l_mp; struct xfs_buf *bp; + struct xfs_dqblk *dqb; struct xfs_disk_dquot *ddq, *recddq; struct xfs_dq_logformat *dq_f; xfs_failaddr_t fa; @@ -130,14 +131,14 @@ xlog_recover_dquot_commit_pass2( return error; ASSERT(bp); - ddq = xfs_buf_offset(bp, dq_f->qlf_boffset); + dqb = xfs_buf_offset(bp, dq_f->qlf_boffset); + ddq = &dqb->dd_diskdq; /* * If the dquot has an LSN in it, recover the dquot only if it's less * than the lsn of the transaction we are replaying. */ if (xfs_has_crc(mp)) { - struct xfs_dqblk *dqb = (struct xfs_dqblk *)ddq; xfs_lsn_t lsn = be64_to_cpu(dqb->dd_lsn); if (lsn && lsn != -1 && XFS_LSN_CMP(lsn, current_lsn) >= 0) { @@ -147,7 +148,7 @@ xlog_recover_dquot_commit_pass2( memcpy(ddq, recddq, item->ri_buf[1].i_len); if (xfs_has_crc(mp)) { - xfs_update_cksum((char *)ddq, sizeof(struct xfs_dqblk), + xfs_update_cksum((char *)dqb, sizeof(struct xfs_dqblk), XFS_DQUOT_CRC_OFF); } From patchwork Mon Nov 20 18:31:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13461857 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7842CC2BB3F for ; Mon, 20 Nov 2023 18:31:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231680AbjKTSbt (ORCPT ); Mon, 20 Nov 2023 13:31:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229497AbjKTSbs (ORCPT ); Mon, 20 Nov 2023 13:31:48 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74032C4 for ; Mon, 20 Nov 2023 10:31:45 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 06CC3C433C9; Mon, 20 Nov 2023 18:31:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700505105; bh=ML45LT19vOJjbCYI9gw1n0kSqKngdZuIE6GiaOeyCVw=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=q2t6/Zf/186MSYKuOkPWs1pJ2qmVVU+SL6uCm3DgnSRKp40l3k9qZiZJyZ8Le0XvT kqV+RwlXeoSyT4C2kzIzDqyo5RvtliOfF7dDxTlGARM5riCe166C3/YZMdb/aRAA6v 3IsaL2VVNwCCBm+cVUJMvHO/K24bs+fS94sQ5253yG/zAAz66d4fnyVunSNWC0Jqm8 eDJIXQ9Jx51DcnHNk+8lLioTm5Un0eJR5gzUaDb4O75NCdAKiJ5bPZ+uhhM/7RXeKs yF1PI1JTG21TxSdyq0pqMiXbGk33pequ6a1Gub80yNWEVsDpj8pS6p7cJJlWv9r7e2 nmoVAnpzOEdag== Subject: [PATCH 2/2] xfs: dquot recovery does not validate the recovered dquot From: "Darrick J. Wong" To: david@fromorbit.com, djwong@kernel.org, chandanbabu@kernel.org Cc: linux-xfs@vger.kernel.org Date: Mon, 20 Nov 2023 10:31:44 -0800 Message-ID: <170050510455.475996.9499832219704912265.stgit@frogsfrogsfrogs> In-Reply-To: <170050509316.475996.582959032103929936.stgit@frogsfrogsfrogs> References: <170050509316.475996.582959032103929936.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong When we're recovering ondisk quota records from the log, we need to validate the recovered buffer contents before writing them to disk. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Reviewed-by: Dave Chinner --- fs/xfs/xfs_dquot_item_recover.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/fs/xfs/xfs_dquot_item_recover.c b/fs/xfs/xfs_dquot_item_recover.c index db2cb5e4197b..2c2720ce6923 100644 --- a/fs/xfs/xfs_dquot_item_recover.c +++ b/fs/xfs/xfs_dquot_item_recover.c @@ -19,6 +19,7 @@ #include "xfs_log.h" #include "xfs_log_priv.h" #include "xfs_log_recover.h" +#include "xfs_error.h" STATIC void xlog_recover_dquot_ra_pass2( @@ -152,6 +153,19 @@ xlog_recover_dquot_commit_pass2( XFS_DQUOT_CRC_OFF); } + /* Validate the recovered dquot. */ + fa = xfs_dqblk_verify(log->l_mp, dqb, dq_f->qlf_id); + if (fa) { + XFS_CORRUPTION_ERROR("Bad dquot after recovery", + XFS_ERRLEVEL_LOW, mp, dqb, + sizeof(struct xfs_dqblk)); + xfs_alert(mp, + "Metadata corruption detected at %pS, dquot 0x%x", + fa, dq_f->qlf_id); + error = -EFSCORRUPTED; + goto out_release; + } + ASSERT(dq_f->qlf_size == 2); ASSERT(bp->b_mount == mp); bp->b_flags |= _XBF_LOGRECOVERY;