Skip to content

Commit ab4109f

Browse files
author
Bartosz Golaszewski
committed
gpio: sim: dispose of irq mappings before destroying the irq_sim domain
If a GPIO simulator device is unbound with interrupts still requested, we will hit a use-after-free issue in __irq_domain_deactivate_irq(). The owner of the irq domain must dispose of all mappings before destroying the domain object. Fixes: cb8c474 ("gpio: sim: new testing module") Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
1 parent 706a741 commit ab4109f

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

drivers/gpio/gpio-sim.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,15 @@ static void gpio_sim_mutex_destroy(void *data)
291291
mutex_destroy(lock);
292292
}
293293

294+
static void gpio_sim_dispose_mappings(void *data)
295+
{
296+
struct gpio_sim_chip *chip = data;
297+
unsigned int i;
298+
299+
for (i = 0; i < chip->gc.ngpio; i++)
300+
irq_dispose_mapping(irq_find_mapping(chip->irq_sim, i));
301+
}
302+
294303
static void gpio_sim_sysfs_remove(void *data)
295304
{
296305
struct gpio_sim_chip *chip = data;
@@ -406,6 +415,10 @@ static int gpio_sim_add_bank(struct fwnode_handle *swnode, struct device *dev)
406415
if (IS_ERR(chip->irq_sim))
407416
return PTR_ERR(chip->irq_sim);
408417

418+
ret = devm_add_action_or_reset(dev, gpio_sim_dispose_mappings, chip);
419+
if (ret)
420+
return ret;
421+
409422
mutex_init(&chip->lock);
410423
ret = devm_add_action_or_reset(dev, gpio_sim_mutex_destroy,
411424
&chip->lock);

0 commit comments

Comments
 (0)