From patchwork Wed Dec 4 03:02:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13893160 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5C2B2FC1D; Wed, 4 Dec 2024 03:02:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733281350; cv=none; b=rLAaK1PiC6ZvhT+3sNatGLRALzPjE3CD7nO40pvSxGzP1/LtB1m5dsHjjX9U9b/s4aplG+NaZU4hO0BdJuwYP6ja0xL9EWLKAc7TRV/hEC1Y4YFj1mC4S0W+tfneO6Qg1u+Za488jwgKb6iAlM8pSA50ttXoclrwqgqhecDK+yk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733281350; c=relaxed/simple; bh=/9DMj9mCY56yShe+2B6QMa1OZCb0/du3Y3WzUpitJgY=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QbsqXWCWj8tpJ31fCIuRA53BdxOfS87IrjZXiJdhnttU/uvexG64jmI0EgTK4ZR9+0/Zf9KnVSDDOgOQFPEE3cSvxxql0zGGTZO2+VjAcO8uEHi25SGdJD/Syx+JmJT+35DUeIaGmCpY885XZ0ZPNJlFGtb8Kvvx3IzZLCa8KzI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BpaM0SNz; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="BpaM0SNz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F3170C4CEDC; Wed, 4 Dec 2024 03:02:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733281350; bh=/9DMj9mCY56yShe+2B6QMa1OZCb0/du3Y3WzUpitJgY=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=BpaM0SNzPf26KIBHUmqzyoaSXs3AEubpPheJH52IJdlHOxBE5dtFzMZh+qROcuc2u 8kfw0nBeYRmj4tdnV10LzrGJMk9QTPbVWE9rc3G+IKQ9xmRTRL4YiUD629whctX871 f3531PsbR/YgQ6opsT0MyW6zNirYMiuJkCtr1RRBxOr1uw/GHpF6rXKHlzTv2yxdrj RpsOaObfbvlEtjkN0uyoZS3ILXHPOJLAIBzGF2CPt+MYZ/C8DcI5q7n3Fq5Ezo6jXQ d1eNuaOhUzVTjtwdFAFqGbO1HFO9V90fRHJmQ1K1f4R124YJB+9s2r52mQgC9ktsM0 v/v863+zFxGfA== Date: Tue, 03 Dec 2024 19:02:29 -0800 Subject: [PATCH 1/6] xfs: don't move nondir/nonreg temporary repair files to the metadir namespace From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: stable@vger.kernel.org, linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <173328106602.1145623.16395857710576941601.stgit@frogsfrogsfrogs> In-Reply-To: <173328106571.1145623.3212405760436181793.stgit@frogsfrogsfrogs> References: <173328106571.1145623.3212405760436181793.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Only directories or regular files are allowed in the metadata directory tree. Don't move the repair tempfile to the metadir namespace if this is not true; this will cause the inode verifiers to trip. Cc: # v6.13-rc1 Fixes: 9dc31acb01a1c7 ("xfs: move repair temporary files to the metadata directory tree") Signed-off-by: "Darrick J. Wong" --- fs/xfs/scrub/tempfile.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/xfs/scrub/tempfile.c b/fs/xfs/scrub/tempfile.c index dc3802c7f678ce..82ecbb654fbb39 100644 --- a/fs/xfs/scrub/tempfile.c +++ b/fs/xfs/scrub/tempfile.c @@ -204,6 +204,9 @@ xrep_tempfile_adjust_directory_tree( if (!sc->ip || !xfs_is_metadir_inode(sc->ip)) return 0; + if (!S_ISDIR(VFS_I(sc->tempip)->i_mode) && + !S_ISREG(VFS_I(sc->tempip)->i_mode)) + return 0; xfs_ilock(sc->tempip, XFS_IOLOCK_EXCL); sc->temp_ilock_flags |= XFS_IOLOCK_EXCL; From patchwork Wed Dec 4 03:02:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13893161 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 32422FC1D; Wed, 4 Dec 2024 03:02:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733281366; cv=none; b=puSXMMgjBMCWFhaYpl4oj68B2EBy1KZCxrKRC1jBzhNF1J413xgYTwirZHKDuPZbxXFny1My4bb6qdsz6A97DNmaroBvQ9Vg9JKsiO1UwoKO+gS643GkPuAPBMBwizPu2WW/wqyP9d8WHscDUfmZxtMR9WjjvOaF0lY5VZJ+9eQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733281366; c=relaxed/simple; bh=Maz2LbzoGI6xm0fNVl+vVrV3CgDAB4vqWeM5uCVdx/s=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Df1l6eIy0EiNc2HbjIThelcGagEXy3AIrfIh7qJJZiiUkLdKdVmPV3M+2IeY+2Oo9/f2HDiyB1qc2Ge/vw2IVaYkf52zKCndY3wdeWlEobrfQTx2bhnltKIfKw6WDptNIB5UwmMW8zGPsN5pZJUc0vLHWny011lR8fFU1t+YRTU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=u6DdncGO; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="u6DdncGO" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B9336C4CEDC; Wed, 4 Dec 2024 03:02:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733281365; bh=Maz2LbzoGI6xm0fNVl+vVrV3CgDAB4vqWeM5uCVdx/s=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=u6DdncGOJzpy6rpafOJPXdePxfkDmOrlfgr2ZL1EgYgKgWMmrd7yyKSra28uXplXC xHPRTzOp9AKbtA/7+igIEIV1UaEzuHOYbhJEs+vYhH8yw8eqloKQOnrQYV2yvivgUh vH6sCaLdQKeTpiwA/j/ANeQOuwUw/oTmsN/hU0ae4DxjASQ7/TekyOKBjGNPr+txOu C8qEg0QHAwwxzTatQYZcZ5rJeAjlMEIlWeey/vCRKjayuRJ7Gki5noSy7v59egKt9b +3QTe+igDWqjVFoXlA9gQAQmQWr2B5lV58hCCPOAQX5SV2AmYS+DEPpleuoqqvS7nb fmCVfk0OmeQWg== Date: Tue, 03 Dec 2024 19:02:45 -0800 Subject: [PATCH 2/6] xfs: don't crash on corrupt /quotas dirent From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: stable@vger.kernel.org, linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <173328106618.1145623.18381388947501707203.stgit@frogsfrogsfrogs> In-Reply-To: <173328106571.1145623.3212405760436181793.stgit@frogsfrogsfrogs> References: <173328106571.1145623.3212405760436181793.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong If the /quotas dirent points to an inode but the inode isn't loadable (and hence mkdir returns -EEXIST), don't crash, just bail out. Cc: # v6.13-rc1 Fixes: e80fbe1ad8eff7 ("xfs: use metadir for quota inodes") Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- fs/xfs/xfs_qm.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fs/xfs/xfs_qm.c b/fs/xfs/xfs_qm.c index 69b70c3e999d72..dc8b1010d4d332 100644 --- a/fs/xfs/xfs_qm.c +++ b/fs/xfs/xfs_qm.c @@ -731,6 +731,13 @@ xfs_qm_create_metadir_qinos( error = xfs_dqinode_mkdir_parent(mp, &qi->qi_dirip); if (error && error != -EEXIST) return error; + /* + * If the /quotas dirent points to an inode that isn't + * loadable, qi_dirip will be NULL but mkdir_parent will return + * -EEXIST. In this case the metadir is corrupt, so bail out. + */ + if (XFS_IS_CORRUPT(mp, qi->qi_dirip == NULL)) + return -EFSCORRUPTED; } if (XFS_IS_UQUOTA_ON(mp) && !qi->qi_uquotaip) { From patchwork Wed Dec 4 03:03:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13893162 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 935C7FC1D; Wed, 4 Dec 2024 03:03:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733281381; cv=none; b=U8pJhC2HCuxOrxuGoq7+eUvwb2uWOtinZZfe1Cu+wFidhIAMv/LwnarvwQqfjW5Duww422xByige2ZuqEw80Jz8orLkJ7ODRytVJ/0qpRr2Y+SyGWe0z8IgvW78n/y9evhUSzHGjSWr7MRUDn1K+sivbDCyUCGeYBA5UhtqYob0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733281381; c=relaxed/simple; bh=9iGuTJO/rl2OpDJ9rNe5GFvAjKqlfOGEI+Q83/4F9N8=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=CCHLap4hleVAfc8uY9k1GGwf3SCWfyrhTNNmYBUkTwsUBAjO+/vnbVgiB4t5lyXStuLnK8gziLMpq/B9vGGtTMinZHad8fGmuEaODk3QkAD9JK43ojGYVho/FRG60AJg9trPJIDj8lYNFmrUqzY57WEn5Tz7v/lN4HXdThshdb0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BIclZqWD; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="BIclZqWD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 682E6C4CEDC; Wed, 4 Dec 2024 03:03:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733281381; bh=9iGuTJO/rl2OpDJ9rNe5GFvAjKqlfOGEI+Q83/4F9N8=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=BIclZqWD81XtGQzJrNcFuxrJXe4iI2w2+y1xTH1XsHzbeqAnQZ3au54wX3uHWPeuG IIq/KGBngDoHf8gQOk5sOAnSfTopa6e+X3qaSPS/QCs2OFnwkFswN+8ZmawMvPaRFf Hnir0bGORqz/FpJ71hGNeydEqttc0yKTIgP/EAp64Rb+S8hlExCMAM+KI6Sm20jkCM CeV1Sk4wJKjC4GF+DEwoi1tlCcdEB46PKHm5upmQ04yXZX/lfzGxEm8hQUWSqP9S0Q LY3g8sYZrmTlX135w6aRvOd7fSgJesFY9QOfBRAl/4lz06Qkodxn9yC4IucgleeMBw snbgbJboTnbWQ== Date: Tue, 03 Dec 2024 19:03:00 -0800 Subject: [PATCH 3/6] xfs: check pre-metadir fields correctly From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: stable@vger.kernel.org, linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <173328106635.1145623.13324476061274052225.stgit@frogsfrogsfrogs> In-Reply-To: <173328106571.1145623.3212405760436181793.stgit@frogsfrogsfrogs> References: <173328106571.1145623.3212405760436181793.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong The checks that were added to the superblock scrubber for metadata directories aren't quite right -- the old inode pointers are now defined to be zeroes until someone else reuses them. Also consolidate the new metadir field checks to one place; they were inexplicably scattered around. Cc: # v6.13-rc1 Fixes: 28d756d4d562dc ("xfs: update sb field checks when metadir is turned on") Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- fs/xfs/scrub/agheader.c | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/fs/xfs/scrub/agheader.c b/fs/xfs/scrub/agheader.c index 1d41b85478da9d..88063d67cb5fd4 100644 --- a/fs/xfs/scrub/agheader.c +++ b/fs/xfs/scrub/agheader.c @@ -145,8 +145,11 @@ xchk_superblock( xchk_block_set_preen(sc, bp); if (xfs_has_metadir(sc->mp)) { - if (sb->sb_metadirino != cpu_to_be64(mp->m_sb.sb_metadirino)) - xchk_block_set_preen(sc, bp); + if (sb->sb_rbmino != cpu_to_be64(0)) + xchk_block_set_corrupt(sc, bp); + + if (sb->sb_rsumino != cpu_to_be64(0)) + xchk_block_set_corrupt(sc, bp); } else { if (sb->sb_rbmino != cpu_to_be64(mp->m_sb.sb_rbmino)) xchk_block_set_preen(sc, bp); @@ -229,7 +232,13 @@ xchk_superblock( * sb_icount, sb_ifree, sb_fdblocks, sb_frexents */ - if (!xfs_has_metadir(mp)) { + if (xfs_has_metadir(mp)) { + if (sb->sb_uquotino != cpu_to_be64(0)) + xchk_block_set_corrupt(sc, bp); + + if (sb->sb_gquotino != cpu_to_be64(0)) + xchk_block_set_preen(sc, bp); + } else { if (sb->sb_uquotino != cpu_to_be64(mp->m_sb.sb_uquotino)) xchk_block_set_preen(sc, bp); @@ -281,15 +290,8 @@ xchk_superblock( if (!!(sb->sb_features2 & cpu_to_be32(~v2_ok))) xchk_block_set_corrupt(sc, bp); - if (xfs_has_metadir(mp)) { - if (sb->sb_rgblklog != mp->m_sb.sb_rgblklog) - xchk_block_set_corrupt(sc, bp); - if (memchr_inv(sb->sb_pad, 0, sizeof(sb->sb_pad))) - xchk_block_set_preen(sc, bp); - } else { - if (sb->sb_features2 != sb->sb_bad_features2) - xchk_block_set_preen(sc, bp); - } + if (sb->sb_features2 != sb->sb_bad_features2) + xchk_block_set_preen(sc, bp); } /* Check sb_features2 flags that are set at mkfs time. */ @@ -351,7 +353,10 @@ xchk_superblock( if (sb->sb_spino_align != cpu_to_be32(mp->m_sb.sb_spino_align)) xchk_block_set_corrupt(sc, bp); - if (!xfs_has_metadir(mp)) { + if (xfs_has_metadir(mp)) { + if (sb->sb_pquotino != cpu_to_be64(0)) + xchk_block_set_corrupt(sc, bp); + } else { if (sb->sb_pquotino != cpu_to_be64(mp->m_sb.sb_pquotino)) xchk_block_set_preen(sc, bp); } @@ -366,11 +371,20 @@ xchk_superblock( } if (xfs_has_metadir(mp)) { + if (sb->sb_metadirino != cpu_to_be64(mp->m_sb.sb_metadirino)) + xchk_block_set_preen(sc, bp); + if (sb->sb_rgcount != cpu_to_be32(mp->m_sb.sb_rgcount)) xchk_block_set_corrupt(sc, bp); if (sb->sb_rgextents != cpu_to_be32(mp->m_sb.sb_rgextents)) xchk_block_set_corrupt(sc, bp); + + if (sb->sb_rgblklog != mp->m_sb.sb_rgblklog) + xchk_block_set_corrupt(sc, bp); + + if (memchr_inv(sb->sb_pad, 0, sizeof(sb->sb_pad))) + xchk_block_set_corrupt(sc, bp); } /* Everything else must be zero. */ From patchwork Wed Dec 4 03:03:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13893163 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7D5B5FC1D; Wed, 4 Dec 2024 03:03:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733281397; cv=none; b=vCRTMbsb1lxcIO9/yVIY01AnhCpxWnfzWmTNFY+NdaGIiyLMV3bb+OFVo/0H9l+XozCn4QoUKHPW3PMgLHUm6A2fFcjZm/QTeiK5sbf3REaQ3m2txEnpveDQ/FDmtpZFfb3cYpGT2bV9DSuFqGWKN9kklUNqLUDYSmH/3md1Lsc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733281397; c=relaxed/simple; bh=an7p+4u86RlIlN3+7Wcv/Bu85sUwKbDRmU/gF7pb5Qc=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=IVloXLiQAJXjvdaN3OR/NfUWY0aRumnGwPtTdZaYEe8LpZcPJuq0sN1AesWMBFvakRFaLW0pDKYnwdehkJ+1U0vXL4+A7VRrHS+4zGADI1iFTDFn5qkWjklb8pIuaSq4R7ViTmbn5Jkzg5qyFA58SpvuzVVGPsboYp5wuQjmFqM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TtBwwnxM; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TtBwwnxM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 07349C4CEDC; Wed, 4 Dec 2024 03:03:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733281397; bh=an7p+4u86RlIlN3+7Wcv/Bu85sUwKbDRmU/gF7pb5Qc=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=TtBwwnxMC2JlrD0KYo9kLdrGWO400Gt63qh8nkQ8chKnO1s4e8XXE87Nz39AcVv+T NWsBilf5olWpInXZvmwcR4t6h6pcibGeCkbgJohHJDzVhEnZl3/CWi0X49wSB/Ce23 LInC8QWxHwtG8p2IwGQ5Wh9pwV9yaGsLz2iI+yp4vJ3L1Jyz04+WtFvobuHjiPHL+l aCQ2Wy9Nm1y60PDVl8AD2Pti7dFIg0X7KrcDPoclrWIhRHxAbT9ER7nWBM/WF4triN gmVa8/AyV5y07EBrMgX76hXaEkhXKgGlFT0cjL+LN+95CzAa/SmZQ4+5xFp7qbrI+n +BA47r8Z1qUCg== Date: Tue, 03 Dec 2024 19:03:16 -0800 Subject: [PATCH 4/6] xfs: fix zero byte checking in the superblock scrubber From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: stable@vger.kernel.org, linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <173328106652.1145623.7325198732846866757.stgit@frogsfrogsfrogs> In-Reply-To: <173328106571.1145623.3212405760436181793.stgit@frogsfrogsfrogs> References: <173328106571.1145623.3212405760436181793.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong The logic to check that the region past the end of the superblock is all zeroes is wrong -- we don't want to check only the bytes past the end of the maximally sized ondisk superblock structure as currently defined in xfs_format.h; we want to check the bytes beyond the end of the ondisk as defined by the feature bits. Port the superblock size logic from xfs_repair and then put it to use in xfs_scrub. Cc: # v4.15 Fixes: 21fb4cb1981ef7 ("xfs: scrub the secondary superblocks") Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- fs/xfs/scrub/agheader.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/fs/xfs/scrub/agheader.c b/fs/xfs/scrub/agheader.c index 88063d67cb5fd4..190d56f8134463 100644 --- a/fs/xfs/scrub/agheader.c +++ b/fs/xfs/scrub/agheader.c @@ -59,6 +59,27 @@ xchk_superblock_xref( /* scrub teardown will take care of sc->sa for us */ } +/* Calculate the ondisk superblock size in bytes */ +STATIC size_t +xchk_superblock_ondisk_size( + struct xfs_mount *mp) +{ + if (xfs_has_metadir(mp)) + return offsetofend(struct xfs_dsb, sb_pad); + if (xfs_has_metauuid(mp)) + return offsetofend(struct xfs_dsb, sb_meta_uuid); + if (xfs_has_crc(mp)) + return offsetofend(struct xfs_dsb, sb_lsn); + if (xfs_sb_version_hasmorebits(&mp->m_sb)) + return offsetofend(struct xfs_dsb, sb_bad_features2); + if (xfs_has_logv2(mp)) + return offsetofend(struct xfs_dsb, sb_logsunit); + if (xfs_has_sector(mp)) + return offsetofend(struct xfs_dsb, sb_logsectsize); + /* only support dirv2 or more recent */ + return offsetofend(struct xfs_dsb, sb_dirblklog); +} + /* * Scrub the filesystem superblock. * @@ -75,6 +96,7 @@ xchk_superblock( struct xfs_buf *bp; struct xfs_dsb *sb; struct xfs_perag *pag; + size_t sblen; xfs_agnumber_t agno; uint32_t v2_ok; __be32 features_mask; @@ -388,8 +410,8 @@ xchk_superblock( } /* Everything else must be zero. */ - if (memchr_inv(sb + 1, 0, - BBTOB(bp->b_length) - sizeof(struct xfs_dsb))) + sblen = xchk_superblock_ondisk_size(mp); + if (memchr_inv((char *)sb + sblen, 0, BBTOB(bp->b_length) - sblen)) xchk_block_set_corrupt(sc, bp); xchk_superblock_xref(sc, bp); From patchwork Wed Dec 4 03:03:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13893164 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 737054AEE0; Wed, 4 Dec 2024 03:03:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733281413; cv=none; b=C440fAbx79VsYG0NVoGYlzWl2MYGtOBc4s/rqmgrpQEoY2dz370TSzD3dP3eTqEzYoSywHO1p6USUOBVbXaE0q+TN8JcfRFTA/13EHTOi5ZcijNa+2iIJDPhC0SMHSuVA/EHy+ZKSxklW+2KFX/zW3zzh6CsVQfYKev7Wxl91mI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733281413; c=relaxed/simple; bh=V7+JaeiFYvZqcYmfwV1i+rnP6fIdiZn/TJxuQ2qNsbo=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=UcPO52dj/J4MtIoqIU8c38e5UXJj9fN3RN5OnhJT3uKKtlzpG+6PUb+dxnmUVfz/WwS8qVFMdazSpR+aREjZx/lhWtPNTFSYiA7FmeW08bmtlU7GoTTJgMyen5Yrqyg9eaRbKiQhb07TNjUDFg5DWuYOfA5F4ZCWGu6skNO09CI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Bn32eHC+; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Bn32eHC+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D6D19C4CEDC; Wed, 4 Dec 2024 03:03:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733281412; bh=V7+JaeiFYvZqcYmfwV1i+rnP6fIdiZn/TJxuQ2qNsbo=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=Bn32eHC+7fZdlAEmWGBtvDgv7g8gRvoLrB/yZoiCt1Yrl94pXVlS9r2mOHNzzlzzk aQglaTZY0v5Lbd1LaKNUUaEi4Ey3ykdkBdMOV0Mo0DW/QsQ9OY20JK5VVQ7pJwnOkE z1LhbDdE7NMmES3hj8tPKNd3JZGIRsJ9kV74iRDj9cOoM3tgjfXwH3ePo4+gsOWX1W FudG1RW8WQITz148AQ/g+JR3m0iIihG74USGYLU48kTAsw6rjFIAvIoLG0yQXqaw8J TpScgjxV3x9u1LBPjzP+8zUIzt/h+0emFoIDWvwbD3pkJMWHZtwl69eKVVb5KRFeOr oCKv1c12/Rnlg== Date: Tue, 03 Dec 2024 19:03:32 -0800 Subject: [PATCH 5/6] xfs: return from xfs_symlink_verify early on V4 filesystems From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: stable@vger.kernel.org, linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <173328106668.1145623.12239868718203963494.stgit@frogsfrogsfrogs> In-Reply-To: <173328106571.1145623.3212405760436181793.stgit@frogsfrogsfrogs> References: <173328106571.1145623.3212405760436181793.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong V4 symlink blocks didn't have headers, so return early if this is a V4 filesystem. Cc: # v5.1 Fixes: 39708c20ab5133 ("xfs: miscellaneous verifier magic value fixups") Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- fs/xfs/libxfs/xfs_symlink_remote.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/xfs/libxfs/xfs_symlink_remote.c b/fs/xfs/libxfs/xfs_symlink_remote.c index f228127a88ff26..fb47a76ead18c2 100644 --- a/fs/xfs/libxfs/xfs_symlink_remote.c +++ b/fs/xfs/libxfs/xfs_symlink_remote.c @@ -92,8 +92,10 @@ xfs_symlink_verify( struct xfs_mount *mp = bp->b_mount; struct xfs_dsymlink_hdr *dsl = bp->b_addr; + /* no verification of non-crc buffers */ if (!xfs_has_crc(mp)) - return __this_address; + return NULL; + if (!xfs_verify_magic(bp, dsl->sl_magic)) return __this_address; if (!uuid_equal(&dsl->sl_uuid, &mp->m_sb.sb_meta_uuid)) From patchwork Wed Dec 4 03:03:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13893177 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0D919FC1D; Wed, 4 Dec 2024 03:03:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733281429; cv=none; b=JOfR8ZI4VkJt1O2h7+WOWLp03dNahg+UI/zu966HANn8yMwb37fN0HXuYcJRrs/VNLy+8055XDc/ZX9GZ3uUIyGtkZRdPM7vUW1HbW+hD7sVhy3o6HQrpu1CN+SvMqhjr3n+nfJLet83l7K+qnYhEj0n6W+1ddZemd690oKalXs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733281429; c=relaxed/simple; bh=TJmM8W5+K0zg3aoxdfu/AUtLBWfrSjomVR1p+yNid3Y=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qRE1UmJu7w4e25ZYDkjf1eRasK3KUQ+QZr8oWlARRHemPf+iaNC++fUnF0MWz+pvTnkK5C9/WYbV/JDLO+ImxZ7Mcr36A5/FmaYNf5Y/EBj5NPQVtxw2oCeR4kPgcAA1SPMZOmo2zaX4HcwCqPVM2Kdi+XbJbq5yK+tTT3+mIus= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Bvk0R5Ev; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Bvk0R5Ev" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 80E1CC4CEDC; Wed, 4 Dec 2024 03:03:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733281428; bh=TJmM8W5+K0zg3aoxdfu/AUtLBWfrSjomVR1p+yNid3Y=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=Bvk0R5EvQblLJNUhJd81FBaG9mAaW44Hla5OTVaAgBCQPWuT0SQXac3I1y/efVLPp EuLfOKQngSyyi5yXZv4nMfGyFxwqoT7X0HL8jnDx50MfnIn8I5w7me5WGpEeHAj222 F84+MiF4DshltB+etQP3Sg2xOsiglSPM0ztj/GC1mA3V9lcGqM2ojzgG4kWw7lIhBn PRzbvWfuh/8cHbqYAHKbhm4YkOmL0co4wN8kIfb5aHoLiulB8xQwh0qsFK0tRpF/Rp zAJOtR/WZADh0R2VUj8AjGRUQ8tewfItF98vEo0azL9qKJrLnu7xKGti+a8oVImvO6 ljGcizlELmPKQ== Date: Tue, 03 Dec 2024 19:03:48 -0800 Subject: [PATCH 6/6] xfs: port xfs_ioc_start_commit to multigrain timestamps From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: jlayton@kernel.org, stable@vger.kernel.org, linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <173328106685.1145623.13634222093317841310.stgit@frogsfrogsfrogs> In-Reply-To: <173328106571.1145623.3212405760436181793.stgit@frogsfrogsfrogs> References: <173328106571.1145623.3212405760436181793.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Take advantage of the multigrain timestamp APIs to ensure that nobody can sneak in and write things to a file between starting a file update operation and committing the results. This should have been part of the multigrain timestamp merge, but I forgot to fling it at jlayton when he resubmitted the patchset due to developer bandwidth problems. Cc: jlayton@kernel.org Cc: # v6.13-rc1 Fixes: 4e40eff0b5737c ("fs: add infrastructure for multigrain timestamps") Signed-off-by: Darrick J. Wong Reviewed-by: Jeff Layton Reviewed-by: Christoph Hellwig --- fs/xfs/xfs_exchrange.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/fs/xfs/xfs_exchrange.c b/fs/xfs/xfs_exchrange.c index 9ab05ad224d127..dd24de420714ab 100644 --- a/fs/xfs/xfs_exchrange.c +++ b/fs/xfs/xfs_exchrange.c @@ -854,7 +854,7 @@ xfs_ioc_start_commit( struct xfs_commit_range __user *argp) { struct xfs_commit_range args = { }; - struct timespec64 ts; + struct kstat kstat; struct xfs_commit_range_fresh *kern_f; struct xfs_commit_range_fresh __user *user_f; struct inode *inode2 = file_inode(file); @@ -871,12 +871,12 @@ xfs_ioc_start_commit( memcpy(&kern_f->fsid, ip2->i_mount->m_fixedfsid, sizeof(xfs_fsid_t)); xfs_ilock(ip2, lockflags); - ts = inode_get_ctime(inode2); - kern_f->file2_ctime = ts.tv_sec; - kern_f->file2_ctime_nsec = ts.tv_nsec; - ts = inode_get_mtime(inode2); - kern_f->file2_mtime = ts.tv_sec; - kern_f->file2_mtime_nsec = ts.tv_nsec; + /* Force writing of a distinct ctime if any writes happen. */ + fill_mg_cmtime(&kstat, STATX_CTIME | STATX_MTIME, inode2); + kern_f->file2_ctime = kstat.ctime.tv_sec; + kern_f->file2_ctime_nsec = kstat.ctime.tv_nsec; + kern_f->file2_mtime = kstat.mtime.tv_sec; + kern_f->file2_mtime_nsec = kstat.mtime.tv_nsec; kern_f->file2_ino = ip2->i_ino; kern_f->file2_gen = inode2->i_generation; kern_f->magic = XCR_FRESH_MAGIC;