From: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>
To: Lorenzo Bianconi <lorenzo@kernel.org>
Cc: Linus Walleij <linusw@kernel.org>, Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Bartosz Golaszewski <brgl@kernel.org>,
Christian Marangi <ansuelsmth@gmail.com>,
Benjamin Larsson <benjamin.larsson@genexis.eu>,
AngeloGioacchino Del Regno
<angelogioacchino.delregno@collabora.com>,
linux-gpio@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org,
Markus Gothe <markus.gothe@genexis.eu>,
Matheus Sampaio Queiroga <srherobrine20@gmail.com>
Subject: Re: [PATCH v7 14/34] pinctrl: airoha: fix potential kenel panic in IRQ handling code
Date: Mon, 27 Jul 2026 12:02:41 +0300 [thread overview]
Message-ID: <d71b9758-b8b8-463e-8da2-a91d1e98759a@iopsys.eu> (raw)
In-Reply-To: <amcXSQ4pfRCJjihI@lore-desk>
On 7/27/26 11:31, Lorenzo Bianconi wrote:
>> airoha_irq_unmask(), airoha_irq_mask(), airoha_irq_type() functions
>> gets invalid pointers when initialize gpiochip and pinctrl variables.
>> Generally this should lead to kernel panic.
>>
>> Details:
>>
>> gpiochip = irq_data_get_irq_chip_data(data);
>>
>> will initialize gpiochip variable with data->chip_data value. This value
>> initialized inside gpiochip_irq_map() function
>>
>> static int gpiochip_irq_map(struct irq_domain *d, unsigned int irq,
>> irq_hw_number_t hwirq)
>> {
>> struct gpio_chip *gc = d->host_data;
>> ...
>> irq_set_chip_data(irq, gc);
>> ...
>> }
>>
>> Thus gpiochip variable of 'struct airoha_pinctrl_gpiochip *' type will be
>> initialized with a pointer to unrelated variable of 'struct gpio_chip'
>> type.
>>
>> pinctrl pointer derived from the gpiochip variable
>>
>> pinctrl = container_of(gpiochip, struct airoha_pinctrl, gpiochip);
>>
>> thus it will get wrong value as well.
>>
>> So any access to the data pointed by gpiochip and pinctrl variables is
>> extremelly dangerous.
>>
>> This patch implements correct logic of getting gpiochip and pinctrl
>> pointers.
>>
>> Fixes: 1c8ace2d0725 ("pinctrl: airoha: Add support for EN7581 SoC")
>> Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>
>> ---
>> drivers/pinctrl/airoha/pinctrl-airoha.c | 20 +++++++++-----------
>> 1 file changed, 9 insertions(+), 11 deletions(-)
>>
>> diff --git a/drivers/pinctrl/airoha/pinctrl-airoha.c b/drivers/pinctrl/airoha/pinctrl-airoha.c
>> index faad5d3ada31c..6cf4ed5976fb0 100644
>> --- a/drivers/pinctrl/airoha/pinctrl-airoha.c
>> +++ b/drivers/pinctrl/airoha/pinctrl-airoha.c
>> @@ -2569,18 +2569,17 @@ static int airoha_gpio_direction_output(struct gpio_chip *chip,
>> /* irq callbacks */
>> static void airoha_irq_unmask(struct irq_data *data)
>> {
>> + struct gpio_chip *gc = irq_data_get_irq_chip_data(data);
>> + struct airoha_pinctrl *pinctrl = gpiochip_get_data(gc);
>> + struct airoha_pinctrl_gpiochip *gpiochip = &pinctrl->gpiochip;
>> u8 offset = data->hwirq % AIROHA_REG_GPIOCTRL_NUM_PIN;
>> u8 index = data->hwirq / AIROHA_REG_GPIOCTRL_NUM_PIN;
>> u32 mask = GENMASK(2 * offset + 1, 2 * offset);
>> - struct airoha_pinctrl_gpiochip *gpiochip;
>> - struct airoha_pinctrl *pinctrl;
>> u32 val = BIT(2 * offset);
>>
>> - gpiochip = irq_data_get_irq_chip_data(data);
> I agree the proposed approach is more standard and I am fine with it, but can
> you please provide more details about how it can panic?
>
> gpio_chip is the first element of airoha_pinctrl_gpiochip so it is fine to cast
> irq_data_get_irq_chip_data() return value to airoha_pinctrl_gpiochip, right?
Sorry, you are right, the will be no panic unless structure fields will
be reordered.
I'll fix commit message
>
> Regards,
> Lorenzo
>
>> if (WARN_ON_ONCE(data->hwirq >= ARRAY_SIZE(gpiochip->irq_type)))
>> return;
>>
>> - pinctrl = container_of(gpiochip, struct airoha_pinctrl, gpiochip);
>> switch (gpiochip->irq_type[data->hwirq]) {
>> case IRQ_TYPE_LEVEL_LOW:
>> val = val << 1;
>> @@ -2606,14 +2605,12 @@ static void airoha_irq_unmask(struct irq_data *data)
>>
>> static void airoha_irq_mask(struct irq_data *data)
>> {
>> + struct gpio_chip *gc = irq_data_get_irq_chip_data(data);
>> + struct airoha_pinctrl *pinctrl = gpiochip_get_data(gc);
>> + struct airoha_pinctrl_gpiochip *gpiochip = &pinctrl->gpiochip;
>> u8 offset = data->hwirq % AIROHA_REG_GPIOCTRL_NUM_PIN;
>> u8 index = data->hwirq / AIROHA_REG_GPIOCTRL_NUM_PIN;
>> u32 mask = GENMASK(2 * offset + 1, 2 * offset);
>> - struct airoha_pinctrl_gpiochip *gpiochip;
>> - struct airoha_pinctrl *pinctrl;
>> -
>> - gpiochip = irq_data_get_irq_chip_data(data);
>> - pinctrl = container_of(gpiochip, struct airoha_pinctrl, gpiochip);
>>
>> regmap_clear_bits(pinctrl->regmap, gpiochip->level[index], mask);
>> regmap_clear_bits(pinctrl->regmap, gpiochip->edge[index], mask);
>> @@ -2621,9 +2618,10 @@ static void airoha_irq_mask(struct irq_data *data)
>>
>> static int airoha_irq_type(struct irq_data *data, unsigned int type)
>> {
>> - struct airoha_pinctrl_gpiochip *gpiochip;
>> + struct gpio_chip *gc = irq_data_get_irq_chip_data(data);
>> + struct airoha_pinctrl *pinctrl = gpiochip_get_data(gc);
>> + struct airoha_pinctrl_gpiochip *gpiochip = &pinctrl->gpiochip;
>>
>> - gpiochip = irq_data_get_irq_chip_data(data);
>> if (data->hwirq >= ARRAY_SIZE(gpiochip->irq_type))
>> return -EINVAL;
>>
>> --
>> 2.53.0
>>
next prev parent reply other threads:[~2026-07-27 9:02 UTC|newest]
Thread overview: 54+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-27 7:42 [PATCH v7 00/34] pinctrl: airoha: split on shared and SoC drivers, add more SoCs Mikhail Kshevetskiy
2026-07-27 7:42 ` [PATCH v7 01/34] dt-bindings: pinctrl: airoha: en7581: fix misprint in i2s function name Mikhail Kshevetskiy
2026-07-27 7:46 ` Lorenzo Bianconi
2026-07-27 7:42 ` [PATCH v7 02/34] dt-bindings: pinctrl: airoha: en7581: fix pwm pin-groups Mikhail Kshevetskiy
2026-07-27 7:47 ` Lorenzo Bianconi
2026-07-27 7:42 ` [PATCH v7 03/34] dt-bindings: pinctrl: airoha: an7583: fix device tree binding schema Mikhail Kshevetskiy
2026-07-27 7:42 ` [PATCH v7 04/34] pinctrl: airoha: an7581: fix misprint in bitfield name Mikhail Kshevetskiy
2026-07-27 7:50 ` Lorenzo Bianconi
2026-07-27 7:42 ` [PATCH v7 05/34] pinctrl: airoha: an7583: fix I2C0_SDA_PD register bit order Mikhail Kshevetskiy
2026-07-27 7:42 ` [PATCH v7 06/34] pinctrl: airoha: an7583: there are no muxes to enable i2c buses Mikhail Kshevetskiy
2026-07-27 7:42 ` [PATCH v7 07/34] dt-bindings: pinctrl: airoha: an7583: remove i2c pin function Mikhail Kshevetskiy
2026-07-27 7:51 ` Lorenzo Bianconi
2026-07-27 7:42 ` [PATCH v7 08/34] pinctrl: airoha: an7581: fix mux/conf of pcie_reset pins Mikhail Kshevetskiy
2026-07-27 7:42 ` [PATCH v7 09/34] dt-bindings: pinctrl: airoha: en7581: allow configuration of pcie_reset pins as gpio or pwm Mikhail Kshevetskiy
2026-07-27 7:42 ` [PATCH v7 10/34] pinctrl: airoha: an7583: fix muxing of non-gpio default pins Mikhail Kshevetskiy
2026-07-27 7:42 ` [PATCH v7 11/34] dt-bindings: pinctrl: airoha: an7583: allow configuration of non-gpio default pins as gpio and pwm Mikhail Kshevetskiy
2026-07-27 7:42 ` [PATCH v7 12/34] pinctrl: airoha: add missed get_direction() function for gpio_chip Mikhail Kshevetskiy
2026-07-27 8:04 ` Lorenzo Bianconi
2026-07-27 9:40 ` Mikhail Kshevetskiy
2026-07-27 9:46 ` Lorenzo Bianconi
2026-07-27 7:42 ` [PATCH v7 13/34] pinctrl: airoha: add set_direction() helper " Mikhail Kshevetskiy
2026-07-27 8:06 ` Lorenzo Bianconi
2026-07-27 7:42 ` [PATCH v7 14/34] pinctrl: airoha: fix potential kenel panic in IRQ handling code Mikhail Kshevetskiy
2026-07-27 8:31 ` Lorenzo Bianconi
2026-07-27 9:02 ` Mikhail Kshevetskiy [this message]
2026-07-27 7:42 ` [PATCH v7 15/34] pinctrl: airoha: fix IRQ mask/unmask code Mikhail Kshevetskiy
2026-07-27 8:37 ` Lorenzo Bianconi
2026-07-27 7:42 ` [PATCH v7 16/34] pinctrl: airoha: add missed IRQ resource helpers Mikhail Kshevetskiy
2026-07-27 8:34 ` Lorenzo Bianconi
2026-07-27 7:42 ` [PATCH v7 17/34] pinctrl: airoha: fix edge-triggered interrupts handling Mikhail Kshevetskiy
2026-07-27 9:01 ` Lorenzo Bianconi
2026-07-27 7:42 ` [PATCH v7 18/34] pinctrl: airoha: remove not needed irq_type[] array Mikhail Kshevetskiy
2026-07-27 9:03 ` Lorenzo Bianconi
2026-07-27 7:42 ` [PATCH v7 19/34] pinctrl: airoha: move common definitions to the separate header Mikhail Kshevetskiy
2026-07-27 7:42 ` [PATCH v7 20/34] pinctrl: airoha: split driver on shared code and SoC specific drivers Mikhail Kshevetskiy
2026-07-27 9:14 ` Lorenzo Bianconi
2026-07-27 9:23 ` Mikhail Kshevetskiy
2026-07-27 9:27 ` Lorenzo Bianconi
2026-07-27 9:28 ` Mikhail Kshevetskiy
2026-07-27 12:48 ` Lorenzo Bianconi
2026-07-27 7:42 ` [PATCH v7 21/34] pinctrl: airoha: an7581: remove en7581 prefix from variable names Mikhail Kshevetskiy
2026-07-27 7:42 ` [PATCH v7 22/34] pinctrl: airoha: an7583: remove an7583 prefix from variable names and definitions Mikhail Kshevetskiy
2026-07-27 7:42 ` [PATCH v7 23/34] pinctrl: airoha: an7583: rename registers to match its an7583 names Mikhail Kshevetskiy
2026-07-27 7:42 ` [PATCH v7 24/34] pinctrl: airoha: an7583: add support for npu_uart pinmux Mikhail Kshevetskiy
2026-07-27 7:42 ` [PATCH v7 25/34] dt-bindings: pinctrl: airoha: an7583: add npu_uart pin group Mikhail Kshevetskiy
2026-07-27 7:42 ` [PATCH v7 26/34] pinctrl: airoha: an7583: add support for pon_alt pinmux Mikhail Kshevetskiy
2026-07-27 7:42 ` [PATCH v7 27/34] dt-bindings: pinctrl: airoha: an7583: add pon_alt pin group Mikhail Kshevetskiy
2026-07-27 7:42 ` [PATCH v7 28/34] pinctrl: airoha: an7583: add support for olt pinmux Mikhail Kshevetskiy
2026-07-27 7:42 ` [PATCH v7 29/34] dt-bindings: pinctrl: airoha: an7583: add olt function/group Mikhail Kshevetskiy
2026-07-27 7:42 ` [PATCH v7 30/34] pinctrl: airoha: add support of en7523 SoC Mikhail Kshevetskiy
2026-07-27 7:42 ` [PATCH v7 31/34] pinctrl: airoha: try to find chip scu node by phandle first Mikhail Kshevetskiy
2026-07-27 7:42 ` [PATCH v7 32/34] dt-bindings: pinctrl: airoha: add support of en7523 pin controller Mikhail Kshevetskiy
2026-07-27 7:42 ` [PATCH v7 33/34] pinctrl: airoha: add support of an7563 SoC Mikhail Kshevetskiy
2026-07-27 7:42 ` [PATCH v7 34/34] dt-bindings: pinctrl: airoha: add support of an7563 pin controller Mikhail Kshevetskiy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d71b9758-b8b8-463e-8da2-a91d1e98759a@iopsys.eu \
--to=mikhail.kshevetskiy@iopsys.eu \
--cc=angelogioacchino.delregno@collabora.com \
--cc=ansuelsmth@gmail.com \
--cc=benjamin.larsson@genexis.eu \
--cc=brgl@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linusw@kernel.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=lorenzo@kernel.org \
--cc=markus.gothe@genexis.eu \
--cc=robh@kernel.org \
--cc=srherobrine20@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®