Skip to content

Commit be89a03

Browse files
jbeulichgregkh
authored andcommitted
Xen/gntdev: correct error checking in gntdev_map_grant_pages()
commit ebee0ea upstream. Failure of the kernel part of the mapping operation should also be indicated as an error to the caller, or else it may assume the respective kernel VA is okay to access. Furthermore gnttab_map_refs() failing still requires recording successfully mapped handles, so they can be unmapped subsequently. This in turn requires there to be a way to tell full hypercall failure from partial success - preset map_op status fields such that they won't "happen" to look as if the operation succeeded. Also again use GNTST_okay instead of implying its value (zero). This is part of XSA-361. Signed-off-by: Jan Beulich <jbeulich@suse.com> Cc: stable@vger.kernel.org Reviewed-by: Juergen Gross <jgross@suse.com> Signed-off-by: Juergen Gross <jgross@suse.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 1a5c227 commit be89a03

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

‎drivers/xen/gntdev.c‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -334,21 +334,22 @@ int gntdev_map_grant_pages(struct gntdev_grant_map *map)
334334
pr_debug("map %d+%d\n", map->index, map->count);
335335
err = gnttab_map_refs(map->map_ops, use_ptemod ? map->kmap_ops : NULL,
336336
map->pages, map->count);
337-
if (err)
338-
return err;
339337

340338
for (i = 0; i < map->count; i++) {
341-
if (map->map_ops[i].status) {
339+
if (map->map_ops[i].status == GNTST_okay)
340+
map->unmap_ops[i].handle = map->map_ops[i].handle;
341+
else if (!err)
342342
err = -EINVAL;
343-
continue;
344-
}
345343

346344
if (map->flags & GNTMAP_device_map)
347345
map->unmap_ops[i].dev_bus_addr = map->map_ops[i].dev_bus_addr;
348346

349-
map->unmap_ops[i].handle = map->map_ops[i].handle;
350-
if (use_ptemod)
351-
map->kunmap_ops[i].handle = map->kmap_ops[i].handle;
347+
if (use_ptemod) {
348+
if (map->kmap_ops[i].status == GNTST_okay)
349+
map->kunmap_ops[i].handle = map->kmap_ops[i].handle;
350+
else if (!err)
351+
err = -EINVAL;
352+
}
352353
}
353354
return err;
354355
}

‎include/xen/grant_table.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ gnttab_set_map_op(struct gnttab_map_grant_ref *map, phys_addr_t addr,
157157
map->flags = flags;
158158
map->ref = ref;
159159
map->dom = domid;
160+
map->status = 1; /* arbitrary positive value */
160161
}
161162

162163
static inline void

0 commit comments

Comments
 (0)