lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20260204203414.89333-1-salah.triki@gmail.com>
Date: Wed,  4 Feb 2026 21:34:13 +0100
From: Salah Triki <salah.triki@...il.com>
To: Jonathan Cameron <jic23@...nel.org>,
	David Lechner <dlechner@...libre.com>,
	Nuno Sá <nuno.sa@...log.com>,
	Andy Shevchenko <andy@...nel.org>
Cc: linux-iio@...r.kernel.org,
	linux-kernel@...r.kernel.org,
	Salah Triki <salah.triki@...il.com>
Subject: [PATCH v2] iio: trigger: fix use-after-free in viio_trigger_alloc()

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 via `put_device()`.

Currently, if `irq_alloc_descs()` or `kvasprintf()` fails, the code
manually calls `irq_free_descs()` and `kfree()`. This is problematic for
two reasons:

1. Calling `kfree()` directly bypasses the device's release callback
   (`iio_trig_release()`), which could lead to resource leaks or
   inconsistencies within the driver core.

2. If we simply replace `kfree()` with `put_device()`, a double free
   occurs because `iio_trig_release()` already calls `irq_free_descs()`.

Fix this by:
- Using `put_device()` to handle memory tearing down.
- Removing the manual call to `irq_free_descs()` in the error path, as
  it is already handled by the trigger's release function.

Path to the issue:
viio_trigger_alloc()
  -> device_initialize() (refcount = 1)
  -> kvasprintf() fails
  -> goto free_descs
  -> irq_free_descs() (first manual free)
  -> kfree(trig) (refcount is still 1, release never called)

Fixes: 2c99f1a09da3d ("iio: trigger: clean up viio_trigger_alloc()")
Signed-off-by: Salah Triki <salah.triki@...il.com>
---
Changes in v2:
- Remove the manual call to irq_free_descs() in the error path to avoid 
  a double free, as this is already handled by iio_trig_release().
- Clarify the error path and the potential for memory corruption in 
  the commit description.
- Remove the blank line in the tag block to comply with kernel script 
  requirements.

 drivers/iio/industrialio-trigger.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/iio/industrialio-trigger.c b/drivers/iio/industrialio-trigger.c
index 54416a384232..7f53e2a5a101 100644
--- a/drivers/iio/industrialio-trigger.c
+++ b/drivers/iio/industrialio-trigger.c
@@ -576,7 +576,7 @@ struct iio_trigger *viio_trigger_alloc(struct device *parent,
 
 	trig->name = kvasprintf(GFP_KERNEL, fmt, vargs);
 	if (trig->name == NULL)
-		goto free_descs;
+		goto free_trig;
 
 	INIT_LIST_HEAD(&trig->list);
 
@@ -594,10 +594,8 @@ struct iio_trigger *viio_trigger_alloc(struct device *parent,
 
 	return trig;
 
-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


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ