* [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 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
0 siblings, 2 replies; 5+ 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] 5+ 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 @ 2026-11-19 15:30 ` Lee Jones 2026-11-19 17:30 ` Andy Shevchenko 2026-11-19 15:30 ` [PATCH 08/10] iio: adc: qcom-spmi-adc5-gen3: Reject empty reg property in probe Lee Jones 1 sibling, 1 reply; 5+ 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] 5+ messages in thread
* Re: [PATCH 07/10] iio: adc: qcom-spmi-adc5-gen3: Free TM auxiliary device wrapper in release callback 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 17:30 ` Andy Shevchenko 0 siblings, 0 replies; 5+ messages in thread From: Andy Shevchenko @ 2026-11-19 17:30 UTC (permalink / raw) To: Lee Jones Cc: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko, Jishnu Prakash, linux-arm-msm, linux-iio, linux-kernel, stable On Thu, Nov 19, 2026 at 03:30:40PM +0000, Lee Jones wrote: > 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(). ... > #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> > +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); container_of() is also in a separate header, id est container_of.h. > + kfree(aux_device); > +} ... > 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); Oh, this is interesting... Usually the release devm_*() calls point to a misdesign somewhere. But I haven't checked the twisted flow of this code. > 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; > + } -- With Best Regards, Andy Shevchenko ^ permalink raw reply [flat|nested] 5+ 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 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 17:31 ` Andy Shevchenko 1 sibling, 1 reply; 5+ 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] 5+ messages in thread
* Re: [PATCH 08/10] iio: adc: qcom-spmi-adc5-gen3: Reject empty reg property in probe 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 17:31 ` Andy Shevchenko 0 siblings, 0 replies; 5+ messages in thread From: Andy Shevchenko @ 2026-11-19 17:31 UTC (permalink / raw) To: Lee Jones Cc: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko, Jishnu Prakash, linux-arm-msm, linux-iio, linux-kernel, stable On Thu, Nov 19, 2026 at 03:30:41PM +0000, Lee Jones wrote: > 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. ENOENT is usually used for that. -- With Best Regards, Andy Shevchenko ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-19 17:34 UTC | newest] Thread overview: 5+ 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 07/10] iio: adc: qcom-spmi-adc5-gen3: Free TM auxiliary device wrapper in release callback Lee Jones 2026-11-19 17:30 ` Andy Shevchenko 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 17:31 ` Andy Shevchenko
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).