• Boris Burkov's avatar
    btrfs: fix qgroup_free_reserved_data int overflow · 9e65bfca
    Boris Burkov authored
    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: default avatarQu Wenruo <wqu@suse.com>
    Signed-off-by: default avatarBoris Burkov <boris@bur.io>
    Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
    Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
    9e65bfca
delalloc-space.c 17.2 KB