From patchwork Fri Aug 23 00:01: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: 13774358 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 121EF1C36 for ; Fri, 23 Aug 2024 00:01: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=1724371299; cv=none; b=I7cfxt3P0nntnMun7sb+xywMm7LlhbKwGqB6E182p8Dbn6QpC/x+sfVYGyI/wy+xymnDo75iyq9jkYyC1JVHGucJpgLSVN9IBEPC5akjTwxEDhrouf4BmwTWKXcLI+b8++vnDZ0OUFsSHpFlxPipkEvsqmMs4qkrmgmAQVCtwgs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724371299; c=relaxed/simple; bh=15XbvOxjHEIqQtdXJUm4MGmRb8QE1Z4v1mwBQBjBn4o=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=c/ln6m2CMeQnRcUeuaBuJ9Le2By24ChznI+hpoHF7h0g641r9CI1A/dJ4c9+wgoNkYTHi1zhjUy3vvwZ3BOFopUyRx4a2+V4rgvDh6bI+SYo80tsHOuw5d988RefVQ1q1cXI1WUaNQ870VDJ6xo7KPl5/bXUny3YAwC5H2Pffqo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MxdkRecN; 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="MxdkRecN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AB038C32782; Fri, 23 Aug 2024 00:01:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724371298; bh=15XbvOxjHEIqQtdXJUm4MGmRb8QE1Z4v1mwBQBjBn4o=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=MxdkRecN7PsQ6pQ5T7N2iQdj5vdNwzFsusAw2b12rDz9V3Ja8oAwfGsdpB8R3+uyq y+KXMkdjnkJzxQyNJPJYp6UBXQGWDQ+7vVHyB+0g0w5vMVQW3SBhful3X2NFIpQLCJ FFpXmOw1ztBGeH/jKUYHCoul/Pq2sigtH0vDya9XReZvv809QmAehEwqxaWfk2lmav hkpeP0kzm1d9tm02Tske85l9dT+ZfrZFIFynTYFpXzN88JuJsgvlfecxw3tqcwDUpG 5CrjhCNSx/hchGKNDPGjeNNO0idqlHuRCDS4Bj4TXJiME0+W8BEdbAN9bJ//epM0i3 MJSaWkDaeb2jg== Date: Thu, 22 Aug 2024 17:01:38 -0700 Subject: [PATCH 1/3] xfs: validate inumber in xfs_iget From: "Darrick J. Wong" To: djwong@kernel.org Cc: Christoph Hellwig , Dave Chinner , hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <172437084655.57308.14689040024608460458.stgit@frogsfrogsfrogs> In-Reply-To: <172437084629.57308.17035804596151035899.stgit@frogsfrogsfrogs> References: <172437084629.57308.17035804596151035899.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Actually use the inumber validator to check the argument passed in here. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Reviewed-by: Dave Chinner --- fs/xfs/xfs_icache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/xfs/xfs_icache.c b/fs/xfs/xfs_icache.c index cf629302d48e7..887d2a01161e4 100644 --- a/fs/xfs/xfs_icache.c +++ b/fs/xfs/xfs_icache.c @@ -755,7 +755,7 @@ xfs_iget( ASSERT((lock_flags & (XFS_IOLOCK_EXCL | XFS_IOLOCK_SHARED)) == 0); /* reject inode numbers outside existing AGs */ - if (!ino || XFS_INO_TO_AGNO(mp, ino) >= mp->m_sb.sb_agcount) + if (!xfs_verify_ino(mp, ino)) return -EINVAL; XFS_STATS_INC(mp, xs_ig_attempts); From patchwork Fri Aug 23 00:01: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: 13774359 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 70626197 for ; Fri, 23 Aug 2024 00:01: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=1724371314; cv=none; b=dnlMu6X8/z1fJWWcV8SQ2RNLrIAph7tENwIb9psWp7Y5UpMhAkQGiV6FMJCUugc4QLE+yj7DrlS7EyL3V/InAYcwiBYIK0kxStwUJOz7sak856GKpMqueip7P6jjziQp9AR4r2dYFaJ/tbx9Bdg9yQlUs7/3osa3lgzl+wv7IqY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724371314; c=relaxed/simple; bh=ogvNcSjC+aDmPHEFl9iYtaA7lVIEXZRLWN2fx8Eo8Xg=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mNXQri39UA3uf4uLdrlPtTUzTDsQrR1ey6w1B3YcIPVVUjhnqTbMIrFmXcagElrgUgOAPkxFoDP0c80fiZWr17XNC1+E7AL4FztYA/jOwhVo/ulb5TfXHjFY71xSPowi+36J4pUNHALodYaRF93U1MVYrFI1en6PFMG0krtemQs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AY9TTomC; 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="AY9TTomC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4E4A8C32782; Fri, 23 Aug 2024 00:01:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724371314; bh=ogvNcSjC+aDmPHEFl9iYtaA7lVIEXZRLWN2fx8Eo8Xg=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=AY9TTomCUV5IjSqy9xlfwzrWDjL4x55TngiU2yItZMaoqo4enkv+1goIeoi4cad3B lp984VWa2o4U+d6INwzPUrdeBaoVbLC8oaKco4VNgP2/veiutlVIoz2zl5+oioa3/g fQiBBsIHJqfFnCt3kMW9CG7toHYU1Ay8eNo6SrYBoKw7EJYNMvcSd3Q9rE+wOh0AR9 ShfUQpWk6rG6n2SGksWA+kOu1Z3H86mfOpX5/kG+y6D7QiZhKP9gMym8dW29gVbpGh khNrvOnPcCv5cpm94sscyTG/sCMO4T+5vYCI+csPXGxDszIK0kz8UxxhTK7iihvqC/ LDh08964bCUMg== Date: Thu, 22 Aug 2024 17:01:53 -0700 Subject: [PATCH 2/3] xfs: match on the global RT inode numbers in xfs_is_metadata_inode From: "Darrick J. Wong" To: djwong@kernel.org Cc: Christoph Hellwig , hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <172437084673.57308.5311622647268357089.stgit@frogsfrogsfrogs> In-Reply-To: <172437084629.57308.17035804596151035899.stgit@frogsfrogsfrogs> References: <172437084629.57308.17035804596151035899.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig Match the inode number instead of the inode pointers, as the inode pointers in the superblock will go away soon. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong [djwong: port to my tree, make the parameter a const pointer] Signed-off-by: Darrick J. Wong --- fs/xfs/xfs_inode.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/fs/xfs/xfs_inode.h b/fs/xfs/xfs_inode.h index 51defdebef30e..1908409968dba 100644 --- a/fs/xfs/xfs_inode.h +++ b/fs/xfs/xfs_inode.h @@ -276,12 +276,13 @@ static inline bool xfs_is_reflink_inode(struct xfs_inode *ip) return ip->i_diflags2 & XFS_DIFLAG2_REFLINK; } -static inline bool xfs_is_metadata_inode(struct xfs_inode *ip) +static inline bool xfs_is_metadata_inode(const struct xfs_inode *ip) { struct xfs_mount *mp = ip->i_mount; - return ip == mp->m_rbmip || ip == mp->m_rsumip || - xfs_is_quota_inode(&mp->m_sb, ip->i_ino); + return ip->i_ino == mp->m_sb.sb_rbmino || + ip->i_ino == mp->m_sb.sb_rsumino || + xfs_is_quota_inode(&mp->m_sb, ip->i_ino); } bool xfs_is_always_cow_inode(struct xfs_inode *ip); From patchwork Fri Aug 23 00:02: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: 13774360 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 643354A08 for ; Fri, 23 Aug 2024 00:02: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=1724371331; cv=none; b=Te3J9hNiQv+DY2kxaN/jYUvtuGf9lfEg+pDSOT0uMbwbPgo1IRDH2IqA0rf0ysZ76XdP7mhoj+MC9n0tJ0XbKrtHwPcCKRR2BNuyqGsiKBsaFvTNyPo6lNjnonLW8x2bH/KncBXIoSp5dDeR9ItJ5KEqCKma7UespwIcUNaAs4s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724371331; c=relaxed/simple; bh=CG0Spvgj1tzBHFviDm3HIqXicChYDAu68kJk5XL1DJo=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=YAX+vreo/4tPD7tTsLrss6Fs0VQ8ggOG5uf8Q5BmH1HwuWHn0FWoXzGeWyhGiSJXjy1/72JpPpQGsvnXyg1UuMP5hz7UHa+2c7HjrnffKNhUi37oGYOr4NzcuUZtngtC9nVQVh9VjEtFfu+l5D7/7X3GG2TIG+s28E6cBwk2Gtw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hTenPTnL; 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="hTenPTnL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E74D9C32782; Fri, 23 Aug 2024 00:02:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724371330; bh=CG0Spvgj1tzBHFviDm3HIqXicChYDAu68kJk5XL1DJo=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=hTenPTnLYABtstVl2HCjeQKRAG3kTs6OwPNPSjTIE9/jFy9JD9Cd5b3AgQHUNcWAh rQcKbsebPk63lh0rz/ApNvFPv1m0McAzLcaWmUU1zj6xhdLXtnuYevlGnyw14R2SOA ofSpEPFfNIqNgtL6VHECVJPyZxUf3R+Aobd/885LgfrcDBO4KBhIS4xQP05ktHgReH QFFWaV1BqxtkA2QNEPQsoF33rhS3QWbQPSqUXNF01pxzHHROODeJy6VXxg+JdcpORF AmW9MxmHLMieHW/Fv3rU9BV25VPyHyJQoHmWAYiaVk0mn1UOb0nwGh8+BV4wSE0fc5 9x/IprkxQpqgg== Date: Thu, 22 Aug 2024 17:02:09 -0700 Subject: [PATCH 3/3] xfs: pass the icreate args object to xfs_dialloc From: "Darrick J. Wong" To: djwong@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <172437084690.57308.4842818086745573630.stgit@frogsfrogsfrogs> In-Reply-To: <172437084629.57308.17035804596151035899.stgit@frogsfrogsfrogs> References: <172437084629.57308.17035804596151035899.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Pass the xfs_icreate_args object to xfs_dialloc since we can extract the relevant mode (really just the file type) and parent inumber from there. This simplifies the calling convention in preparation for the next patch. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/libxfs/xfs_ialloc.c | 5 +++-- fs/xfs/libxfs/xfs_ialloc.h | 4 +++- fs/xfs/scrub/tempfile.c | 2 +- fs/xfs/xfs_inode.c | 4 ++-- fs/xfs/xfs_qm.c | 2 +- fs/xfs/xfs_symlink.c | 2 +- 6 files changed, 11 insertions(+), 8 deletions(-) diff --git a/fs/xfs/libxfs/xfs_ialloc.c b/fs/xfs/libxfs/xfs_ialloc.c index 0af5b7a33d055..fc70601e8d8ee 100644 --- a/fs/xfs/libxfs/xfs_ialloc.c +++ b/fs/xfs/libxfs/xfs_ialloc.c @@ -1855,11 +1855,12 @@ xfs_dialloc_try_ag( int xfs_dialloc( struct xfs_trans **tpp, - xfs_ino_t parent, - umode_t mode, + const struct xfs_icreate_args *args, xfs_ino_t *new_ino) { struct xfs_mount *mp = (*tpp)->t_mountp; + xfs_ino_t parent = args->pip ? args->pip->i_ino : 0; + umode_t mode = args->mode & S_IFMT; xfs_agnumber_t agno; int error = 0; xfs_agnumber_t start_agno; diff --git a/fs/xfs/libxfs/xfs_ialloc.h b/fs/xfs/libxfs/xfs_ialloc.h index b549627e3a615..3a1323155a455 100644 --- a/fs/xfs/libxfs/xfs_ialloc.h +++ b/fs/xfs/libxfs/xfs_ialloc.h @@ -33,11 +33,13 @@ xfs_make_iptr(struct xfs_mount *mp, struct xfs_buf *b, int o) return xfs_buf_offset(b, o << (mp)->m_sb.sb_inodelog); } +struct xfs_icreate_args; + /* * Allocate an inode on disk. Mode is used to tell whether the new inode will * need space, and whether it is a directory. */ -int xfs_dialloc(struct xfs_trans **tpp, xfs_ino_t parent, umode_t mode, +int xfs_dialloc(struct xfs_trans **tpp, const struct xfs_icreate_args *args, xfs_ino_t *new_ino); int xfs_difree(struct xfs_trans *tp, struct xfs_perag *pag, diff --git a/fs/xfs/scrub/tempfile.c b/fs/xfs/scrub/tempfile.c index d390d56cd8751..177f922acfaf1 100644 --- a/fs/xfs/scrub/tempfile.c +++ b/fs/xfs/scrub/tempfile.c @@ -88,7 +88,7 @@ xrep_tempfile_create( goto out_release_dquots; /* Allocate inode, set up directory. */ - error = xfs_dialloc(&tp, dp->i_ino, mode, &ino); + error = xfs_dialloc(&tp, &args, &ino); if (error) goto out_trans_cancel; error = xfs_icreate(tp, ino, &args, &sc->tempip); diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index 7dc6f326936ca..9ea7a18f5da14 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -704,7 +704,7 @@ xfs_create( * entry pointing to them, but a directory also the "." entry * pointing to itself. */ - error = xfs_dialloc(&tp, dp->i_ino, args->mode, &ino); + error = xfs_dialloc(&tp, args, &ino); if (!error) error = xfs_icreate(tp, ino, args, &du.ip); if (error) @@ -812,7 +812,7 @@ xfs_create_tmpfile( if (error) goto out_release_dquots; - error = xfs_dialloc(&tp, dp->i_ino, args->mode, &ino); + error = xfs_dialloc(&tp, args, &ino); if (!error) error = xfs_icreate(tp, ino, args, &ip); if (error) diff --git a/fs/xfs/xfs_qm.c b/fs/xfs/xfs_qm.c index 9490b913a4ab4..63f6ca2db2515 100644 --- a/fs/xfs/xfs_qm.c +++ b/fs/xfs/xfs_qm.c @@ -799,7 +799,7 @@ xfs_qm_qino_alloc( }; xfs_ino_t ino; - error = xfs_dialloc(&tp, 0, S_IFREG, &ino); + error = xfs_dialloc(&tp, &args, &ino); if (!error) error = xfs_icreate(tp, ino, &args, ipp); if (error) { diff --git a/fs/xfs/xfs_symlink.c b/fs/xfs/xfs_symlink.c index 77f19e2f66e07..4252b07cd2513 100644 --- a/fs/xfs/xfs_symlink.c +++ b/fs/xfs/xfs_symlink.c @@ -165,7 +165,7 @@ xfs_symlink( /* * Allocate an inode for the symlink. */ - error = xfs_dialloc(&tp, dp->i_ino, S_IFLNK, &ino); + error = xfs_dialloc(&tp, &args, &ino); if (!error) error = xfs_icreate(tp, ino, &args, &du.ip); if (error)