Skip to content

Commit 139a561

Browse files
lorddoskiaskdave
authored andcommitted
btrfs: Avoid possible qgroup_rsv_size overflow in btrfs_calculate_inode_block_rsv_size
qgroup_rsv_size is calculated as the product of outstanding_extent * fs_info->nodesize. The product is calculated with 32 bit precision since both variables are defined as u32. Yet qgroup_rsv_size expects a 64 bit result. Avoid possible multiplication overflow by casting outstanding_extent to u64. Such overflow would in the worst case (64K nodesize) require more than 65536 extents, which is quite large and i'ts not likely that it would happen in practice. Fixes-coverity-id: 1435101 Fixes: ff6bc37 ("btrfs: qgroup: Use independent and accurate per inode qgroup rsv") CC: stable@vger.kernel.org # 4.19+ Reviewed-by: Qu Wenruo <wqu@suse.com> Signed-off-by: Nikolay Borisov <nborisov@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 7ff2c2a commit 139a561

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

fs/btrfs/extent-tree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6174,7 +6174,7 @@ static void btrfs_calculate_inode_block_rsv_size(struct btrfs_fs_info *fs_info,
61746174
*
61756175
* This is overestimating in most cases.
61766176
*/
6177-
qgroup_rsv_size = outstanding_extents * fs_info->nodesize;
6177+
qgroup_rsv_size = (u64)outstanding_extents * fs_info->nodesize;
61786178

61796179
spin_lock(&block_rsv->lock);
61806180
block_rsv->size = reserve_size;

0 commit comments

Comments
 (0)