zhack: Fix importing large allocation profiles on small pools (#18256)

This patch fixes a segmentation fault in zhack metaslab leak which might
be triggered by feeding zhack with a fragmentation profile that's
exported from a pool larger than the target pool.

Fixes: 8f15d2e4d5
Sponsored-by: Klara, Inc.
Sponsored-by: Wasabi Technology, Inc.
Reviewed-by: Paul Dagnelie <paul.dagnelie@klarasystems.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>

Signed-off-by: Mateusz Piotrowski <mateusz.piotrowski@klarasystems.com>
This commit is contained in:
Mateusz Piotrowski 2026-02-24 19:24:22 +01:00 committed by GitHub
parent 0f608aa6ca
commit 3408332d71
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -745,8 +745,11 @@ zhack_do_metaslab_leak(int argc, char **argv)
&start, &size), ==, 2);
ASSERT(vd);
metaslab_t *cur =
vd->vdev_ms[start >> vd->vdev_ms_shift];
size_t idx;
idx = start >> vd->vdev_ms_shift;
if (idx >= vd->vdev_ms_count)
continue;
metaslab_t *cur = vd->vdev_ms[idx];
if (prev != cur) {
if (prev) {
dmu_tx_commit(tx);