From patchwork Mon Sep 2 18:23: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: 13787584 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 98EDC19CC13 for ; Mon, 2 Sep 2024 18:23: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=1725301403; cv=none; b=BfnNJLROPBQ/zfQcENjhMLdN+Hi4ZAQ9KLgHGv1P1D3FaQuZ4lM1BTQoH2jt5PimkiOKUud02w+pda/bDxxuy8SYjtH7FymRFOfF3Fy2t28GyS6aAEi/+f9ZXHfpMgyAE9zVm6PST19NJYkOkIC8ovNBPWfmbMfzoUUxLL5vuMs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725301403; c=relaxed/simple; bh=3aXwgQgjWvfhf6ybbBvm/dEtiVoedmXMSGUbLjzNM2s=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ifO3LsMqS0x8H+VysfOTIZJdkgAzg6XsdGuOvO7hfQ8AjmwvwiJwobMRlGUJC09xxKxD9AQu5vPUP0VTKOMD2alz2jP7ybrf2h2BOopWzK9HW3bJNtF6CUk1JFLM7jpvsjm4arPJ3yCTfkYmM76Lo2dR/H83ytAJPcKt0AMR3D4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QvjJeWno; 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="QvjJeWno" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6AEAFC4CEC2; Mon, 2 Sep 2024 18:23:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725301403; bh=3aXwgQgjWvfhf6ybbBvm/dEtiVoedmXMSGUbLjzNM2s=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=QvjJeWnoi04v9dUHGpg1kIsWEotrYvhesc9HngGvOMRd/429AKiOXyQ0bHs20iLOe 54AVRKF+VAbJ8I9tF5YplUQb2F1rtEMzYJMVEQaZo4knRa/wgTBcoJF1zAmoBiiHBP kt5T1VutxBDDT+J8U+j58fPkLGyQExFdxzV5+O7Gp8o+x0nQjyMptabFAIF2ZcZCtk our4h74I4rvJCNkQWdBcu0KjhGJL/jO6d0OIds4Mav7/elsJwWPiWhkaCKRIHR1LSe HcffdlKcmXj8PWmo6Omy8U4+B987HHjDEcZ4pbzcli19Yo27/zrUSFncQxqJoqkmgb 3L5siGCNFU5sQ== Date: Mon, 02 Sep 2024 11:23:22 -0700 Subject: [PATCH 1/3] xfs: validate inumber in xfs_iget From: "Darrick J. Wong" To: chandanbabu@kernel.org, djwong@kernel.org Cc: Christoph Hellwig , Dave Chinner , linux-xfs@vger.kernel.org Message-ID: <172530105323.3324987.17852010194613598900.stgit@frogsfrogsfrogs> In-Reply-To: <172530105300.3324987.5977059243804546726.stgit@frogsfrogsfrogs> References: <172530105300.3324987.5977059243804546726.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 cf629302d48e..887d2a01161e 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 Mon Sep 2 18:23: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: 13787585 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 73B8B5680 for ; Mon, 2 Sep 2024 18:23:39 +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=1725301419; cv=none; b=qoU/GQ+D3Idgg0nhAN5pRUsHGcr5NiqMw1vtLsYDrB18Nunp6v2e4jutSCuRzuipvPoKKlFo1KkdcBYTAnDq1Yu6BV9F3IJGMGf4YT75kYDZwvmhzmunSlHDsFR1IjrzAy6b08f1W2Bb7QLAwe8NWilvFXzGDUQ3+TrYL8talYs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725301419; c=relaxed/simple; bh=zvvHylj8DN9zNqk6frhvIz34CSS4wSiIWoAauOBQ7ws=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=C9pBaGUWjxlJVCmypYhCkfoj4s6UlQ49CvxkrcTV8as5q0oAAXvx8xaybWs50LL4yZM5q+ii6NHVcGAP1X8tw1Oo3ToQz8Yl1Dv7GDE6vVcImjZxV05sRGvNcQUtVwGKqPKw1c/5Gz05YIObkjAMGjEb7cjnhKR43gkI9wRVCJM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=q5pZ8f7h; 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="q5pZ8f7h" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0FF17C4CEC2; Mon, 2 Sep 2024 18:23:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725301419; bh=zvvHylj8DN9zNqk6frhvIz34CSS4wSiIWoAauOBQ7ws=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=q5pZ8f7hDl2XqZxpH/dNFGekE0zMZz8WQJhGh3Fwc914iD/2nAAw7a/41dlfgUkon 5ep0YpAu8SZZGZCYwTks9uf4oWS46vYbwmI+5R1B89lslngcZR5KhPKhUH7FSJbbYW HGxYdNzE1sXxZ5+g/Y4QlBLCHuxQLJ33pXWeFhECxnk/Ec4btnCUBbsOhkGy68ERZR wAfzAzaKcab6Kv3phhqLYle/yxS4SCO+/9J7kxOIcbvTM6Ha26z0fkUSxcvOz7xU5U 1jBcLERaJG9E3Ym6NbntjhZrLoUfZPgfdv91uvLp7TAWLkDHjVixzUcEBGcyO+DURN gTJ3FzpCd6VYQ== Date: Mon, 02 Sep 2024 11:23:38 -0700 Subject: [PATCH 2/3] xfs: match on the global RT inode numbers in xfs_is_metadata_inode From: "Darrick J. Wong" To: chandanbabu@kernel.org, djwong@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172530105339.3324987.3663743222940678218.stgit@frogsfrogsfrogs> In-Reply-To: <172530105300.3324987.5977059243804546726.stgit@frogsfrogsfrogs> References: <172530105300.3324987.5977059243804546726.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 51defdebef30..1908409968db 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 Mon Sep 2 18:23:54 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: 13787586 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 34CF819CC03 for ; Mon, 2 Sep 2024 18:23: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=1725301435; cv=none; b=RjlGsPz9T1wtZCGPThcFLYM9Tv01ffsBUb72w0VA5eiLiGSkz4q7HGCPhoDODOTiPimh7P1EG4qBQO+dZhq8sy1Tief3tMbKEFHaRQTHqKoXQ6358u8zUKcg2Ukk4zV+n1KTYTjhTQ9cav/Q3+2+Bx3IIr/THHkSL4Cxx/mkJ6o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725301435; c=relaxed/simple; bh=tbOv9CTHgtChSiHs2pGqKJMRyMTKRa9HG4Q60s+dG1Q=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=SN+AT3CkB93QT6GCDBvuN7HU7gGPebSGzBT6SBbi4yHvgLIC9K4BNotFpa+1G9HVALmLd9nbiWm78XfrmWFYTEEaHaF99Gx/ETgkbgzKg6gEilvKbM91Amo/6SZnep7Ey+k9yp70parUGXVIHZafmsAqZnr8fDMLwpQPOObOVYc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TEAffdNK; 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="TEAffdNK" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C4AD8C4CEC2; Mon, 2 Sep 2024 18:23:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725301434; bh=tbOv9CTHgtChSiHs2pGqKJMRyMTKRa9HG4Q60s+dG1Q=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=TEAffdNKnsAvLy11iUYHtfsPvmakSGBgphGRATqCmANFNqRsJc1j+U9IoPthedo1Z nd30BBaB3YGijGu5VDWd2qwnIKuLPJ7xUy/7xWSoe6SeNOzU0Q6rfbCVm1ctbrrxY7 gebcQ2zQQ1jif6ivOJDT4NzQRThQ2pwPu5ezbVpzs++gqTy9U5VL7icLIU6u3N9Onn blfkBgoxmcbFYFVB6GFvwZL/dQonQNk+AwVL4uw1qoDGudSBMn5exjjt+ncyWtQ90P CZQi/6WUxxbofDz+sth+wDLj9YTg4/fqFqgURB/sByeskErTxtMO/tbgxAT4ysyXG8 oa+9DoG7PsQ6g== Date: Mon, 02 Sep 2024 11:23:54 -0700 Subject: [PATCH 3/3] xfs: pass the icreate args object to xfs_dialloc From: "Darrick J. Wong" To: chandanbabu@kernel.org, djwong@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172530105356.3324987.8567603124185540522.stgit@frogsfrogsfrogs> In-Reply-To: <172530105300.3324987.5977059243804546726.stgit@frogsfrogsfrogs> References: <172530105300.3324987.5977059243804546726.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 0af5b7a33d05..fc70601e8d8e 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 b549627e3a61..3a1323155a45 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 d390d56cd875..177f922acfaf 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 7dc6f326936c..9ea7a18f5da1 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 9490b913a4ab..63f6ca2db251 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 77f19e2f66e0..4252b07cd251 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)