Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bcachefs: Guard against insufficient devices to create stripes

We can't create stripes if we don't have enough devices - this
manifested as an integer underflow bug later.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>

+14 -2
+14 -2
fs/bcachefs/ec.c
··· 1373 1373 h->nr_active_devs++; 1374 1374 1375 1375 rcu_read_unlock(); 1376 + 1377 + /* 1378 + * If we only have redundancy + 1 devices, we're better off with just 1379 + * replication: 1380 + */ 1381 + if (h->nr_active_devs < h->redundancy + 2) 1382 + bch_err(c, "insufficient devices available to create stripe (have %u, need %u) - mismatched bucket sizes?", 1383 + h->nr_active_devs, h->redundancy + 2); 1384 + 1376 1385 list_add(&h->list, &c->ec_stripe_head_list); 1377 1386 return h; 1378 1387 } ··· 1433 1424 1434 1425 h = ec_new_stripe_head_alloc(c, target, algo, redundancy, watermark); 1435 1426 found: 1427 + if (!IS_ERR_OR_NULL(h) && 1428 + h->nr_active_devs < h->redundancy + 2) { 1429 + mutex_unlock(&h->lock); 1430 + h = NULL; 1431 + } 1436 1432 mutex_unlock(&c->ec_stripe_head_lock); 1437 1433 return h; 1438 1434 } ··· 1695 1681 int ret; 1696 1682 1697 1683 h = __bch2_ec_stripe_head_get(trans, target, algo, redundancy, watermark); 1698 - if (!h) 1699 - bch_err(c, "no stripe head"); 1700 1684 if (IS_ERR_OR_NULL(h)) 1701 1685 return h; 1702 1686