diff mbox series

xfs: don't allow SWAPEXT if we'd screw up quota accounting

Message ID 20200514205442.GK6714@magnolia (mailing list archive)
State Accepted
Headers show
Series xfs: don't allow SWAPEXT if we'd screw up quota accounting | expand

Commit Message

Darrick J. Wong May 14, 2020, 8:54 p.m. UTC
From: Darrick J. Wong <darrick.wong@oracle.com>

Since the old SWAPEXT ioctl doesn't know how to adjust quota ids,
bail out of the ids don't match and quotas are enabled.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 fs/xfs/xfs_bmap_util.c |    6 ++++++
 1 file changed, 6 insertions(+)

Comments

Eric Sandeen May 14, 2020, 9:12 p.m. UTC | #1
On 5/14/20 3:54 PM, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> Since the old SWAPEXT ioctl doesn't know how to adjust quota ids,
> bail out of the ids don't match and quotas are enabled.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>

makes sense, I probably missed the discussion that presumably arrived
at "ye gods trying to fix up the quota allocations is nigh impossible?"

And in the end, what's yet another -EINVAL return here, anyway? ;)

Reviewed-by: Eric Sandeen <sandeen@redhat.com>

> ---
>  fs/xfs/xfs_bmap_util.c |    6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c
> index cc23a3e23e2d..5e7da27c6e98 100644
> --- a/fs/xfs/xfs_bmap_util.c
> +++ b/fs/xfs/xfs_bmap_util.c
> @@ -1210,6 +1210,12 @@ xfs_swap_extents_check_format(
>  	struct xfs_inode	*ip,	/* target inode */
>  	struct xfs_inode	*tip)	/* tmp inode */
>  {
> +	/* User/group/project quota ids must match if quotas are enforced. */
> +	if (XFS_IS_QUOTA_ON(ip->i_mount) &&
> +	    (!uid_eq(VFS_I(ip)->i_uid, VFS_I(tip)->i_uid) ||
> +	     !gid_eq(VFS_I(ip)->i_gid, VFS_I(tip)->i_gid) ||
> +	     ip->i_d.di_projid != tip->i_d.di_projid))
> +		return -EINVAL;
>  
>  	/* Should never get a local format */
>  	if (ip->i_d.di_format == XFS_DINODE_FMT_LOCAL ||
>
Darrick J. Wong May 14, 2020, 9:18 p.m. UTC | #2
On Thu, May 14, 2020 at 04:12:44PM -0500, Eric Sandeen wrote:
> On 5/14/20 3:54 PM, Darrick J. Wong wrote:
> > From: Darrick J. Wong <darrick.wong@oracle.com>
> > 
> > Since the old SWAPEXT ioctl doesn't know how to adjust quota ids,
> > bail out of the ids don't match and quotas are enabled.
> > 
> > Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> 
> makes sense, I probably missed the discussion that presumably arrived
> at "ye gods trying to fix up the quota allocations is nigh impossible?"

No, it's not impossible[1], it's just the one person who replied also
declined to review it, so now I'm racing patches. :P

--D

[1] https://lore.kernel.org/linux-xfs/158864102885.182577.15936710415441871446.stgit@magnolia/

> And in the end, what's yet another -EINVAL return here, anyway? ;)
> 
> Reviewed-by: Eric Sandeen <sandeen@redhat.com>
> 
> > ---
> >  fs/xfs/xfs_bmap_util.c |    6 ++++++
> >  1 file changed, 6 insertions(+)
> > 
> > diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c
> > index cc23a3e23e2d..5e7da27c6e98 100644
> > --- a/fs/xfs/xfs_bmap_util.c
> > +++ b/fs/xfs/xfs_bmap_util.c
> > @@ -1210,6 +1210,12 @@ xfs_swap_extents_check_format(
> >  	struct xfs_inode	*ip,	/* target inode */
> >  	struct xfs_inode	*tip)	/* tmp inode */
> >  {
> > +	/* User/group/project quota ids must match if quotas are enforced. */
> > +	if (XFS_IS_QUOTA_ON(ip->i_mount) &&
> > +	    (!uid_eq(VFS_I(ip)->i_uid, VFS_I(tip)->i_uid) ||
> > +	     !gid_eq(VFS_I(ip)->i_gid, VFS_I(tip)->i_gid) ||
> > +	     ip->i_d.di_projid != tip->i_d.di_projid))
> > +		return -EINVAL;
> >  
> >  	/* Should never get a local format */
> >  	if (ip->i_d.di_format == XFS_DINODE_FMT_LOCAL ||
> >
Christoph Hellwig May 17, 2020, 7:35 a.m. UTC | #3
On Thu, May 14, 2020 at 01:54:42PM -0700, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> Since the old SWAPEXT ioctl doesn't know how to adjust quota ids,
> bail out of the ids don't match and quotas are enabled.

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>
diff mbox series

Patch

diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c
index cc23a3e23e2d..5e7da27c6e98 100644
--- a/fs/xfs/xfs_bmap_util.c
+++ b/fs/xfs/xfs_bmap_util.c
@@ -1210,6 +1210,12 @@  xfs_swap_extents_check_format(
 	struct xfs_inode	*ip,	/* target inode */
 	struct xfs_inode	*tip)	/* tmp inode */
 {
+	/* User/group/project quota ids must match if quotas are enforced. */
+	if (XFS_IS_QUOTA_ON(ip->i_mount) &&
+	    (!uid_eq(VFS_I(ip)->i_uid, VFS_I(tip)->i_uid) ||
+	     !gid_eq(VFS_I(ip)->i_gid, VFS_I(tip)->i_gid) ||
+	     ip->i_d.di_projid != tip->i_d.di_projid))
+		return -EINVAL;
 
 	/* Should never get a local format */
 	if (ip->i_d.di_format == XFS_DINODE_FMT_LOCAL ||