Linux ARM-MSM sub-architecture
 help / color / mirror / Atom feed
* [PATCH v2 0/7] iio: Fix memory corruption, teardown races and bounds checks
@ 2026-11-23  7:50 Lee Jones
  2026-11-23  7:50 ` [PATCH v2 5/7] iio: adc: qcom-spmi-adc5-gen3: Free TM auxiliary device wrapper in release callback Lee Jones
  2026-11-23  7:50 ` [PATCH v2 6/7] iio: adc: qcom-spmi-adc5-gen3: Reject empty reg property in probe Lee Jones
  0 siblings, 2 replies; 3+ messages in thread
From: Lee Jones @ 2026-11-23  7:50 UTC (permalink / raw)
  To: lee
  Cc: linux-kernel, Alexandru Ardelean, Andy Shevchenko, Bogdan Bolocan,
	David Lechner, Jishnu Prakash, Jonathan Cameron,
	Lars-Peter Clausen, linux, linux-arm-msm, linux-iio,
	Lothar Rubusch, Lucas Stankus, Marius Cristea, Mathieu Othacehe,
	Michael Hennerich, Nuno Sá, Radu Sabau

These issues were reported by Sashiko.

None of these changes have been tested on physical hardware.

v1 => v2:
 - Drop the 3 patches already applied upstream (stm32-adc x2, tsl2591)
 - Rebase onto fixes-togreg
 - CC Radu Sabau on the adis patch (Jonathan)
 - adxl313: Return -EIO on excessive FIFO entry count and -ERANGE on
   sub-base ODR codes (Andy, Jonathan)
 - pac1934: Order local variables in reverse Christmas tree style and
   scope the loop index j to the for-loop (Andy, Jonathan)
 - qcom-spmi-adc5-gen3: Manage tm_props and the OF node reference via
   adc5_gen3_aux_device_release(), register auxiliary_device_destroy()
   with devm_add_action_or_reset(), and return -ENOENT on an empty reg
   property (Andy, Jonathan)
 - isl29501: Use HZ_PER_MHZ, group range checks by variable, and order
   local declarations in reverse Christmas tree style (Andy)

v1: https://lore.kernel.org/all/20261119153151.1397003-1-lee@kernel.org/

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: Jishnu Prakash <jishnu.prakash@oss.qualcomm.com>
Cc: Jonathan Cameron <jic23@kernel.org>
Cc: Lars-Peter Clausen <lars@metafoo.de>
Cc: linux@analog.com
Cc: linux-arm-msm@vger.kernel.org
Cc: linux-iio@vger.kernel.org
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: Michael Hennerich <Michael.Hennerich@analog.com>
Cc: Nuno Sá <nuno.sa@analog.com>
Cc: Radu Sabau <radu.sabau@analog.com>

Lee Jones (7):
  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: 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()

 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 | 59 +++++++++++++--------------
 drivers/iio/imu/adis_buffer.c         |  2 +
 drivers/iio/proximity/isl29501.c      | 13 ++++--
 6 files changed, 68 insertions(+), 54 deletions(-)

-- 
2.56.1.750.gf70dc682cf-goog


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v2 5/7] iio: adc: qcom-spmi-adc5-gen3: Free TM auxiliary device wrapper in release callback
  2026-11-23  7:50 [PATCH v2 0/7] iio: Fix memory corruption, teardown races and bounds checks Lee Jones
@ 2026-11-23  7:50 ` Lee Jones
  2026-11-23  7:50 ` [PATCH v2 6/7] iio: adc: qcom-spmi-adc5-gen3: Reject empty reg property in probe Lee Jones
  1 sibling, 0 replies; 3+ messages in thread
From: Lee Jones @ 2026-11-23  7:50 UTC (permalink / raw)
  To: lee, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Jishnu Prakash, linux-arm-msm, linux-iio,
	linux-kernel
  Cc: 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 and its tm_props array with parent-managed
devm_*() helpers and providing an empty adc5_gen3_aux_device_release()
causes parent devres teardown to free both allocations immediately when
the parent unbinds, even if external references to the embedded struct
device are still held.  It also leaks the OF node reference taken by
device_set_of_node_from_dev().

Allocate the wrapper and tm_props array without devm, release them
together with the OF node reference in adc5_gen3_aux_device_release(),
and register auxiliary_device_destroy() via devm_add_action_or_reset()
once the auxiliary device has been added.

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>
---

v1 => v2:
 - Allocate tm_props without devm and release it alongside the OF node
   reference in adc5_gen3_aux_device_release() (Jonathan)
 - Move auxiliary_device_init() earlier and register
   auxiliary_device_destroy() via devm_add_action_or_reset(), avoiding
   devm_release_action() (Andy, Jonathan)
 - Note: <linux/container_of.h> is already included

 drivers/iio/adc/qcom-spmi-adc5-gen3.c | 57 +++++++++++++--------------
 1 file changed, 27 insertions(+), 30 deletions(-)

diff --git a/drivers/iio/adc/qcom-spmi-adc5-gen3.c b/drivers/iio/adc/qcom-spmi-adc5-gen3.c
index a23eb5c9096d..85450aa37e65 100644
--- a/drivers/iio/adc/qcom-spmi-adc5-gen3.c
+++ b/drivers/iio/adc/qcom-spmi-adc5-gen3.c
@@ -21,9 +21,11 @@
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/mutex.h>
+#include <linux/of.h>
 #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>
 
@@ -598,24 +600,22 @@ static int adc5_get_fw_data(struct adc5_chip *adc)
 	return 0;
 }
 
-static void adc5_gen3_uninit_aux(void *data)
+static void adc5_gen3_aux_device_release(struct device *dev)
 {
-	auxiliary_device_uninit(data);
-}
+	struct tm5_aux_dev_wrapper *aux_device =
+		container_of(dev, struct tm5_aux_dev_wrapper, aux_dev.dev);
 
-static void adc5_gen3_delete_aux(void *data)
-{
-	auxiliary_device_delete(data);
+	of_node_put(dev->of_node);
+	kfree(aux_device->tm_props);
+	kfree(aux_device);
 }
 
-static void adc5_gen3_aux_device_release(struct device *dev) {}
-
 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(adc->dev, sizeof(*aux_device), GFP_KERNEL);
+	aux_device = kzalloc_obj(*aux_device);
 	if (!aux_device)
 		return -ENOMEM;
 
@@ -624,11 +624,20 @@ static int adc5_gen3_add_aux_tm_device(struct adc5_chip *adc, int id)
 	aux_device->aux_dev.dev.parent = adc->dev;
 	aux_device->aux_dev.dev.release = adc5_gen3_aux_device_release;
 
-	aux_device->tm_props = devm_kcalloc(adc->dev, adc->n_tm_channels,
-					    sizeof(*aux_device->tm_props),
-					    GFP_KERNEL);
-	if (!aux_device->tm_props)
+	ret = auxiliary_device_init(&aux_device->aux_dev);
+	if (ret) {
+		kfree(aux_device);
+		return ret;
+	}
+
+	device_set_of_node_from_dev(&aux_device->aux_dev.dev, adc->dev);
+
+	aux_device->tm_props = kzalloc_objs(*aux_device->tm_props,
+					    adc->n_tm_channels);
+	if (!aux_device->tm_props) {
+		auxiliary_device_uninit(&aux_device->aux_dev);
 		return -ENOMEM;
+	}
 
 	aux_device->dev_data = &adc->dev_data;
 
@@ -639,28 +648,16 @@ static int adc5_gen3_add_aux_tm_device(struct adc5_chip *adc, int id)
 		i_tm++;
 	}
 
-	device_set_of_node_from_dev(&aux_device->aux_dev.dev, adc->dev);
-
 	aux_device->n_tm_channels = adc->n_tm_channels;
 
-	ret = auxiliary_device_init(&aux_device->aux_dev);
-	if (ret)
-		return ret;
-
-	ret = devm_add_action_or_reset(adc->dev, adc5_gen3_uninit_aux,
-				       &aux_device->aux_dev);
-	if (ret)
-		return ret;
-
 	ret = auxiliary_device_add(&aux_device->aux_dev);
-	if (ret)
-		return ret;
-	ret = devm_add_action_or_reset(adc->dev, adc5_gen3_delete_aux,
-				       &aux_device->aux_dev);
-	if (ret)
+	if (ret) {
+		auxiliary_device_uninit(&aux_device->aux_dev);
 		return ret;
+	}
 
-	return 0;
+	return devm_add_action_or_reset(adc->dev, auxiliary_device_destroy,
+					&aux_device->aux_dev);
 }
 
 void adc5_gen3_mutex_lock(struct device *dev)
-- 
2.56.1.750.gf70dc682cf-goog


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH v2 6/7] iio: adc: qcom-spmi-adc5-gen3: Reject empty reg property in probe
  2026-11-23  7:50 [PATCH v2 0/7] iio: Fix memory corruption, teardown races and bounds checks Lee Jones
  2026-11-23  7:50 ` [PATCH v2 5/7] iio: adc: qcom-spmi-adc5-gen3: Free TM auxiliary device wrapper in release callback Lee Jones
@ 2026-11-23  7:50 ` Lee Jones
  1 sibling, 0 replies; 3+ messages in thread
From: Lee Jones @ 2026-11-23  7:50 UTC (permalink / raw)
  To: lee, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Jishnu Prakash, linux-arm-msm, linux-iio,
	linux-kernel
  Cc: 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 -ENOENT 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>
---

v1 => v2:
 - Return -ENOENT instead of -EINVAL when reg is empty (Andy)

 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 85450aa37e65..8e316aa88f48 100644
--- a/drivers/iio/adc/qcom-spmi-adc5-gen3.c
+++ b/drivers/iio/adc/qcom-spmi-adc5-gen3.c
@@ -736,6 +736,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 -ENOENT;
 
 	adc->dev_data.num_sdams = ret;
 
-- 
2.56.1.750.gf70dc682cf-goog


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-23  7:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23  7:50 [PATCH v2 0/7] iio: Fix memory corruption, teardown races and bounds checks Lee Jones
2026-11-23  7:50 ` [PATCH v2 5/7] iio: adc: qcom-spmi-adc5-gen3: Free TM auxiliary device wrapper in release callback Lee Jones
2026-11-23  7:50 ` [PATCH v2 6/7] iio: adc: qcom-spmi-adc5-gen3: Reject empty reg property in probe Lee Jones

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox