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

dm zoned: Fix zone report handling

The function blkdev_report_zones() returns success even if no zone
information is reported (empty report). Empty zone reports can only
happen if the report start sector passed exceeds the device capacity.
The conditions for this to happen are either a bug in the caller code,
or, a change in the device that forced the low level driver to change
the device capacity to a value that is lower than the report start
sector. This situation includes a failed disk revalidation resulting in
the disk capacity being changed to 0.

If this change happens while dm-zoned is in its initialization phase
executing dmz_init_zones(), this function may enter an infinite loop
and hang the system. To avoid this, add a check to disallow empty zone
reports and bail out early. Also fix the function dmz_update_zone() to
make sure that the report for the requested zone was correctly obtained.

Fixes: 3b1a94c88b79 ("dm zoned: drive-managed zoned block device target")
Cc: stable@vger.kernel.org
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Reviewed-by: Shaun Tancheff <shaun@tancheff.com>
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>

authored by

Damien Le Moal and committed by
Mike Snitzer
7aedf75f a3839bc6

+5
+5
drivers/md/dm-zoned-metadata.c
··· 1169 1169 goto out; 1170 1170 } 1171 1171 1172 + if (!nr_blkz) 1173 + break; 1174 + 1172 1175 /* Process report */ 1173 1176 for (i = 0; i < nr_blkz; i++) { 1174 1177 ret = dmz_init_zone(zmd, zone, &blkz[i]); ··· 1207 1204 /* Get zone information from disk */ 1208 1205 ret = blkdev_report_zones(zmd->dev->bdev, dmz_start_sect(zmd, zone), 1209 1206 &blkz, &nr_blkz, GFP_NOIO); 1207 + if (!nr_blkz) 1208 + ret = -EIO; 1210 1209 if (ret) { 1211 1210 dmz_dev_err(zmd->dev, "Get zone %u report failed", 1212 1211 dmz_id(zmd, zone));