]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commit
Btrfs: fix data bytes_may_use underflow with fallocate due to failed quota reserve
authorRobbie Ko <robbieko@synology.com>
Tue, 26 Mar 2019 03:56:11 +0000 (11:56 +0800)
committerKleber Sacilotto de Souza <kleber.souza@canonical.com>
Wed, 14 Aug 2019 09:18:49 +0000 (11:18 +0200)
commite7c84b6c42078ac144d4f60cde7d1c7932286dc7
treea9ee72b6a0178c1522e32f6646929f82063f9b85
parent74f2a43c5816ccec7463fb6c1d2d7b4fad49d4d5
Btrfs: fix data bytes_may_use underflow with fallocate due to failed quota reserve

BugLink: https://bugs.launchpad.net/bugs/1838700
[ Upstream commit 39ad317315887c2cb9a4347a93a8859326ddf136 ]

When doing fallocate, we first add the range to the reserve_list and
then reserve the quota.  If quota reservation fails, we'll release all
reserved parts of reserve_list.

However, cur_offset is not updated to indicate that this range is
already been inserted into the list.  Therefore, the same range is freed
twice.  Once at list_for_each_entry loop, and once at the end of the
function.  This will result in WARN_ON on bytes_may_use when we free the
remaining space.

At the end, under the 'out' label we have a call to:

   btrfs_free_reserved_data_space(inode, data_reserved, alloc_start, alloc_end - cur_offset);

The start offset, third argument, should be cur_offset.

Everything from alloc_start to cur_offset was freed by the
list_for_each_entry_safe_loop.

Fixes: 18513091af94 ("btrfs: update btrfs_space_info's bytes_may_use timely")
Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Robbie Ko <robbieko@synology.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
fs/btrfs/file.c