Skip to content

Commit 4e0473f

Browse files
elic307iSaeed Mahameed
authored andcommitted
lib: cpu_rmap: Avoid use after free on rmap->obj array entries
When calling irq_set_affinity_notifier() with NULL at the notify argument, it will cause freeing of the glue pointer in the corresponding array entry but will leave the pointer in the array. A subsequent call to free_irq_cpu_rmap() will try to free this entry again leading to possible use after free. Fix that by setting NULL to the array entry and checking that we have non-zero at the array entry when iterating over the array in free_irq_cpu_rmap(). The current code does not suffer from this since there are no cases where irq_set_affinity_notifier(irq, NULL) (note the NULL passed for the notify arg) is called, followed by a call to free_irq_cpu_rmap() so we don't hit and issue. Subsequent patches in this series excersize this flow, hence the required fix. Cc: Thomas Gleixner <[email protected]> Signed-off-by: Eli Cohen <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]> Reviewed-by: Jacob Keller <[email protected]>
1 parent e8d018d commit 4e0473f

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

lib/cpu_rmap.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,8 @@ void free_irq_cpu_rmap(struct cpu_rmap *rmap)
232232

233233
for (index = 0; index < rmap->used; index++) {
234234
glue = rmap->obj[index];
235-
irq_set_affinity_notifier(glue->notify.irq, NULL);
235+
if (glue)
236+
irq_set_affinity_notifier(glue->notify.irq, NULL);
236237
}
237238

238239
cpu_rmap_put(rmap);
@@ -268,6 +269,7 @@ static void irq_cpu_rmap_release(struct kref *ref)
268269
container_of(ref, struct irq_glue, notify.kref);
269270

270271
cpu_rmap_put(glue->rmap);
272+
glue->rmap->obj[glue->index] = NULL;
271273
kfree(glue);
272274
}
273275

@@ -297,6 +299,7 @@ int irq_cpu_rmap_add(struct cpu_rmap *rmap, int irq)
297299
rc = irq_set_affinity_notifier(irq, &glue->notify);
298300
if (rc) {
299301
cpu_rmap_put(glue->rmap);
302+
rmap->obj[glue->index] = NULL;
300303
kfree(glue);
301304
}
302305
return rc;

0 commit comments

Comments
 (0)