]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
gpio: aggregator: fix a potential use-after-free
authorBartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Wed, 20 May 2026 08:49:11 +0000 (10:49 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 1 Jun 2026 15:54:53 +0000 (17:54 +0200)
[ Upstream commit 30c073cab97afb31901f94de9605177b6b84367e ]

On error we free aggr->lookups->dev_id before removing the entry from
the lookup table. If a concurrent thread calls gpiod_find() before we
remove the entry, it could iterate over the list and call
gpiod_match_lookup_table() which unconditionally dereferences dev_id
when calling strcmp(). Reverse the order of cleanup.

Fixes: 86f162e73d2d ("gpio: aggregator: introduce basic configfs interface")
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Link: https://patch.msgid.link/20260520084911.27938-1-bartosz.golaszewski@oss.qualcomm.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/gpio/gpio-aggregator.c

index 9adf3228c12a84e098ab7ffd543fcad58951ba99..6c84ca3ff1b648593d392e6e5b94644518c0a3e8 100644 (file)
@@ -969,8 +969,8 @@ static int gpio_aggregator_activate(struct gpio_aggregator *aggr)
        return 0;
 
 err_remove_lookup_table:
-       kfree(aggr->lookups->dev_id);
        gpiod_remove_lookup_table(aggr->lookups);
+       kfree(aggr->lookups->dev_id);
 err_remove_swnode:
        fwnode_remove_software_node(swnode);
 err_remove_lookups: