scoutfs: warn on invalid item counts

We had a bug where a caller was slowly increasing their item count for
every transaction they attempted in a loop.  Eventually the item count
grew to be too large to fit in a segment and they slept indefinitely.

Let's warn on invalid and impossibly large item counts as we enter
transactions.

Signed-off-by: Zach Brown <zab@versity.com>
This commit is contained in:
Zach Brown
2017-09-12 10:41:55 -07:00
committed by Mark Fasheh
parent ba40899e84
commit e165d89f7f
+9
View File
@@ -346,6 +346,15 @@ int scoutfs_hold_trans(struct super_block *sb, struct scoutfs_item_count *cnt)
struct scoutfs_reservation *rsv;
int ret;
/*
* Caller shouldn't provide garbage counts, nor counts that
* can't fit in segments by themselves.
*/
if (WARN_ON_ONCE(cnt->items <= 0 || cnt->keys < 0 || cnt->vals < 0) ||
WARN_ON_ONCE(!scoutfs_seg_fits_single(cnt->items, cnt->keys,
cnt->vals)))
return -EINVAL;
if (current == sbi->trans_task)
return 0;