From patchwork Sat Dec 7 00:31:06 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: 13898153 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 D329A38B; Sat, 7 Dec 2024 00:31:07 +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=1733531467; cv=none; b=lz6Snay2Bjc9jQIgLd0ZwWkRwA9+z+U0dbV0bcODHp559qVd0Bhz3Riom8d8oRXugPmuiqbwmaye8/cBs/4T3U9RyLyYWgtows7HXoNGWWdER6Y5BnCdrpqyUkRwg1tU/V1QhJ6v9Co4e7K1byOngjTxOIfkKtTq17EAk0Z36mI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733531467; c=relaxed/simple; bh=/xK9+B+Rp1/tA1ujHR7KeRByCf2uW4qAqYDe5JrrGv0=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=NofYqH1Fx1x8I2k8S3H7qNc0VnqHt8rxkjKgAFtml5/uN0zYNfSNUJmxJg+xB8bFgRWZRD0QXASCTb9LEpCh8fTJ8I6L7W8HOc3n1SznLMsg3JwIKA2lY46TPXfMPVIgprtB6LDx2U17pfDur19tTLn0HULnyLJuihSSNoahkMA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ErZPZU16; 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="ErZPZU16" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 71EBEC4CED1; Sat, 7 Dec 2024 00:31:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733531467; bh=/xK9+B+Rp1/tA1ujHR7KeRByCf2uW4qAqYDe5JrrGv0=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=ErZPZU16QOfhSNxR7rwBAtJ5nPog3jenYliFR2tuJUUgysyoFo+WEVv/sKPyGNfcO Z3eGP14wUzjEqzGJ3uSdK8jcMXE4Ma4Gi1gpIHEZ37ELlxKp9i5fDgBtxoTA5VV19I 7RtoA2oQ7s0195R7QhYPM6a9bzNf5y/w2NOlblB8YGJJhnVmZzv6xBfKad+Aho5uKC Ph42d2vhw/jkhH++v0aKQRS5k547tTDO+h06g9Yz8L9K7kDh5Ee6OF0RQsvPFY7JSu kF9GEi36u49pngCY2uYOdYzT/5x9ULppdtLlOpAplMx7GV2uKM4q9SvVAmnsVJznv/ NDfVFDSltnkdA== Date: Fri, 06 Dec 2024 16:31:06 -0800 Subject: [PATCH 1/6] xfs: don't move nondir/nonreg temporary repair files to the metadir namespace From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org Cc: stable@vger.kernel.org, hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173353139318.192136.14125386849342549320.stgit@frogsfrogsfrogs> In-Reply-To: <173353139288.192136.15243674953215007178.stgit@frogsfrogsfrogs> References: <173353139288.192136.15243674953215007178.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" --- 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 Sat Dec 7 00:31:22 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: 13898154 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 9E0AD20E6; Sat, 7 Dec 2024 00:31:23 +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=1733531483; cv=none; b=WXVcX1m1qh8Vy9HaQZZ167zwy+5cy5a/FjKGD8sTwb5dI4wmvmZBLN3NO5qibZemL/ImxV1GWL/wqoiMgqLcQsVLMOVwsqCozk/zxLSH4qzDd66OCgjogLCqZxW3MVMfFFklTET0m4GL+W50ZAc3OrrHBaxi6bc/Bgah+qzAZKY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733531483; c=relaxed/simple; bh=jYJayrTQJvKRAI0mBU27ZP63G//tvKs0ArIgrBMb7G4=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=EY2Bbg5XgQUzpAgPtklqurQHEB1LYmTwPWW7AcWOsW0o9DBlChaNqjIku+weNr/n0m/nUiUhI8Yl2YK2E1DGyCaKiTjq36vi7xc7sU4nasdGdVh0nc56JwFunQeUldtNntgoWJW9SbW/AVMCxIiMVNsfesw8ySRI2VVF+7/JoLc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tjkx2n8k; 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="tjkx2n8k" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 25844C4CED1; Sat, 7 Dec 2024 00:31:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733531483; bh=jYJayrTQJvKRAI0mBU27ZP63G//tvKs0ArIgrBMb7G4=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=tjkx2n8kIJDMqWuZqhZ7kldgQPhQ9pYAQ9p5/bkecE7Cb1i8GLh9xpgZUOvLr3sVn q/sSUYt4OyBLqDXBSrfJF+zBoeNLStZhiaPX3umu8po5jq6gSwxFSzp+wxiYzc0Rg0 x5ly0D+t0hVjneey++lMq21RvXr2BkYtJ3UppySg3X5gnvaDkUWD1KHNc7fRTwNbRL H2lQNXjgFSnm2IlbEKlpLzICoAqKW2yQQsj/3x7Exje3jIKWwEq45WsukpRq+JbXeo jNbe3URH/on95nIqjq0XOjIXnzXWz9HuWagpmV9vK+lj674s8JWNJGxr9P1+oaA62H 4rabikpsKaClw== Date: Fri, 06 Dec 2024 16:31:22 -0800 Subject: [PATCH 2/6] xfs: don't crash on corrupt /quotas dirent From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org Cc: stable@vger.kernel.org, hch@lst.de, hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173353139335.192136.5415870424463872835.stgit@frogsfrogsfrogs> In-Reply-To: <173353139288.192136.15243674953215007178.stgit@frogsfrogsfrogs> References: <173353139288.192136.15243674953215007178.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 Sat Dec 7 00:31:38 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: 13898155 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 4083517FE; Sat, 7 Dec 2024 00:31:38 +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=1733531500; cv=none; b=eJsCuDeRwMPIgqTz8j+Ovc39yQmLGW+0dlAbk3TFrgslp1cBepP+YtnnO8LLnFk7Z73dG+xXPvruYunwmAHUwvMIvXayjgIAWw0IHGGqWF+45wAU1Q+JZZR6I+MvLCO97ovdCl5e1mCPQoIk9+ypq912iEaYCAeiVXB4ozJ6Pv0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733531500; c=relaxed/simple; bh=9IWf77lrk7H8zbrW+W0y6OObHF2pbcOytSxzgwnz0sE=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ky7yC/KqG99tyonHLa4lB2+bj1+MTPRqv5dtZE7UxE78Xy+wV4fLgfU7Cp4WPffmL7Y0D7aJ0NmTaMt5Ac9IH1JvvOlfy2z8CGvNv5H9oce9i50blBB9DxR0QYb2UlxOLCFxUzTdP3c1zn42DHD1vxAxDandRPn8kNKcWBrSN7Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=b0KKqnfP; 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="b0KKqnfP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BF924C4CED1; Sat, 7 Dec 2024 00:31:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733531498; bh=9IWf77lrk7H8zbrW+W0y6OObHF2pbcOytSxzgwnz0sE=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=b0KKqnfPVjLgfovwlF0PF6M1+9LcxTPX3GNncyu9a8t21YrHdL/+37zA59DWCIRDV p2l1OS5ryb3u3+h8MFh9t9tlBvIsYJ7v6ubufo3sVbZSZcUhkn6T3KtSPkYXztSiP8 natGg5pjFVQkvxp5awLAxLpvVWp7aqJMGtrBvUr7grPBg+Dv8Hnx0PDczqyHrd3j0P 8tIdThuVq3Kwy2pcb5TlxZHyJmFoRZQHZJ4hpci5riJNpeYcUK7bt1L8AX8bYr7Bj6 mxdYfa33wXehCVueOl9wRcl8gb1YYugC0/ytmMAjuC/TAn39DGzmzgBXK2Q6Kgqtlv uTMNAenkgmSnw== Date: Fri, 06 Dec 2024 16:31:38 -0800 Subject: [PATCH 3/6] xfs: check pre-metadir fields correctly From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org Cc: stable@vger.kernel.org, hch@lst.de, hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173353139351.192136.8465362180134347529.stgit@frogsfrogsfrogs> In-Reply-To: <173353139288.192136.15243674953215007178.stgit@frogsfrogsfrogs> References: <173353139288.192136.15243674953215007178.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 Sat Dec 7 00:31:53 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: 13898156 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 F008238B; Sat, 7 Dec 2024 00:31:54 +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=1733531515; cv=none; b=kiBwTGi9r9Q1jC3T/O+oRGXwz8fPeE11Gui4TzVUuS8pn1Ja2v3uZ0XheuRXDWjF2VBYataw+AbjJq9Krrpyc42yuDT2+BII9BTLiq7XJ65EJ/b03C50S9SMH7dcRS5JCJ9eKNBW/u7k3goLf4ZbjQhxMqDyfUyiG8gB3Ce8T08= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733531515; c=relaxed/simple; bh=iI19QR/L/ukXQi3tmndHRmdDiNI7qXxqZWOMoPhxsL8=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Zgq4D21IQoPDKLSP6PnQUjIkAVMIy3J0iUmk0XGlXWHnOlZeSBTmWdsj4i53Pk9CpPTYz7D5QWvrtWpagEcMIf8cqVmBdneh8tl6upZP3YngRbXQ8mJoF5pqHRCLrC/NBK7BBnDKCY+ejiwS9IxAv/tDw48TIEZT+ZgOLkFfHlU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PctVzXtR; 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="PctVzXtR" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 77E6DC4CED1; Sat, 7 Dec 2024 00:31:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733531514; bh=iI19QR/L/ukXQi3tmndHRmdDiNI7qXxqZWOMoPhxsL8=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=PctVzXtRG1/zMev7CLDGOCU+cigrxWpGTfIcDyQ5DLwj2mcFkZX+mg2wPTaEy76mb vAO21xqK5fL8cTbRPEj8CUz6p7lv0edhB4D5WQlycrl/ikAehnUhKlIFQL2a2rAWAN w2MqZvcik3+YX3DcjLrB/65FxL8obyt42RU1B7JoZPlBR88/kj7FUUdt0cdGocnWRE l07wiGlfN+U2wCZo8DMDh0ZYaIEryPMdqVQgSEe7fnyMcBTbMq0kFTa0YxKuzvg/PI 7VTLiGABcYy6UU+C2mR6imWDSnrbPoFCkZ9MxgSkGtHku3hYJNYygfOw97xPkjBwtb N1RgpzOmGH6gQ== Date: Fri, 06 Dec 2024 16:31:53 -0800 Subject: [PATCH 4/6] xfs: fix zero byte checking in the superblock scrubber From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org Cc: stable@vger.kernel.org, hch@lst.de, hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173353139368.192136.9553326949796475388.stgit@frogsfrogsfrogs> In-Reply-To: <173353139288.192136.15243674953215007178.stgit@frogsfrogsfrogs> References: <173353139288.192136.15243674953215007178.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 Sat Dec 7 00:32:09 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: 13898157 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 CDED7323D; Sat, 7 Dec 2024 00:32:10 +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=1733531530; cv=none; b=WJSAFQ+GgGMnPUmwCy/tFLxRB+zpXykmt1kKsZ5aCR+tBrBm6GgT2WHuTMjcynL4ByJl8vFvxBrb6kbKVr29cLDFQ3MuBCr/SCDE9IBxDMyQByySIugJKwrigotfFBE5N5E9ab4oyWBxxafMWuW78g+i9ccJtDOaNsxCjAaAPKI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733531530; c=relaxed/simple; bh=V4djZAqloTW/JtfS6BayRTkU4mK+EkNDZzNG2jMMdQw=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=iByZYjEjkgXhHsGepCVxGerfPx2HH/CL0p1RtCHCJpEN8iLpt+/fYN6tfV8bsMz3GD5Qwf5okBdn6dC1A31yil8/u0dKljJELajcoHi9Q37Gvg0VgD7q+ePYNUNC3Y9x8MWFUwp2tu4gzDFpsvCwzRXUk0EcABsYWN2r6dfTjjY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=snB548vE; 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="snB548vE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 289B9C4CED1; Sat, 7 Dec 2024 00:32:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733531530; bh=V4djZAqloTW/JtfS6BayRTkU4mK+EkNDZzNG2jMMdQw=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=snB548vEXgkC8woN0KcgqTRbygMPYI10UDw2NEfpo9fnNbJgot9k5I4HZ8GLKWaqo eeku+dnxZbk1SZf1KYYXmMDG6BqSexOBYWP6gfMQ/jKt07/y1qBrdjr4uMDsJLy3XX rbttgIL+SmEwtIUXyM/sKtmgBTsDtXg/ezRHmteXGCWoK8wvXl8IYtjGC14MMjLTql nsur/k8/XmL4ODnuRef2XLo7NNPfe6YWh8c8XqkcqRdMuYZSO59VVfg9vnq0p+KFQD h90t24yP+1suOfahBXipZsWaq1uAGLl7ib9P2eLoCMFGbly/JKPBGqVXgGGDT24ar2 RyereaEqrt7ug== Date: Fri, 06 Dec 2024 16:32:09 -0800 Subject: [PATCH 5/6] xfs: return from xfs_symlink_verify early on V4 filesystems From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org Cc: stable@vger.kernel.org, hch@lst.de, hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173353139385.192136.1552414924467294012.stgit@frogsfrogsfrogs> In-Reply-To: <173353139288.192136.15243674953215007178.stgit@frogsfrogsfrogs> References: <173353139288.192136.15243674953215007178.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 Sat Dec 7 00:32:25 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: 13898158 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 79E7038B; Sat, 7 Dec 2024 00:32:26 +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=1733531546; cv=none; b=qatm4iB77hBL76aHqlYFZhyTVykiroLAEQrjPltf+ovE8Dx0w9ttvTRQHrDcYBP5CpXm1AahISID0eAptrQUGDBaAxGMmcwscRHJA3ZrDa5sur+A3RVZktvo/Ijku8pVC5jhi7At2Wc1XyDXbpcI7ysZEaxOQU6LXgSYl7ynMaM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733531546; c=relaxed/simple; bh=Q9pXaAeGQzLuS7Y7a4pvKyvgQUQw8ZYdE/YM9zxiaiE=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pa1r6Xphz3Sd/DbrEcgnhQZ9/+4GX07tQ4sQnd4q0pWXUfCLD1cnS8/HaAE0wNem4cEilvfTXNa2yKt+YvbLor54/XPDbQ+XX2s0KAcFYfpoUK1kOQMTbIeIuS05JTBeayiRfnUpYt4ocafxWOKQjKPaVw90wiGRI/AVsEujklE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=sbb1NCfs; 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="sbb1NCfs" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 000AFC4CED1; Sat, 7 Dec 2024 00:32:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733531546; bh=Q9pXaAeGQzLuS7Y7a4pvKyvgQUQw8ZYdE/YM9zxiaiE=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=sbb1NCfs98KOxJjEwiWP0k4no31SFUwgXEecFi/hd7EDJoC3xc3OxLcp4eRYikGH9 sjLPln6MWKmU5JuIRdTRhRo/H25tXk0uQjeqrOEZa01okF+8MaIOP/vGkHZKIC08FL /UrJJjUpKiQnrbX8/Mp37J62iMUnkfqXfgdok2wdc6gIFXcSx5O1R4ya0Vjm5Dqe1V +pQ3/7csTYhrAvt7Ti0XJQBL2aIPCyPivlonNYP4SRT8Cfc9tACqqBpk6NCNzmknvA 04HY5XfvJxJyHv4cVf9feHUkN9fXOO2GTN+2q6xEaiZldg8c6W5mwyar/2WRO1wTVY Nqxs9UtLjPixQ== Date: Fri, 06 Dec 2024 16:32:25 -0800 Subject: [PATCH 6/6] xfs: port xfs_ioc_start_commit to multigrain timestamps From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org Cc: jlayton@kernel.org, stable@vger.kernel.org, hch@lst.de, jlayton@kernel.org, hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173353139401.192136.14215988524314353493.stgit@frogsfrogsfrogs> In-Reply-To: <173353139288.192136.15243674953215007178.stgit@frogsfrogsfrogs> References: <173353139288.192136.15243674953215007178.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;