* [PATCH 04/10] iio: adc: stm32-adc: Validate channel index before writing chan_name
2026-11-19 15:30 [PATCH 00/10] iio: Fix memory corruption, teardown races and bounds checks Lee Jones
@ 2026-11-19 15:30 ` Lee Jones
2026-11-19 15:30 ` [PATCH 05/10] iio: adc: stm32-adc: Detach chained IRQ handler before removing domain Lee Jones
1 sibling, 0 replies; 3+ messages in thread
From: Lee Jones @ 2026-11-19 15:30 UTC (permalink / raw)
To: lee, Jonathan Cameron, David Lechner, Nuno Sá,
Andy Shevchenko, Maxime Coquelin, Alexandre Torgue,
Fabrice Gasnier, Olivier Moysan, linux-iio, linux-stm32,
linux-arm-kernel
Cc: linux-kernel, stable
stm32_adc_generic_chan_init() reads the child node's reg property into a
signed int and, when the optional label property is present, writes into
adc->chan_name[val] and calls stm32_adc_populate_int_ch() before
checking whether val exceeds adc_info->max_channels. Because val is
signed, values with the top bit set also become negative and bypass the
upper-bound check altogether.
Store val as a u32, matching fwnode_property_read_u32(), and move the
max_channels bounds check immediately after reading reg.
Fixes: 95bc818404b2 ("iio: adc: stm32-adc: add support of generic channels binding")
Closes: https://sashiko.dev/#/bug/linux-efd2944a-ec30-488d-b2ac-1c7feb831095
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/iio/adc/stm32-adc.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/drivers/iio/adc/stm32-adc.c b/drivers/iio/adc/stm32-adc.c
index ab99116aea0a..42f1fc64250a 100644
--- a/drivers/iio/adc/stm32-adc.c
+++ b/drivers/iio/adc/stm32-adc.c
@@ -2745,9 +2745,9 @@ static int stm32_adc_generic_chan_init(struct iio_dev *indio_dev,
const struct stm32_adc_info *adc_info = adc->cfg->adc_info;
struct device *dev = &indio_dev->dev;
const char *name;
- int val, scan_index = 0, ret;
+ int scan_index = 0, ret;
bool differential;
- u32 vin[2];
+ u32 val, vin[2];
device_for_each_child_node_scoped(dev, child) {
ret = fwnode_property_read_u32(child, "reg", &val);
@@ -2755,6 +2755,10 @@ static int stm32_adc_generic_chan_init(struct iio_dev *indio_dev,
return dev_err_probe(dev, ret,
"Missing channel index\n");
+ if (val >= adc_info->max_channels)
+ return dev_err_probe(dev, -EINVAL,
+ "Invalid channel %u\n", val);
+
ret = fwnode_property_read_string(child, "label", &name);
/* label is optional */
if (!ret) {
@@ -2773,10 +2777,6 @@ static int stm32_adc_generic_chan_init(struct iio_dev *indio_dev,
return dev_err_probe(dev, ret, "Invalid label\n");
}
- if (val >= adc_info->max_channels)
- return dev_err_probe(dev, -EINVAL,
- "Invalid channel %d\n", val);
-
differential = false;
ret = fwnode_property_read_u32_array(child, "diff-channels", vin, 2);
/* diff-channels is optional */
--
2.56.1.708.g77570a6a1d-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread* [PATCH 05/10] iio: adc: stm32-adc: Detach chained IRQ handler before removing domain
2026-11-19 15:30 [PATCH 00/10] iio: Fix memory corruption, teardown races and bounds checks Lee Jones
2026-11-19 15:30 ` [PATCH 04/10] iio: adc: stm32-adc: Validate channel index before writing chan_name Lee Jones
@ 2026-11-19 15:30 ` Lee Jones
1 sibling, 0 replies; 3+ messages in thread
From: Lee Jones @ 2026-11-19 15:30 UTC (permalink / raw)
To: lee, Jonathan Cameron, David Lechner, Nuno Sá,
Andy Shevchenko, Maxime Coquelin, Alexandre Torgue,
Fabrice Gasnier, linux-iio, linux-stm32, linux-arm-kernel
Cc: linux-kernel, stable
stm32_adc_irq_remove() disposes of the child IRQ mappings and removes
priv->domain before clearing the parent chained IRQ handlers. Because
the parent hardware interrupt lines remain unmasked while child devices
use dummy_irq_chip, an interrupt arriving during teardown invokes
stm32_adc_irq_handler() after irq_domain_remove() has freed
priv->domain, and irq_set_chained_handler() also leaves handler_data
dangling.
Detach the chained handlers and clear handler_data with
irq_set_chained_handler_and_data() before tearing down the mappings and
removing the domain.
Fixes: 1add69880240 ("iio: adc: Add support for STM32 ADC core")
Closes: https://sashiko.dev/#/bug/linux-27c38690-bc20-43aa-a3fc-1ddd6f1bb74e
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/iio/adc/stm32-adc-core.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/iio/adc/stm32-adc-core.c b/drivers/iio/adc/stm32-adc-core.c
index 4b532db3db62..13b75475046c 100644
--- a/drivers/iio/adc/stm32-adc-core.c
+++ b/drivers/iio/adc/stm32-adc-core.c
@@ -467,12 +467,12 @@ static void stm32_adc_irq_remove(struct platform_device *pdev,
int hwirq;
unsigned int i;
+ for (i = 0; i < priv->nb_irqs; i++)
+ irq_set_chained_handler_and_data(priv->irq[i], NULL, NULL);
+
for (hwirq = 0; hwirq < priv->nb_adc_max; hwirq++)
irq_dispose_mapping(irq_find_mapping(priv->domain, hwirq));
irq_domain_remove(priv->domain);
-
- for (i = 0; i < priv->nb_irqs; i++)
- irq_set_chained_handler(priv->irq[i], NULL);
}
static int stm32_adc_core_switches_supply_en(struct stm32_adc_priv *priv,
--
2.56.1.708.g77570a6a1d-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread