From: Juergen Gross Date: Wed, 20 May 2020 08:35:01 +0000 (+0200) Subject: tools/libxengnttab: correct size of allocated memory X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=aad20e538d7ba0e36f5ed8d2bebb74096e3a6d7f;p=people%2Fsstabellini%2Fxen-unstable.git%2F.git tools/libxengnttab: correct size of allocated memory The size of the memory allocated for the IOCTL_GNTDEV_MAP_GRANT_REF ioctl() parameters is calculated wrong, which results in too much memory allocated. Signed-off-by: Juergen Gross Reviewed-by: Ian Jackson Reviewed-by: Roger Pau Monné Release-acked-by: Paul Durrant --- diff --git a/tools/libs/gnttab/freebsd.c b/tools/libs/gnttab/freebsd.c index 886b588303..0588501d0f 100644 --- a/tools/libs/gnttab/freebsd.c +++ b/tools/libs/gnttab/freebsd.c @@ -74,7 +74,7 @@ void *osdep_gnttab_grant_map(xengnttab_handle *xgt, void *addr = NULL; int domids_stride; unsigned int refs_size = ROUNDUP(count * - sizeof(struct ioctl_gntdev_map_grant_ref), + sizeof(struct ioctl_gntdev_grant_ref), PAGE_SHIFT); domids_stride = (flags & XENGNTTAB_GRANT_MAP_SINGLE_DOMAIN) ? 0 : 1; diff --git a/tools/libs/gnttab/linux.c b/tools/libs/gnttab/linux.c index a01bb6c698..74331a4c7b 100644 --- a/tools/libs/gnttab/linux.c +++ b/tools/libs/gnttab/linux.c @@ -91,9 +91,7 @@ void *osdep_gnttab_grant_map(xengnttab_handle *xgt, { int fd = xgt->fd; struct ioctl_gntdev_map_grant_ref *map; - unsigned int map_size = ROUNDUP((sizeof(*map) + (count - 1) * - sizeof(struct ioctl_gntdev_map_grant_ref)), - PAGE_SHIFT); + unsigned int map_size = sizeof(*map) + (count - 1) * sizeof(map->refs[0]); void *addr = NULL; int domids_stride = 1; int i; @@ -102,10 +100,10 @@ void *osdep_gnttab_grant_map(xengnttab_handle *xgt, domids_stride = 0; if ( map_size <= PAGE_SIZE ) - map = alloca(sizeof(*map) + - (count - 1) * sizeof(struct ioctl_gntdev_map_grant_ref)); + map = alloca(map_size); else { + map_size = ROUNDUP(map_size, PAGE_SHIFT); map = mmap(NULL, map_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON | MAP_POPULATE, -1, 0); if ( map == MAP_FAILED )