Skip to content

Commit feda880

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 0e38268 commit feda880

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
@@ -344,21 +344,22 @@ int gntdev_map_grant_pages(struct gntdev_grant_map *map)
344344
pr_debug("map %d+%d\n", map->index, map->count);
345345
err = gnttab_map_refs(map->map_ops, use_ptemod ? map->kmap_ops : NULL,
346346
map->pages, map->count);
347-
if (err)
348-
return err;
349347

350348
for (i = 0; i < map->count; i++) {
351-
if (map->map_ops[i].status) {
349+
if (map->map_ops[i].status == GNTST_okay)
350+
map->unmap_ops[i].handle = map->map_ops[i].handle;
351+
else if (!err)
352352
err = -EINVAL;
353-
continue;
354-
}
355353

356354
if (map->flags & GNTMAP_device_map)
357355
map->unmap_ops[i].dev_bus_addr = map->map_ops[i].dev_bus_addr;
358356

359-
map->unmap_ops[i].handle = map->map_ops[i].handle;
360-
if (use_ptemod)
361-
map->kunmap_ops[i].handle = map->kmap_ops[i].handle;
357+
if (use_ptemod) {
358+
if (map->kmap_ops[i].status == GNTST_okay)
359+
map->kunmap_ops[i].handle = map->kmap_ops[i].handle;
360+
else if (!err)
361+
err = -EINVAL;
362+
}
362363
}
363364
return err;
364365
}

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)