From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796384440; b=G5JolFefVLYlPn60AZ//yUyBHm6EybePUYARim3QgunGtFdHYDNOQnFiTK8r2cn2mQHY V+eSPJz/S5xtHcgIxmko/9FjSTVeiuTKJmn83eMMofHoldt6VI01vm4U1hZGXDNBhB1hv oJ1NcJlGxzgH/S1ZnBEpXrdjSMKg65YroLlJujtsJWq7wxVG1VDJK1wPer4J6goX8IbE3 Uv3KSnMFbmp9iIWXbIQui4FYWj66mWaokTWFcRLw31XjtOC+uiR0rJ3IrI0JM3k2XFX6k ioO5BdfIz/sr/c9VDDyatk7j/eQNMx0RrWGJtqSGG1RAtFkQsSNxXR2m4tkRVv7NAqQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384440; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=sFgE/ZQliNBgR+2iT0wMcodYDRPkUowvNDnaxJTR+j4=; b=QrPBNKNhPRaYwb8L1sG2RTp8SMzirYQnsmPaTfz9xCafLbjO6x+qKukRyyRlHMfuHooy MFlaDafk4EJxbCUXtXFbJAoObS8PNmEM1pHvksFOCvaJ+cJYuKoMR5+LujKGP+ykqGSJZ 2egVtkq//5cLVphEUolb6gmVQMqIF1lv9CWOpMFCSy0/ilzSaaNikZsXwEqShzO56IZPB F4UClsXUNgrLRa2BZHO7enqFENKZnY8apGSZ1bG7dswg1abIZSO7yEQ8Iitaqf2XGA1qL 0kdk6Kldd4grv+PH2Do6Ivpr0bevbl0b3XNlf49kPvnX4aXSrGlHp+YcDfPM5feMI0A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=F4zYFAyA; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BB8AC606A322; Fri, 4 Dec 2026 11:40:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=F4zYFAyA Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2EE3C1F0092C; Fri, 4 Dec 2026 11:40:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796384440; bh=sFgE/ZQliNBgR+2iT0wMcodYDRPkUowvNDnaxJTR+j4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=F4zYFAyAPW9yBoHXE7RUS+Gv3DW0Mb901dn3k5XJT3wLQkiJckPaXMiqMXZzavibH BDYJsY7QK2trjudEO1VxG2d4TaKkFnnzDfkjl2xHMPgPH/4OpWYzloYjdAsDd12b6k CldcvZZhdBuZM/HD36qLkuTRUXgk3IhDItxAOk+g= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Guangshuo Li , Bartosz Golaszewski , Sasha Levin Subject: [PATCH 6.6 0109/1167] gpio: mpc8xxx: Fix potential use-after-free of IRQ domain Date: Fri, 4 Dec 2026 18:52:16 +0900 Message-ID: <20261204100704.933634764@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Guangshuo Li [ Upstream commit 9e4b35c95fede87bad36f68b7ff1eae94ea6b910 ] GPIO chip cleanup can call the to_irq callback while releasing requested GPIOs. Removing the IRQ domain first leaves that callback using a freed domain, both on removal and after an IRQ request failure. Register domain cleanup before GPIO chip registration so devres removes the chip before freeing the domain. This issue was found by our static analysis tool under development. Fixes: 257e10752c13 ("gpio: mpc8xxx: Use of_mm_gpiochip_remove") Signed-off-by: Guangshuo Li Link: https://patch.msgid.link/a4fec7fe970d6fc9135b488f57ba7e145b809359.1793377433.git.liguangshuo@mail.sdu.edu.cn Signed-off-by: Bartosz Golaszewski Signed-off-by: Sasha Levin --- drivers/gpio/gpio-mpc8xxx.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/drivers/gpio/gpio-mpc8xxx.c b/drivers/gpio/gpio-mpc8xxx.c index 6116035dca557..2817bc966285b 100644 --- a/drivers/gpio/gpio-mpc8xxx.c +++ b/drivers/gpio/gpio-mpc8xxx.c @@ -296,6 +296,14 @@ static const struct of_device_id mpc8xxx_gpio_ids[] = { {} }; +static void mpc8xxx_irq_domain_remove(void *data) +{ + struct mpc8xxx_gpio_chip *mpc8xxx_gc = data; + + if (mpc8xxx_gc->irq) + irq_domain_remove(mpc8xxx_gc->irq); +} + static int mpc8xxx_probe(struct platform_device *pdev) { const struct mpc8xxx_gpio_devtype *devtype = NULL; @@ -376,6 +384,11 @@ static int mpc8xxx_probe(struct platform_device *pdev) gc->read_reg(mpc8xxx_gc->regs + GPIO_DIR); } + /* GPIO chip cleanup still needs the IRQ domain. */ + ret = devm_add_action_or_reset(dev, mpc8xxx_irq_domain_remove, mpc8xxx_gc); + if (ret) + return ret; + ret = devm_gpiochip_add_data(dev, gc, mpc8xxx_gc); if (ret) { dev_err(dev, @@ -406,25 +419,20 @@ static int mpc8xxx_probe(struct platform_device *pdev) if (ret) { dev_err(dev, "failed to devm_request_irq(%d), ret = %d\n", mpc8xxx_gc->irqn, ret); - goto err; + return ret; } device_init_wakeup(dev, true); return 0; -err: - irq_domain_remove(mpc8xxx_gc->irq); - return ret; } static void mpc8xxx_remove(struct platform_device *pdev) { struct mpc8xxx_gpio_chip *mpc8xxx_gc = platform_get_drvdata(pdev); - if (mpc8xxx_gc->irq) { + if (mpc8xxx_gc->irq) irq_set_chained_handler_and_data(mpc8xxx_gc->irqn, NULL, NULL); - irq_domain_remove(mpc8xxx_gc->irq); - } } #ifdef CONFIG_PM -- 2.53.0