public inbox for linux-iio@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] iio: trigger: fix use-after-free in viio_trigger_alloc()
@ 2026-01-31  9:23 Salah Triki
  2026-01-31 12:44 ` Jonathan Cameron
  0 siblings, 1 reply; 8+ messages in thread
From: Salah Triki @ 2026-01-31  9:23 UTC (permalink / raw)
  To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko
  Cc: linux-iio, linux-kernel, Salah Triki

Once `device_initialize()` is called, the reference count of the device
is set to 1. The memory associated with the device must then be
managed by the kobject reference counting.

In `viio_trigger_alloc()`, if `irq_alloc_descs()` or `kvasprintf()` fails,
the code currently calls `kfree()`. Using `kfree()` in this case bypasses
the device's release callback and can lead to a use-after-free or memory
corruption.

Fix this by calling `put_device()` instead of `kfree()`. This ensures that
the memory is freed properly via `iio_trig_release()` when the reference
count drops to zero.

Fixes: 2c99f1a09da3d ("iio: trigger: clean up viio_trigger_alloc()")

Signed-off-by: Salah Triki <salah.triki@gmail.com>
---
 drivers/iio/industrialio-trigger.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/industrialio-trigger.c b/drivers/iio/industrialio-trigger.c
index 54416a384232..981e19757870 100644
--- a/drivers/iio/industrialio-trigger.c
+++ b/drivers/iio/industrialio-trigger.c
@@ -597,7 +597,7 @@ struct iio_trigger *viio_trigger_alloc(struct device *parent,
 free_descs:
 	irq_free_descs(trig->subirq_base, CONFIG_IIO_CONSUMERS_PER_TRIGGER);
 free_trig:
-	kfree(trig);
+	put_device(&trig->dev);
 	return NULL;
 }
 
-- 
2.43.0


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

end of thread, other threads:[~2026-02-04 20:03 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-31  9:23 [PATCH] iio: trigger: fix use-after-free in viio_trigger_alloc() Salah Triki
2026-01-31 12:44 ` Jonathan Cameron
2026-02-02 10:12   ` Nuno Sá
2026-02-02 20:52     ` Jonathan Cameron
2026-02-03 11:18       ` Andy Shevchenko
2026-02-03 11:20         ` Andy Shevchenko
2026-02-03 11:26           ` Andy Shevchenko
2026-02-04 20:03   ` Salah Triki

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