* [PATCH 00/10] iio: Fix memory corruption, teardown races and bounds checks
@ 2026-11-19 15:30 Lee Jones
2026-11-19 15:30 ` [PATCH 01/10] iio: imu: adis: Clear pointers after freeing in adis_update_scan_mode() Lee Jones
` (9 more replies)
0 siblings, 10 replies; 11+ messages in thread
From: Lee Jones @ 2026-11-19 15:30 UTC (permalink / raw)
To: lee
Cc: linux-kernel, Alexandre Torgue, Alexandru Ardelean,
Andy Shevchenko, Bogdan Bolocan, David Lechner, Fabrice Gasnier,
Jishnu Prakash, Joe Sandom, Jonathan Cameron, Lars-Peter Clausen,
linux, linux-arm-kernel, linux-arm-msm, linux-iio, linux-stm32,
Lothar Rubusch, Lucas Stankus, Marius Cristea, Mathieu Othacehe,
Maxime Coquelin, Michael Hennerich, Nuno Sá, Olivier Moysan
These issues were reported by Sashiko.
Cc: Alexandre Torgue <alexandre.torgue@foss.st.com>
Cc: Alexandru Ardelean <ardeleanalex@gmail.com>
Cc: Andy Shevchenko <andy@kernel.org>
Cc: Bogdan Bolocan <bogdan.bolocan@microchip.com>
Cc: David Lechner <dlechner@baylibre.com>
Cc: Fabrice Gasnier <fabrice.gasnier@foss.st.com>
Cc: Jishnu Prakash <jishnu.prakash@oss.qualcomm.com>
Cc: Joe Sandom <joe.g.sandom@gmail.com>
Cc: Jonathan Cameron <jic23@kernel.org>
Cc: Lars-Peter Clausen <lars@metafoo.de>
Cc: linux@analog.com
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-arm-msm@vger.kernel.org
Cc: linux-iio@vger.kernel.org
Cc: linux-stm32@st-md-mailman.stormreply.com
Cc: Lothar Rubusch <l.rubusch@gmail.com>
Cc: Lucas Stankus <lucas.p.stankus@gmail.com>
Cc: Marius Cristea <marius.cristea@microchip.com>
Cc: Mathieu Othacehe <othacehe@gnu.org>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Michael Hennerich <Michael.Hennerich@analog.com>
Cc: "Nuno Sá" <nuno.sa@analog.com>
Cc: Olivier Moysan <olivier.moysan@foss.st.com>
Lee Jones (10):
iio: imu: adis: Clear pointers after freeing in
adis_update_scan_mode()
iio: accel: adxl313: Prevent FIFO buffer overflow in
adxl313_fifo_transfer()
iio: accel: adxl313: Reject sub-base ODR codes in adxl313_read_raw()
iio: adc: stm32-adc: Validate channel index before writing chan_name
iio: adc: stm32-adc: Detach chained IRQ handler before removing domain
iio: adc: pac1934: Fix custom attribute allocation and channel bounds
iio: adc: qcom-spmi-adc5-gen3: Free TM auxiliary device wrapper in
release callback
iio: adc: qcom-spmi-adc5-gen3: Reject empty reg property in probe
iio: proximity: isl29501: Fix division by zero and overflow in
isl29501_set_freq()
iio: light: tsl2591: Prevent infinite recursion on threshold
boundaries
drivers/iio/accel/adxl313.h | 2 +-
drivers/iio/accel/adxl313_core.c | 13 +++++++++--
drivers/iio/adc/pac1934.c | 33 ++++++++++++---------------
drivers/iio/adc/qcom-spmi-adc5-gen3.c | 32 +++++++++++++++++++++-----
drivers/iio/adc/stm32-adc-core.c | 6 ++---
drivers/iio/adc/stm32-adc.c | 12 +++++-----
drivers/iio/imu/adis_buffer.c | 2 ++
drivers/iio/light/tsl2591.c | 25 ++++++++++++--------
drivers/iio/proximity/isl29501.c | 10 ++++++--
9 files changed, 87 insertions(+), 48 deletions(-)
--
2.56.1.708.g77570a6a1d-goog
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 01/10] iio: imu: adis: Clear pointers after freeing in adis_update_scan_mode()
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 02/10] iio: accel: adxl313: Prevent FIFO buffer overflow in adxl313_fifo_transfer() Lee Jones
` (8 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Lee Jones @ 2026-11-19 15:30 UTC (permalink / raw)
To: lee, Nuno Sa, Michael Hennerich, Jonathan Cameron, David Lechner,
Andy Shevchenko, Lars-Peter Clausen, linux-iio, linux
Cc: linux-kernel, stable
adis_update_scan_mode() frees both adis->xfer and adis->buffer at the
start of a scan mode update without clearing either pointer to NULL.
In both adis_update_scan_mode_burst() and the non-burst path, adis->xfer
is allocated before adis->buffer. If the adis->xfer allocation fails,
the function returns -ENOMEM while adis->buffer still holds the freed
pointer from the previous scan configuration, causing a double-free on
the next scan mode update or during device teardown in
adis_buffer_cleanup().
Clear both pointers immediately after freeing them.
Fixes: aacff892cbd5 ("staging:iio:adis: Preallocate transfer message")
Closes: https://sashiko.dev/#/bug/linux-966f0cd4-488a-4d69-b8a5-449c751365d2
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/iio/imu/adis_buffer.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/iio/imu/adis_buffer.c b/drivers/iio/imu/adis_buffer.c
index 501da4eaef69..9d317b627eba 100644
--- a/drivers/iio/imu/adis_buffer.c
+++ b/drivers/iio/imu/adis_buffer.c
@@ -74,7 +74,9 @@ int adis_update_scan_mode(struct iio_dev *indio_dev,
__be16 *tx, *rx;
kfree(adis->xfer);
+ adis->xfer = NULL;
kfree(adis->buffer);
+ adis->buffer = NULL;
if (adis->data->burst_len)
return adis_update_scan_mode_burst(indio_dev, scan_mask);
--
2.56.1.708.g77570a6a1d-goog
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 02/10] iio: accel: adxl313: Prevent FIFO buffer overflow in adxl313_fifo_transfer()
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 01/10] iio: imu: adis: Clear pointers after freeing in adis_update_scan_mode() Lee Jones
@ 2026-11-19 15:30 ` Lee Jones
2026-11-19 15:30 ` [PATCH 03/10] iio: accel: adxl313: Reject sub-base ODR codes in adxl313_read_raw() Lee Jones
` (7 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Lee Jones @ 2026-11-19 15:30 UTC (permalink / raw)
To: lee, Lucas Stankus, Nuno Sá, Michael Hennerich,
Jonathan Cameron, David Lechner, Andy Shevchenko, Lothar Rubusch,
linux, linux-iio
Cc: linux-kernel, stable
The ADXL313 32-entry FIFO plus one sample held in the output filter can
yield up to 33 3-axis samples (ADXL313_FIFO_SIZE + 1). Because of
missing parentheses in ADXL313_NUM_AXIS * ADXL313_FIFO_SIZE + 1,
fifo_buf is sized at 97 16-bit elements instead of 99, overflowing the
buffer by four bytes whenever all 33 entries are read.
In addition, adxl313_get_samples() returns the 6-bit FIFO_STATUS entries
field (0..63) without bounds checking, allowing a malfunctioning or
spoofed bus device to overflow fifo_buf on the heap in
adxl313_fifo_transfer().
Parenthesise (ADXL313_FIFO_SIZE + 1) when sizing fifo_buf and reject
entry counts exceeding ADXL313_FIFO_SIZE + 1 in adxl313_get_samples().
Fixes: ff8093fa6ba4 ("iio: accel: adxl313: add buffered FIFO watermark with interrupt handling")
Closes: https://sashiko.dev/#/bug/linux-6baeb7fe-ad68-4961-b5f9-5f0c7628df1e
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/iio/accel/adxl313.h | 2 +-
drivers/iio/accel/adxl313_core.c | 7 ++++++-
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/accel/adxl313.h b/drivers/iio/accel/adxl313.h
index 75ef54b60f75..de0bccfcdd0a 100644
--- a/drivers/iio/accel/adxl313.h
+++ b/drivers/iio/accel/adxl313.h
@@ -93,7 +93,7 @@ struct adxl313_data {
struct mutex lock; /* lock to protect transf_buf */
u8 watermark;
__le16 transf_buf __aligned(IIO_DMA_MINALIGN);
- __le16 fifo_buf[ADXL313_NUM_AXIS * ADXL313_FIFO_SIZE + 1];
+ __le16 fifo_buf[ADXL313_NUM_AXIS * (ADXL313_FIFO_SIZE + 1)];
};
struct adxl313_chip_info {
diff --git a/drivers/iio/accel/adxl313_core.c b/drivers/iio/accel/adxl313_core.c
index 6dc918c4ae17..72ef8652d398 100644
--- a/drivers/iio/accel/adxl313_core.c
+++ b/drivers/iio/accel/adxl313_core.c
@@ -921,7 +921,12 @@ static int adxl313_get_samples(struct adxl313_data *data)
if (ret)
return ret;
- return FIELD_GET(ADXL313_REG_FIFO_STATUS_ENTRIES_MSK, regval);
+ /* 32 FIFO entries plus 1 entry at the output filter */
+ ret = FIELD_GET(ADXL313_REG_FIFO_STATUS_ENTRIES_MSK, regval);
+ if (ret > ADXL313_FIFO_SIZE + 1)
+ return -EINVAL;
+
+ return ret;
}
static int adxl313_fifo_transfer(struct adxl313_data *data, int samples)
--
2.56.1.708.g77570a6a1d-goog
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 03/10] iio: accel: adxl313: Reject sub-base ODR codes in adxl313_read_raw()
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 01/10] iio: imu: adis: Clear pointers after freeing in adis_update_scan_mode() Lee Jones
2026-11-19 15:30 ` [PATCH 02/10] iio: accel: adxl313: Prevent FIFO buffer overflow in adxl313_fifo_transfer() Lee Jones
@ 2026-11-19 15:30 ` Lee Jones
2026-11-19 15:30 ` [PATCH 04/10] iio: adc: stm32-adc: Validate channel index before writing chan_name Lee Jones
` (6 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Lee Jones @ 2026-11-19 15:30 UTC (permalink / raw)
To: lee, Lucas Stankus, Nuno Sá, Michael Hennerich,
Jonathan Cameron, David Lechner, Andy Shevchenko,
Alexandru Ardelean, linux, linux-iio
Cc: linux-kernel, stable
When reading IIO_CHAN_INFO_SAMP_FREQ, adxl313_read_raw() extracts the
4-bit rate field (0..15) from ADXL313_REG_BW_RATE and subtracts
ADXL313_RATE_BASE (6) to index adxl313_odr_freqs[].
ADXL312 and ADXL314 support sub-6.25 Hz rate codes 0..5 and do not
perform a soft reset during setup, and debugfs register writes or a
faulty bus read can likewise yield codes below ADXL313_RATE_BASE. When
that happens, subtracting ADXL313_RATE_BASE produces a negative index
and reads before the start of adxl313_odr_freqs[].
Return -EINVAL if the rate field is below ADXL313_RATE_BASE.
Fixes: 636d44633039 ("iio: accel: Add driver support for ADXL313")
Closes: https://sashiko.dev/#/bug/linux-d6086ee0-d732-43b6-b8ac-24e5bf86a9f8
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/iio/accel/adxl313_core.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/iio/accel/adxl313_core.c b/drivers/iio/accel/adxl313_core.c
index 72ef8652d398..811218953c2a 100644
--- a/drivers/iio/accel/adxl313_core.c
+++ b/drivers/iio/accel/adxl313_core.c
@@ -647,7 +647,11 @@ static int adxl313_read_raw(struct iio_dev *indio_dev,
if (ret)
return ret;
- ret = FIELD_GET(ADXL313_RATE_MSK, regval) - ADXL313_RATE_BASE;
+ regval = FIELD_GET(ADXL313_RATE_MSK, regval);
+ if (regval < ADXL313_RATE_BASE)
+ return -EINVAL;
+
+ ret = regval - ADXL313_RATE_BASE;
*val = adxl313_odr_freqs[ret][0];
*val2 = adxl313_odr_freqs[ret][1];
return IIO_VAL_INT_PLUS_MICRO;
--
2.56.1.708.g77570a6a1d-goog
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [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
` (2 preceding siblings ...)
2026-11-19 15:30 ` [PATCH 03/10] iio: accel: adxl313: Reject sub-base ODR codes in adxl313_read_raw() 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
` (5 subsequent siblings)
9 siblings, 0 replies; 11+ 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] 11+ 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
` (3 preceding siblings ...)
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
2026-11-19 15:30 ` [PATCH 06/10] iio: adc: pac1934: Fix custom attribute allocation and channel bounds Lee Jones
` (4 subsequent siblings)
9 siblings, 0 replies; 11+ 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] 11+ messages in thread
* [PATCH 06/10] iio: adc: pac1934: Fix custom attribute allocation and channel bounds
2026-11-19 15:30 [PATCH 00/10] iio: Fix memory corruption, teardown races and bounds checks Lee Jones
` (4 preceding siblings ...)
2026-11-19 15:30 ` [PATCH 05/10] iio: adc: stm32-adc: Detach chained IRQ handler before removing domain Lee Jones
@ 2026-11-19 15:30 ` Lee Jones
2026-11-19 15:30 ` [PATCH 07/10] iio: adc: qcom-spmi-adc5-gen3: Free TM auxiliary device wrapper in release callback Lee Jones
` (3 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Lee Jones @ 2026-11-19 15:30 UTC (permalink / raw)
To: lee, Marius Cristea, Jonathan Cameron, David Lechner,
Nuno Sá, Andy Shevchenko, Bogdan Bolocan, linux-iio
Cc: linux-kernel, stable
pac1934_prep_custom_attributes() sizes the pac1934_custom_attr pointer
array using sizeof(*pac1934_group) instead of
sizeof(*pac1934_custom_attr) and adds 1 byte rather than one pointer
element for the terminating NULL entry. When active_channels_count is
zero, only a single byte is allocated and iio_device_register_sysfs()
reads past the allocation when scanning the attribute list.
In addition, active_channels_count is counted over info->phys_channels,
whereas the population steps unconditionally inspect all four entries of
info->active_channels[], which can write past the end of the array on
1-, 2-, and 3-channel chip variants.
Allocate active_channels_count + 1 attribute pointers with
devm_kzalloc_objs() and bound the population loop by
info->phys_channels.
Fixes: 0fb528c8255b ("iio: adc: adding support for PAC193x")
Closes: https://sashiko.dev/#/bug/linux-e7b7eab1-9ed4-4d4b-b9c7-889bf720aa5b
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/iio/adc/pac1934.c | 33 +++++++++++++++------------------
1 file changed, 15 insertions(+), 18 deletions(-)
diff --git a/drivers/iio/adc/pac1934.c b/drivers/iio/adc/pac1934.c
index 1d7608e8246a..c3da0c519456 100644
--- a/drivers/iio/adc/pac1934.c
+++ b/drivers/iio/adc/pac1934.c
@@ -1435,10 +1435,17 @@ static IIO_DEVICE_ATTR(in_shunt_resistor3, 0644,
static IIO_DEVICE_ATTR(in_shunt_resistor4, 0644,
pac1934_shunt_value_show, pac1934_shunt_value_store, 3);
+static struct attribute * const pac1934_shunt_attrs[] = {
+ PAC1934_DEV_ATTR(in_shunt_resistor1),
+ PAC1934_DEV_ATTR(in_shunt_resistor2),
+ PAC1934_DEV_ATTR(in_shunt_resistor3),
+ PAC1934_DEV_ATTR(in_shunt_resistor4),
+};
+
static int pac1934_prep_custom_attributes(struct pac1934_chip_info *info,
struct iio_dev *indio_dev)
{
- int i, active_channels_count = 0;
+ int i, j, active_channels_count = 0;
struct attribute **pac1934_custom_attr;
struct attribute_group *pac1934_group;
struct device *dev = &info->client->dev;
@@ -1451,26 +1458,16 @@ static int pac1934_prep_custom_attributes(struct pac1934_chip_info *info,
if (!pac1934_group)
return -ENOMEM;
- pac1934_custom_attr = devm_kzalloc(dev,
- (PAC1934_CUSTOM_ATTR_FOR_CHANNEL *
- active_channels_count)
- * sizeof(*pac1934_group) + 1,
- GFP_KERNEL);
+ pac1934_custom_attr = devm_kzalloc_objs(dev, *pac1934_custom_attr,
+ PAC1934_CUSTOM_ATTR_FOR_CHANNEL *
+ active_channels_count + 1);
if (!pac1934_custom_attr)
return -ENOMEM;
- i = 0;
- if (info->active_channels[0])
- pac1934_custom_attr[i++] = PAC1934_DEV_ATTR(in_shunt_resistor1);
-
- if (info->active_channels[1])
- pac1934_custom_attr[i++] = PAC1934_DEV_ATTR(in_shunt_resistor2);
-
- if (info->active_channels[2])
- pac1934_custom_attr[i++] = PAC1934_DEV_ATTR(in_shunt_resistor3);
-
- if (info->active_channels[3])
- pac1934_custom_attr[i] = PAC1934_DEV_ATTR(in_shunt_resistor4);
+ j = 0;
+ for (i = 0; i < info->phys_channels; i++)
+ if (info->active_channels[i])
+ pac1934_custom_attr[j++] = pac1934_shunt_attrs[i];
pac1934_group->attrs = pac1934_custom_attr;
info->iio_info.attrs = pac1934_group;
--
2.56.1.708.g77570a6a1d-goog
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 07/10] iio: adc: qcom-spmi-adc5-gen3: Free TM auxiliary device wrapper in release callback
2026-11-19 15:30 [PATCH 00/10] iio: Fix memory corruption, teardown races and bounds checks Lee Jones
` (5 preceding siblings ...)
2026-11-19 15:30 ` [PATCH 06/10] iio: adc: pac1934: Fix custom attribute allocation and channel bounds Lee Jones
@ 2026-11-19 15:30 ` Lee Jones
2026-11-19 15:30 ` [PATCH 08/10] iio: adc: qcom-spmi-adc5-gen3: Reject empty reg property in probe Lee Jones
` (2 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Lee Jones @ 2026-11-19 15:30 UTC (permalink / raw)
To: lee, Jonathan Cameron, David Lechner, Nuno Sá,
Andy Shevchenko, Jishnu Prakash, linux-arm-msm, linux-iio
Cc: linux-kernel, stable
struct tm5_aux_dev_wrapper embeds a reference-counted struct
auxiliary_device, whose memory must be released from its dev.release
callback once the final device reference is dropped.
Allocating the wrapper with devm_kzalloc_obj() on the parent ADC device
and providing an empty adc5_gen3_aux_device_release() causes parent
devres teardown to free the wrapper immediately after
auxiliary_device_uninit(), even if external references to the embedded
struct device are still held.
Allocate the wrapper with kzalloc_obj(), release it from
adc5_gen3_aux_device_release(), and unwind cleanly on early error paths
in adc5_gen3_add_aux_tm_device().
Fixes: baff45179e90 ("iio: adc: Add support for QCOM PMIC5 Gen3 ADC")
Closes: https://sashiko.dev/#/bug/linux-b738d116-f32b-4edf-aa73-77827b79a407
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/iio/adc/qcom-spmi-adc5-gen3.c | 30 +++++++++++++++++++++------
1 file changed, 24 insertions(+), 6 deletions(-)
diff --git a/drivers/iio/adc/qcom-spmi-adc5-gen3.c b/drivers/iio/adc/qcom-spmi-adc5-gen3.c
index 351c4fff17b4..52f039795418 100644
--- a/drivers/iio/adc/qcom-spmi-adc5-gen3.c
+++ b/drivers/iio/adc/qcom-spmi-adc5-gen3.c
@@ -24,6 +24,7 @@
#include <linux/platform_device.h>
#include <linux/property.h>
#include <linux/regmap.h>
+#include <linux/slab.h>
#include <linux/types.h>
#include <linux/unaligned.h>
@@ -607,14 +608,20 @@ static void adc5_gen3_delete_aux(void *data)
auxiliary_device_delete(data);
}
-static void adc5_gen3_aux_device_release(struct device *dev) {}
+static void adc5_gen3_aux_device_release(struct device *dev)
+{
+ struct tm5_aux_dev_wrapper *aux_device =
+ container_of(dev, struct tm5_aux_dev_wrapper, aux_dev.dev);
+
+ kfree(aux_device);
+}
static int adc5_gen3_add_aux_tm_device(struct adc5_chip *adc, int id)
{
struct tm5_aux_dev_wrapper *aux_device;
int i, ret, i_tm = 0;
- aux_device = devm_kzalloc_obj(adc->dev, *aux_device);
+ aux_device = kzalloc_obj(*aux_device);
if (!aux_device)
return -ENOMEM;
@@ -626,8 +633,10 @@ static int adc5_gen3_add_aux_tm_device(struct adc5_chip *adc, int id)
aux_device->tm_props = devm_kzalloc_objs(adc->dev,
*aux_device->tm_props,
adc->n_tm_channels);
- if (!aux_device->tm_props)
+ if (!aux_device->tm_props) {
+ kfree(aux_device);
return -ENOMEM;
+ }
aux_device->dev_data = &adc->dev_data;
@@ -643,8 +652,10 @@ static int adc5_gen3_add_aux_tm_device(struct adc5_chip *adc, int id)
aux_device->n_tm_channels = adc->n_tm_channels;
ret = auxiliary_device_init(&aux_device->aux_dev);
- if (ret)
+ if (ret) {
+ kfree(aux_device);
return ret;
+ }
ret = devm_add_action_or_reset(adc->dev, adc5_gen3_uninit_aux,
&aux_device->aux_dev);
@@ -652,12 +663,19 @@ static int adc5_gen3_add_aux_tm_device(struct adc5_chip *adc, int id)
return ret;
ret = auxiliary_device_add(&aux_device->aux_dev);
- if (ret)
+ if (ret) {
+ devm_release_action(adc->dev, adc5_gen3_uninit_aux,
+ &aux_device->aux_dev);
return ret;
+ }
+
ret = devm_add_action_or_reset(adc->dev, adc5_gen3_delete_aux,
&aux_device->aux_dev);
- if (ret)
+ if (ret) {
+ devm_release_action(adc->dev, adc5_gen3_uninit_aux,
+ &aux_device->aux_dev);
return ret;
+ }
return 0;
}
--
2.56.1.708.g77570a6a1d-goog
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 08/10] iio: adc: qcom-spmi-adc5-gen3: Reject empty reg property in probe
2026-11-19 15:30 [PATCH 00/10] iio: Fix memory corruption, teardown races and bounds checks Lee Jones
` (6 preceding siblings ...)
2026-11-19 15:30 ` [PATCH 07/10] iio: adc: qcom-spmi-adc5-gen3: Free TM auxiliary device wrapper in release callback Lee Jones
@ 2026-11-19 15:30 ` Lee Jones
2026-11-19 15:30 ` [PATCH 09/10] iio: proximity: isl29501: Fix division by zero and overflow in isl29501_set_freq() Lee Jones
2026-11-19 15:30 ` [PATCH 10/10] iio: light: tsl2591: Prevent infinite recursion on threshold boundaries Lee Jones
9 siblings, 0 replies; 11+ messages in thread
From: Lee Jones @ 2026-11-19 15:30 UTC (permalink / raw)
To: lee, Jonathan Cameron, David Lechner, Nuno Sá,
Andy Shevchenko, Jishnu Prakash, linux-arm-msm, linux-iio
Cc: linux-kernel, stable
If a firmware node supplies an empty reg property,
device_property_count_u32() returns 0, which passes the negative error
check in adc5_gen3_probe() and leaves num_sdams set to 0. Subsequent
zero-length allocations return ZERO_SIZE_PTR, which is then dereferenced
when requesting the VADC SDAM interrupt, and num_sdams * 8 - 1 wraps in
unsigned comparisons when counting TM channels.
Return -EINVAL when device_property_count_u32() reports zero elements.
Fixes: baff45179e90 ("iio: adc: Add support for QCOM PMIC5 Gen3 ADC")
Closes: https://sashiko.dev/#/bug/linux-d8ad5868-82f5-4c97-bc67-84ceebb10a1a
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/iio/adc/qcom-spmi-adc5-gen3.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/iio/adc/qcom-spmi-adc5-gen3.c b/drivers/iio/adc/qcom-spmi-adc5-gen3.c
index 52f039795418..9102346feea9 100644
--- a/drivers/iio/adc/qcom-spmi-adc5-gen3.c
+++ b/drivers/iio/adc/qcom-spmi-adc5-gen3.c
@@ -756,6 +756,8 @@ static int adc5_gen3_probe(struct platform_device *pdev)
ret = device_property_count_u32(dev, "reg");
if (ret < 0)
return ret;
+ if (!ret)
+ return -EINVAL;
adc->dev_data.num_sdams = ret;
--
2.56.1.708.g77570a6a1d-goog
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 09/10] iio: proximity: isl29501: Fix division by zero and overflow in isl29501_set_freq()
2026-11-19 15:30 [PATCH 00/10] iio: Fix memory corruption, teardown races and bounds checks Lee Jones
` (7 preceding siblings ...)
2026-11-19 15:30 ` [PATCH 08/10] iio: adc: qcom-spmi-adc5-gen3: Reject empty reg property in probe Lee Jones
@ 2026-11-19 15:30 ` Lee Jones
2026-11-19 15:30 ` [PATCH 10/10] iio: light: tsl2591: Prevent infinite recursion on threshold boundaries Lee Jones
9 siblings, 0 replies; 11+ messages in thread
From: Lee Jones @ 2026-11-19 15:30 UTC (permalink / raw)
To: lee, Jonathan Cameron, David Lechner, Nuno Sá,
Andy Shevchenko, Mathieu Othacehe, linux-iio
Cc: linux-kernel, stable
isl29501_set_freq() computes freq = val * 1000000 + val2 % 1000000 in a
signed 32-bit int and passes it directly to do_div() without checking
for zero or negative inputs. Writing 0 to the sampling_frequency
attribute triggers a division by zero in the kernel, while valid
frequencies above 2147 Hz up to the sensor's 2222 Hz limit overflow
signed int.
Validate that val and val2 are non-negative, compute freq as an unsigned
int within [1, 2222000000], and return -ERANGE otherwise.
Fixes: 1c28799257bc ("iio: light: isl29501: Add support for the ISL29501 ToF sensor.")
Closes: https://sashiko.dev/#/bug/linux-e4bc1c30-bbf1-458a-99f9-a36e949af67c
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/iio/proximity/isl29501.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/proximity/isl29501.c b/drivers/iio/proximity/isl29501.c
index b337ee530972..09575d890104 100644
--- a/drivers/iio/proximity/isl29501.c
+++ b/drivers/iio/proximity/isl29501.c
@@ -863,11 +863,17 @@ static int isl29501_set_calibbias(struct isl29501_private *isl29501,
static int isl29501_set_freq(struct isl29501_private *isl29501,
int val, int val2)
{
- int freq;
+ unsigned int freq;
unsigned long long sample_time;
+ if (val < 0 || val2 < 0 || val > 2222)
+ return -ERANGE;
+
/* sample_freq = 1 / (0.000450 * (sample_time + 1) * 10^-6) */
- freq = val * 1000000 + val2 % 1000000;
+ freq = val * 1000000U + val2 % 1000000U;
+ if (!freq || freq > 2222000000U)
+ return -ERANGE;
+
sample_time = 2222ULL * 1000000ULL;
do_div(sample_time, freq);
--
2.56.1.708.g77570a6a1d-goog
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 10/10] iio: light: tsl2591: Prevent infinite recursion on threshold boundaries
2026-11-19 15:30 [PATCH 00/10] iio: Fix memory corruption, teardown races and bounds checks Lee Jones
` (8 preceding siblings ...)
2026-11-19 15:30 ` [PATCH 09/10] iio: proximity: isl29501: Fix division by zero and overflow in isl29501_set_freq() Lee Jones
@ 2026-11-19 15:30 ` Lee Jones
9 siblings, 0 replies; 11+ messages in thread
From: Lee Jones @ 2026-11-19 15:30 UTC (permalink / raw)
To: lee, Jonathan Cameron, David Lechner, Nuno Sá,
Andy Shevchenko, Joe Sandom, linux-iio
Cc: linux-kernel, stable
tsl2591_set_als_lower_threshold() adjusts the upper threshold to
als_lower_threshold + 1 whenever the new lower threshold is greater than
or equal to the current upper threshold, and
tsl2591_set_als_upper_threshold() symmetrically adjusts the lower
threshold to als_upper_threshold - 1.
Writing 65535 (TSL2591_ALS_MAX_VALUE) to the falling threshold wraps the
16-bit addition to 0 and calls tsl2591_set_als_upper_threshold(chip, 0),
which then wraps 0 - 1 back to 65535 and calls
tsl2591_set_als_lower_threshold(chip, 65535) in an infinite mutual
recursion until the kernel stack overflows. Writing 0 to the rising
threshold triggers the same cycle whenever the lower threshold is
non-zero.
Reject als_lower_threshold == TSL2591_ALS_MAX_VALUE and
als_upper_threshold == 0 with -EINVAL, propagate errors from the
cross-calls, and only update chip->als_settings once the I2C writes
succeed.
Fixes: 2335f0d7c790 ("iio: light: Added AMS tsl2591 driver implementation")
Closes: https://sashiko.dev/#/bug/linux-29f0f993-c799-4717-9daa-d0ad367f4e6d
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/iio/light/tsl2591.c | 25 +++++++++++++++----------
1 file changed, 15 insertions(+), 10 deletions(-)
diff --git a/drivers/iio/light/tsl2591.c b/drivers/iio/light/tsl2591.c
index 8cfce720efb9..e0c2b67c7dd4 100644
--- a/drivers/iio/light/tsl2591.c
+++ b/drivers/iio/light/tsl2591.c
@@ -466,23 +466,25 @@ static int tsl2591_set_als_gain_int_time(struct tsl2591_chip *chip)
static int tsl2591_set_als_lower_threshold(struct tsl2591_chip *chip,
u16 als_lower_threshold)
{
- struct tsl2591_als_settings als_settings = chip->als_settings;
struct i2c_client *client = chip->client;
u16 als_upper_threshold;
u8 als_lower_l;
u8 als_lower_h;
int ret;
- chip->als_settings.als_lower_thresh = als_lower_threshold;
+ if (als_lower_threshold == TSL2591_ALS_MAX_VALUE)
+ return -EINVAL;
/*
* Lower threshold should not be greater or equal to upper.
* If this is the case, then assert upper threshold to new lower
* threshold + 1 to avoid ordering issues when setting thresholds.
*/
- if (als_lower_threshold >= als_settings.als_upper_thresh) {
+ if (als_lower_threshold >= chip->als_settings.als_upper_thresh) {
als_upper_threshold = als_lower_threshold + 1;
- tsl2591_set_als_upper_threshold(chip, als_upper_threshold);
+ ret = tsl2591_set_als_upper_threshold(chip, als_upper_threshold);
+ if (ret)
+ return ret;
}
als_lower_l = als_lower_threshold;
@@ -504,32 +506,33 @@ static int tsl2591_set_als_lower_threshold(struct tsl2591_chip *chip,
return ret;
}
+ chip->als_settings.als_lower_thresh = als_lower_threshold;
+
return 0;
}
static int tsl2591_set_als_upper_threshold(struct tsl2591_chip *chip,
u16 als_upper_threshold)
{
- struct tsl2591_als_settings als_settings = chip->als_settings;
struct i2c_client *client = chip->client;
u16 als_lower_threshold;
u8 als_upper_l;
u8 als_upper_h;
int ret;
- if (als_upper_threshold > TSL2591_ALS_MAX_VALUE)
+ if (!als_upper_threshold)
return -EINVAL;
- chip->als_settings.als_upper_thresh = als_upper_threshold;
-
/*
* Upper threshold should not be less than lower. If this
* is the case, then assert lower threshold to new upper
* threshold - 1 to avoid ordering issues when setting thresholds.
*/
- if (als_upper_threshold < als_settings.als_lower_thresh) {
+ if (als_upper_threshold < chip->als_settings.als_lower_thresh) {
als_lower_threshold = als_upper_threshold - 1;
- tsl2591_set_als_lower_threshold(chip, als_lower_threshold);
+ ret = tsl2591_set_als_lower_threshold(chip, als_lower_threshold);
+ if (ret)
+ return ret;
}
als_upper_l = als_upper_threshold;
@@ -551,6 +554,8 @@ static int tsl2591_set_als_upper_threshold(struct tsl2591_chip *chip,
return ret;
}
+ chip->als_settings.als_upper_thresh = als_upper_threshold;
+
return 0;
}
--
2.56.1.708.g77570a6a1d-goog
^ permalink raw reply related [flat|nested] 11+ messages in thread
end of thread, other threads:[~2026-11-19 15:33 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 01/10] iio: imu: adis: Clear pointers after freeing in adis_update_scan_mode() Lee Jones
2026-11-19 15:30 ` [PATCH 02/10] iio: accel: adxl313: Prevent FIFO buffer overflow in adxl313_fifo_transfer() Lee Jones
2026-11-19 15:30 ` [PATCH 03/10] iio: accel: adxl313: Reject sub-base ODR codes in adxl313_read_raw() 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 ` [PATCH 05/10] iio: adc: stm32-adc: Detach chained IRQ handler before removing domain Lee Jones
2026-11-19 15:30 ` [PATCH 06/10] iio: adc: pac1934: Fix custom attribute allocation and channel bounds Lee Jones
2026-11-19 15:30 ` [PATCH 07/10] iio: adc: qcom-spmi-adc5-gen3: Free TM auxiliary device wrapper in release callback Lee Jones
2026-11-19 15:30 ` [PATCH 08/10] iio: adc: qcom-spmi-adc5-gen3: Reject empty reg property in probe Lee Jones
2026-11-19 15:30 ` [PATCH 09/10] iio: proximity: isl29501: Fix division by zero and overflow in isl29501_set_freq() Lee Jones
2026-11-19 15:30 ` [PATCH 10/10] iio: light: tsl2591: Prevent infinite recursion on threshold boundaries Lee Jones
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox