btrfs: fix qgroup_free_reserved_data int overflow
authorBoris Burkov <boris@bur.io>
Fri, 1 Dec 2023 21:00:10 +0000 (13:00 -0800)
committerDavid Sterba <dsterba@suse.com>
Wed, 6 Dec 2023 21:32:46 +0000 (22:32 +0100)
commit9e65bfca24cf1d77e4a5c7a170db5867377b3fe7
treee8b84d6ae6fd7cbc7036f246ca1f4bfda1021cce
parentf63e1164b90b385cd832ff0fdfcfa76c3cc15436
btrfs: fix qgroup_free_reserved_data int overflow

The reserved data counter and input parameter is a u64, but we
inadvertently accumulate it in an int. Overflowing that int results in
freeing the wrong amount of data and breaking reserve accounting.

Unfortunately, this overflow rot spreads from there, as the qgroup
release/free functions rely on returning an int to take advantage of
negative values for error codes.

Therefore, the full fix is to return the "released" or "freed" amount by
a u64 argument and to return 0 or negative error code via the return
value.

Most of the call sites simply ignore the return value, though some
of them handle the error and count the returned bytes. Change all of
them accordingly.

CC: stable@vger.kernel.org # 6.1+
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Boris Burkov <boris@bur.io>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/delalloc-space.c
fs/btrfs/file.c
fs/btrfs/inode.c
fs/btrfs/ordered-data.c
fs/btrfs/qgroup.c
fs/btrfs/qgroup.h