From patchwork Wed Dec 11 20:07:42 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: 13904111 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 E28DA1DDC29; Wed, 11 Dec 2024 20:07:43 +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=1733947664; cv=none; b=CThBEuokXKSxQqzf1MnB/1NFilDXQCUjBTET0y8PXFXJpGSSK4dRdxRuRlAcqzF3JeGBRGOBFafIzEFCxkn9Z5INzaClfZJrBv/41pV5f9uQ8t/t24I9ldX3/GM0wMOvZHvMxk1xie6awZ/h+s5ywzRvJKEkY5MH8lbiZdHwsKM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733947664; c=relaxed/simple; bh=VEJ7nM2+TWjB8W7NXFVdcjyXRoYVWbKOdidDuBGcLxc=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=rW0UMO2Rh5egIfbe/jAtSuqfVnVhNsqy+8F9gxdHKb76dKvTYXfyaZCmqilBPK/4VYv6NMSS3ABSFbOJJO4bSFVxfHcVngskRVdcud8nydvBE/OWwI8iMrZZ+FI0paORUuLfUlv54WJyFoqCQZz8kD9f7yE1s7/gpK4UjYdFwig= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CYAzxQYB; 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="CYAzxQYB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 79E26C4CED2; Wed, 11 Dec 2024 20:07:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733947663; bh=VEJ7nM2+TWjB8W7NXFVdcjyXRoYVWbKOdidDuBGcLxc=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=CYAzxQYBTOuBdVpdnBjNuOnVSucS/QQa/143RL25ryqTr6y1cycRXcIl28WXOMjpO liUsU9aEQHDfUVBS7v59uN6DAHfZ9gG1u/qaY55mN7ogoUjamdxdj/nEH7N3gRLtOX JWaGWmq6UNIEPk+k8pmGk6cZPavoPpUC10nWWJdhRCjn765c/EBu/Chd3Qx9/EA6KH hnoWcu6wDIXWFbw9fOGi9J1DOOqFMt1gjV0OuIHvOMfCnc2/uUvoKLs2CkMzvRQyPd dRzXZFJdYVicU94Z+QesMcrbo3tKQ9cbgPCdDuwHr6ovIP5tJ87BBpVAzmUIl6YyuE 1U7cQTKLk5vOA== Date: Wed, 11 Dec 2024 12:07:42 -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, hch@lst.de, linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <173394758086.171676.16603584597088340131.stgit@frogsfrogsfrogs> In-Reply-To: <173394758055.171676.7276594331259256376.stgit@frogsfrogsfrogs> References: <173394758055.171676.7276594331259256376.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. xrep_tempfile_adjust_directory_tree opportunistically moves sc->tempip from the regular directory tree to the metadata directory tree if sc->ip is part of the metadata directory tree. However, the scrub setup functions grab sc->ip and create sc->tempip before we actually get around to checking if the file mode is the right type for the scrubber. IOWs, you can invoke the symlink scrubber with the file handle of a subdirectory in the metadir. xrep_setup_symlink will create a temporary symlink file, xrep_tempfile_adjust_directory_tree will foolishly try to set the METADATA flag on the temp symlink, which trips the inode verifier in the inode item precommit, which shuts down the filesystem when expensive checks are turned on. If they're /not/ turned on, then xchk_symlink will return ENOENT when it sees that it's been passed a symlink, but the invalid inode could still get flushed to disk. We don't want that. Cc: # v6.13-rc1 Fixes: 9dc31acb01a1c7 ("xfs: move repair temporary files to the metadata directory tree") Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- fs/xfs/scrub/tempfile.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/fs/xfs/scrub/tempfile.c b/fs/xfs/scrub/tempfile.c index dc3802c7f678ce..2d7ca7e1bbca0f 100644 --- a/fs/xfs/scrub/tempfile.c +++ b/fs/xfs/scrub/tempfile.c @@ -184,11 +184,18 @@ xrep_tempfile_create( } /* + * Move sc->tempip from the regular directory tree to the metadata directory + * tree if sc->ip is part of the metadata directory tree and tempip has an + * eligible file mode. + * * Temporary files have to be created before we even know which inode we're * going to scrub, so we assume that they will be part of the regular directory * tree. If it turns out that we're actually scrubbing a file from the * metadata directory tree, we have to subtract the temp file from the root - * dquots and detach the dquots. + * dquots and detach the dquots prior to setting the METADATA iflag. However, + * the scrub setup functions grab sc->ip and create sc->tempip before we + * actually get around to checking if the file mode is the right type for the + * scrubber. */ int xrep_tempfile_adjust_directory_tree( @@ -204,6 +211,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 11 20:07:58 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: 13904112 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 7D4001C1F22; Wed, 11 Dec 2024 20:07:59 +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=1733947679; cv=none; b=lvSEdr3QO3mC0XQ1qHAo6CvzF+/Ek8nfGOdu7q2gvEujkIOBzwuzJ7437PN3xrca8wNcGGrto2Ya/JrCPwW4jJiswpaKzLGRfGITfkB02Sr72A0oyuuzJWN6/btrhaS+VkwjezjTzxipcIBXrlZJvsesrHdCrVaSh7hjJ3ixiKc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733947679; c=relaxed/simple; bh=jYJayrTQJvKRAI0mBU27ZP63G//tvKs0ArIgrBMb7G4=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=aw/AAo36xj8CYGlF5wQYKvnWGyJJLV0f9k2u+SsGZKKwQD3io8sfkZjVqzPuJReyNcJrPj5MKiDWnkLOQKjICVtpgYlDU150bfyZ/6YSpgzmjkMmcKeTAWab7DWVUlNLbZcyr3nQlh8hb2DCUx0EkzHZtEBDFaUBc/ClGmc69w8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dcQ2I1Mb; 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="dcQ2I1Mb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 216E8C4CED2; Wed, 11 Dec 2024 20:07:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733947679; bh=jYJayrTQJvKRAI0mBU27ZP63G//tvKs0ArIgrBMb7G4=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=dcQ2I1MbkpEkk4f4wqaVCNjgagWLbMACji5WWsGjOTMlp7U4N/vNoorDtIpvUZrjN AVzxbop9FeUCnZJUQyabEi+ttMKgENOMM4K1jQ6NOxDZbMBtOuYoroPNovXJl94SA/ QaO9XysCFw7yHsbx2M+KroDJpnZ8/livlfQ7z1GxWlIOXLnPwT8KJp48SStVMT3Rsd eU0xucv9xNN7rc1uaXlwE9iIt8Ev9Mw0hAD7uF8nfftFRTkJX9AFwb90/Gzq8kPR+E 4iPSYW49gqTfdicNlRzwm+lys5epyBLijZ2eSxbZ5ksLglgslZe3oMid84AjouuFES HBw2iXS8hfVCw== Date: Wed, 11 Dec 2024 12:07:58 -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, hch@lst.de, linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <173394758103.171676.16671624158372257924.stgit@frogsfrogsfrogs> In-Reply-To: <173394758055.171676.7276594331259256376.stgit@frogsfrogsfrogs> References: <173394758055.171676.7276594331259256376.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 11 20:08:14 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: 13904113 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 414182594B3; Wed, 11 Dec 2024 20:08:14 +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=1733947695; cv=none; b=Mv9/86qwgL02EFOhnip5xpQoAo96a3mLBsTvkglPPbxOm2Ip1wVzGqiaKeaqZAM1H3nVlQi5HhwOBGHxOsTf6HVJfsQ2eFk6tqJnPwTJiHHEkGwBDo+HB66ZkLSn32VIBE2lTVE/3HUtO7Oz8gV+o/qajD8oUjpLuLwQitWrYrs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733947695; c=relaxed/simple; bh=9IWf77lrk7H8zbrW+W0y6OObHF2pbcOytSxzgwnz0sE=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=s/e02YkWToXaX+bdSZOMCYCi7tr2f0JbFgwIpN/OITK6q0J5KTkNKka9A1rmd/LL/VhqgaA5FRGPJibqtEBpAiWJy5uT0LANJIr0PQZmxHqJcdSJ4ih1ldf5qCF6BlZDxlUf3gODSpKZTwjS9tYzFBMo8Aiw6KcnJM/+Yfc3Oow= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EFXwVJo8; 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="EFXwVJo8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C7A60C4CED2; Wed, 11 Dec 2024 20:08:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733947694; bh=9IWf77lrk7H8zbrW+W0y6OObHF2pbcOytSxzgwnz0sE=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=EFXwVJo8Fa+I6qRfDRbojjnriXcDaKrI9Rw8jv913I7z2gAPAMG0yedIUPKtU2X2D JakMR4LLERk3VaKWjQ5KVK6zPq7VtQsRv/d4xBDNcRNC/adRPWy5GNzm670WwKTy2O Nc3x1c6CPRAzzS/9ZiX5dhtzwGj/LAQVq+90zrNT6OCYSgvu0AQ22vGnBo+QdoK4lz hexBKLTWVi99lTS9cOB0JooNWxubaTAMCKpGXi6uIRgaytVV+4hqrFeasdl/rLya9S r0Yy3BQQq8AU0r1kbsZyamFgPMYdPnFdHe4MV+3jcB+3J5CGr80T878+8oGuspeDKf 2xoTRAesZ+xBA== Date: Wed, 11 Dec 2024 12:08:14 -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, hch@lst.de, linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <173394758120.171676.4704523076706311668.stgit@frogsfrogsfrogs> In-Reply-To: <173394758055.171676.7276594331259256376.stgit@frogsfrogsfrogs> References: <173394758055.171676.7276594331259256376.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 11 20:08: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: 13904114 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 E80E41D6DA4; Wed, 11 Dec 2024 20:08: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=1733947711; cv=none; b=eIAJiNwDSilg5Jcl3HlElhCqAThMOUax7lOYfTWPAoPfzeK560xUwWZxckyZw6GI5Zt7qU/56Lij8Kgpoku8sV6Q1eDXfBq3D/4aoXIzN2QSvKUypxboWg/KX4Ks5LH8m5ROTvRuibYSZOyY3fwrNqnV7rqPoedKAmEWKpO5b0s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733947711; c=relaxed/simple; bh=iI19QR/L/ukXQi3tmndHRmdDiNI7qXxqZWOMoPhxsL8=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ll5dOPw0lohlqwMTiJyPMXjaJj30N0pf+/FjOIt3hoLSMlg+RQuYGDa0qmvrSkUN4O3qSCnRpfKuuW4g0BVbtha+m+NNCGYfxzUU95PPTwar3bgDtLTNvCRc9FFM8qfLtNJEUcUTi7mxYnhng4rEgIQn8i4pWT5jZ7wt5/XR900= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hWEIu4sY; 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="hWEIu4sY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6EEFEC4CED2; Wed, 11 Dec 2024 20:08:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733947710; bh=iI19QR/L/ukXQi3tmndHRmdDiNI7qXxqZWOMoPhxsL8=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=hWEIu4sYiBz5DrihqoN/M1MAB92IA0WcSQgXtLoEHTHR5Y8ERy1lJ784JPjYiqhT8 hyrxuUTSiYSgoS5OG11M/gKoI028N77yq0EzEIgUhAf1YNfp/A5wWY7cRf1zQRdFtG pZcBZC2rm0BnmT2g47QnhzKB8iYGKabUKwTorgONo7SqvfAGO06+wuVMZJxvI8IeuZ t8SiX+qslXHrsW8HriWRQJqFVI3u7NKt6NMh+VA6v3irieZM2fgS9AbC3HX1jb4UkB cN58KfZjDnhS6Z7w1vhuKs9aYTIDkUct4m83AbwYe5XbaAhlaZfRXK4UitRvgUKfM2 oo7SXRieTHYhg== Date: Wed, 11 Dec 2024 12:08:29 -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, hch@lst.de, linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <173394758136.171676.17192371570679186844.stgit@frogsfrogsfrogs> In-Reply-To: <173394758055.171676.7276594331259256376.stgit@frogsfrogsfrogs> References: <173394758055.171676.7276594331259256376.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 | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/fs/xfs/scrub/agheader.c b/fs/xfs/scrub/agheader.c index 88063d67cb5fd4..9f8c312dfd3c82 100644 --- a/fs/xfs/scrub/agheader.c +++ b/fs/xfs/scrub/agheader.c @@ -59,6 +59,32 @@ xchk_superblock_xref( /* scrub teardown will take care of sc->sa for us */ } +/* + * Calculate the ondisk superblock size in bytes given the feature set of the + * mounted filesystem (aka the primary sb). This is subtlely different from + * the logic in xfs_repair, which computes the size of a secondary sb given the + * featureset listed in the secondary sb. + */ +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 +101,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 +415,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 11 20:08: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: 13904115 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 4329A2594B3; Wed, 11 Dec 2024 20:08:46 +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=1733947726; cv=none; b=LUkYcW0w7oyu9O/5zFE2hfFj5l+M4Aabfk88SP+GsYON8aNMhu9KEhdJBbQdGwy40ZhJwFu+H+TDg8j9XBySxpDfreut2D2jRmFKexg30f5Mcf7ZDo/1VlxqSa+gWfhB7IH1fFWRE2QQnD1+DjvJ0rhd9DtS4uGN2QEq289BoR4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733947726; c=relaxed/simple; bh=V4djZAqloTW/JtfS6BayRTkU4mK+EkNDZzNG2jMMdQw=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=A8RvctKnDzSQKwx0MaX5aZEDuHrTgYjGLgO1FXsO7kuF8EUReFmUVqOThV7HI5ja4JFs8N8KKXTaPHIrElQSn+M7Dwly+SiLp35ScJfrL+ssyOaFjmxOBaMluYBY7w0YoofGDe9lLSwYfH8pmyNErJ1YAhx1B5/n73sgncf3dqw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QKDpOYEk; 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="QKDpOYEk" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 19708C4CED2; Wed, 11 Dec 2024 20:08:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733947726; bh=V4djZAqloTW/JtfS6BayRTkU4mK+EkNDZzNG2jMMdQw=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=QKDpOYEkOvh0xD/9D3KKTUMw3Q3NvZw2hrOGTkqQRqpFQIqGQkp4i2Ci+/4ntiKRR oCJNWoys0n8I/kycl7IhqYNimqB7LsCArC/PKCdPxFH1IYzEVD0ry7oplNminiJOhi r+ktlUhLfbE9qmPo+GJ774odRTYNdGjDPZwH7QeKrC4Ozutni+1njXzZG5lgsk7cqF NOx04gVj4oEg4V68wXKZxt/gjCSrZgHUvw0AZoEFncDAQQKFc9giKTJ+t7czyaQjzY oDt2fDhi4KwgVoXCur2aQaPiatCwkk1AaZUSV3Leddrm1FeawOInGR7CFrH8zzbzD6 VZo0Tx0B8qjaQ== Date: Wed, 11 Dec 2024 12:08:45 -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, hch@lst.de, linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <173394758153.171676.9419928146112357260.stgit@frogsfrogsfrogs> In-Reply-To: <173394758055.171676.7276594331259256376.stgit@frogsfrogsfrogs> References: <173394758055.171676.7276594331259256376.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 11 20:09:01 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: 13904116 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 4909B2594B3; Wed, 11 Dec 2024 20:09: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=1733947742; cv=none; b=A68AhqKn1TCdRCQAupZ/+GHxPvF6XbFHQ5mFap8vFDNLQkMY1lDn6hTxY1AvSIB9DYuf7VSIhu/Gxn79vE0zLtvsSl+pSBgwYgNWrAOYgTTqwXpwoWHouWsT1WL4fx1gNmEPXqZgIGX+C5JvlOagXnyQEQm6qIvlb8jGnnAoIso= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733947742; c=relaxed/simple; bh=Q9pXaAeGQzLuS7Y7a4pvKyvgQUQw8ZYdE/YM9zxiaiE=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=rAnUBIpvimd94yh3Vt9mpOLoiQnJVhs9JacANAcBexik/mkOPTmcQPEVfH12y6XkBhLv9x12TfidVPQa+CWM9nuMixeh0RG72Wf0w5tB85nQ+ZtrpwyZFtUdPv92UpFBwz7tDmww+3hzuL7sv/coKvrCd2grPTEOug1ig5W8edg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KFYYhxl4; 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="KFYYhxl4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CDCADC4CED2; Wed, 11 Dec 2024 20:09:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733947741; bh=Q9pXaAeGQzLuS7Y7a4pvKyvgQUQw8ZYdE/YM9zxiaiE=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=KFYYhxl4EA8g5Pfvo3kUFh+jydrZWXHLkk/M91DFC8KJ4ig+AMxWVzUsJVgUOuAH8 xna8bIX0zt9j1Ac8AKPBHvR2Qp7WKXbwh29cHiNY990y9VyMc9w7pGjk8khsJBsIL7 RdM3qR1F7+5yYw7if4eQgEc7iMnIUXYuT8unqcBJlJ4ouyjEEzS4X9BUEunX2AV+0f F2lilHdJ7AbmTHe76jfO9/DLLkDpTOR4vuiH42dKhnfTB7dE0bXO6Ezd3mEg/3xspj BeL+xi0hOvXS1Nk9MtSJC+rVl821WvKaEV2FVA6lM5puROe8eb7NrbZbEszw7k64aa o74Pn0Oc3Nmxg== Date: Wed, 11 Dec 2024 12:09:01 -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, hch@lst.de, jlayton@kernel.org, linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <173394758170.171676.7652487151213103514.stgit@frogsfrogsfrogs> In-Reply-To: <173394758055.171676.7276594331259256376.stgit@frogsfrogsfrogs> References: <173394758055.171676.7276594331259256376.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: Christoph Hellwig Reviewed-by: Jeff Layton --- 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;