Skip to content

Commit f34462c

Browse files
bcodding-rhtrondmy
authored andcommitted
pnfs/blocklayout: Ensure disk address in block device map
It's possible that the device map is smaller than the offset into the device for the I/O we're adding. Add a check for it and bail out, otherwise we risk botching the bio calculations that follow. Signed-off-by: Benjamin Coddington <[email protected]> Signed-off-by: Trond Myklebust <[email protected]>
1 parent b396047 commit f34462c

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

fs/nfs/blocklayout/blocklayout.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ bl_alloc_init_bio(int npg, struct block_device *bdev, sector_t disk_sector,
137137
return bio;
138138
}
139139

140+
static bool offset_in_map(u64 offset, struct pnfs_block_dev_map *map)
141+
{
142+
return offset >= map->start && offset < map->start + map->len;
143+
}
144+
140145
static struct bio *
141146
do_add_page_to_bio(struct bio *bio, int npg, int rw, sector_t isect,
142147
struct page *page, struct pnfs_block_dev_map *map,
@@ -156,8 +161,8 @@ do_add_page_to_bio(struct bio *bio, int npg, int rw, sector_t isect,
156161

157162
/* translate to physical disk offset */
158163
disk_addr = (u64)isect << SECTOR_SHIFT;
159-
if (disk_addr < map->start || disk_addr >= map->start + map->len) {
160-
if (!dev->map(dev, disk_addr, map))
164+
if (!offset_in_map(disk_addr, map)) {
165+
if (!dev->map(dev, disk_addr, map) || !offset_in_map(disk_addr, map))
161166
return ERR_PTR(-EIO);
162167
bio = bl_submit_bio(bio);
163168
}

0 commit comments

Comments
 (0)