]> git.baikalelectronics.ru Git - kernel.git/commit
xfs: fix chown leaking delalloc quota blocks when fssetxattr fails
authorDarrick J. Wong <djwong@kernel.org>
Sat, 30 Jan 2021 03:06:10 +0000 (19:06 -0800)
committerDarrick J. Wong <djwong@kernel.org>
Wed, 3 Feb 2021 17:17:47 +0000 (09:17 -0800)
commit1aecf3734a95f3c167d1495550ca57556d33f7ec
treeebd8b86b29f38b71938eb903d8829f0bfe3a4e75
parent560ab6c0d12ebccabb83638abe23a7875b946f9a
xfs: fix chown leaking delalloc quota blocks when fssetxattr fails

While refactoring the quota code to create a function to allocate inode
change transactions, I noticed that xfs_qm_vop_chown_reserve does more
than just make reservations: it also *modifies* the incore counts
directly to handle the owner id change for the delalloc blocks.

I then observed that the fssetxattr code continues validating input
arguments after making the quota reservation but before dirtying the
transaction.  If the routine decides to error out, it fails to undo the
accounting switch!  This leads to incorrect quota reservation and
failure down the line.

We can fix this by making the reservation function do only that -- for
the new dquot, it reserves ondisk and delalloc blocks to the
transaction, and the old dquot hangs on to its incore reservation for
now.  Once we actually switch the dquots, we can then update the incore
reservations because we've dirtied the transaction and it's too late to
turn back now.

No fixes tag because this has been broken since the start of git.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
fs/xfs/xfs_qm.c