* [PATCH] btrfs: fix int32 overflow in shrink_delalloc().
@ 2016-05-08 13:08 Adam Borowski
2016-05-09 9:51 ` David Sterba
0 siblings, 1 reply; 2+ messages in thread
From: Adam Borowski @ 2016-05-08 13:08 UTC (permalink / raw)
To: Chris Mason, Josef Bacik, David Sterba, linux-btrfs; +Cc: Adam Borowski
UBSAN: Undefined behaviour in fs/btrfs/extent-tree.c:4623:21
signed integer overflow:
10808 * 262144 cannot be represented in type 'int [8]'
If 8192<=items<16384, we request a writeback of an insane number of pages
which is benign (everything will be written). But if items>=16384, the
space reservation won't be enough.
Signed-off-by: Adam Borowski <kilobyte@angband.pl>
---
fs/btrfs/extent-tree.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 84e060e..391f576 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -4620,7 +4620,7 @@ static void shrink_delalloc(struct btrfs_root *root, u64 to_reclaim, u64 orig,
/* Calc the number of the pages we need flush for space reservation */
items = calc_reclaim_items_nr(root, to_reclaim);
- to_reclaim = items * EXTENT_SIZE_PER_ITEM;
+ to_reclaim = (u64)items * EXTENT_SIZE_PER_ITEM;
trans = (struct btrfs_trans_handle *)current->journal_info;
block_rsv = &root->fs_info->delalloc_block_rsv;
--
2.8.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] btrfs: fix int32 overflow in shrink_delalloc().
2016-05-08 13:08 [PATCH] btrfs: fix int32 overflow in shrink_delalloc() Adam Borowski
@ 2016-05-09 9:51 ` David Sterba
0 siblings, 0 replies; 2+ messages in thread
From: David Sterba @ 2016-05-09 9:51 UTC (permalink / raw)
To: Adam Borowski; +Cc: Chris Mason, Josef Bacik, David Sterba, linux-btrfs
On Sun, May 08, 2016 at 03:08:00PM +0200, Adam Borowski wrote:
> UBSAN: Undefined behaviour in fs/btrfs/extent-tree.c:4623:21
> signed integer overflow:
> 10808 * 262144 cannot be represented in type 'int [8]'
>
> If 8192<=items<16384, we request a writeback of an insane number of pages
> which is benign (everything will be written). But if items>=16384, the
> space reservation won't be enough.
>
> Signed-off-by: Adam Borowski <kilobyte@angband.pl>
Reviewed-by: David Sterba <dsterba@suse.com>
I think this is the best fix, although I usually do not like to see
random type casts. In this case, we'd have to change items to something
else and propagate the change trhough several functions for no apparent
gain. Just to satisfy one multiplication.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-05-09 9:51 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-08 13:08 [PATCH] btrfs: fix int32 overflow in shrink_delalloc() Adam Borowski
2016-05-09 9:51 ` David Sterba
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).