Skip to contentSkip to conversation

xen-gntalloc: integer overflow in gntalloc_ioctl_alloc()

PATCH In review Dan Carpenter 2 participants 2 messages Nov 4, 2011

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 xen-gntalloc: integer overflow in gntalloc_ioctl_alloc()

On 32 bit systems a high value of op.count could lead to an integer overflow in the kzalloc() and gref_ids would be smaller than expected. If the you triggered another integer overflow in "if (gref_size + op.count > limit)" then you'd probably get memory corruption inside add_grefs().

drivers/xen/gntalloc.c +1 -1
index f6832f4..23c60cf 100644
@@ -280,7 +280,7 @@ static long gntalloc_ioctl_alloc(struct gntalloc_file_private_data *priv,
 		goto out;
 	}
 
-	gref_ids = kzalloc(sizeof(gref_ids[0]) * op.count, GFP_TEMPORARY);
+	gref_ids = kcalloc(op.count, sizeof(gref_ids[0]), GFP_TEMPORARY);
 	if (!gref_ids) {
 		rc = -ENOMEM;
 		goto out;
#1 lore raw

Re: [patch 1/2] xen-gntalloc: integer overflow in

Quoted 7 lines · Dan Carpenter

On 32 bit systems a high value of op.count could lead to an integer overflow in the kzalloc() and gref_ids would be smaller than expected. If the you triggered another integer overflow in "if (gref_size + op.count > limit)" then you'd probably get memory corruption inside add_grefs().

Great! Keep them coming! Will push for stable and 3.2.

Quoted 14 lines
drivers/xen/gntalloc.c +1 -1
index f6832f4..23c60cf 100644
@@ -280,7 +280,7 @@ static long gntalloc_ioctl_alloc(struct gntalloc_file_private_data *priv,
 		goto out;
 	}
 
-	gref_ids = kzalloc(sizeof(gref_ids[0]) * op.count, GFP_TEMPORARY);
+	gref_ids = kcalloc(op.count, sizeof(gref_ids[0]), GFP_TEMPORARY);
 	if (!gref_ids) {
 		rc = -ENOMEM;
 		goto out;