mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] iio: buffer: Fix double-free in iio_buffers_alloc_sysfs_and_mask()
@ 2021-10-12  9:25 Yang Yingliang
  2021-10-12 11:36 ` Alexandru Ardelean
  0 siblings, 1 reply; 11+ messages in thread
From: Yang Yingliang @ 2021-10-12  9:25 UTC (permalink / raw)
  To: linux-kernel, linux-iio; +Cc: lars, jic23, andy.shevchenko

When __iio_buffer_alloc_sysfs_and_mask() failed, 'unwind_idx' should be
set to 'i - 1' to prevent double-free when cleanup resources.

BUG: KASAN: double-free or invalid-free in __iio_buffer_free_sysfs_and_mask+0x32/0xb0 [industrialio]
Call Trace:
 kfree+0x117/0x4c0
 __iio_buffer_free_sysfs_and_mask+0x32/0xb0 [industrialio]
 iio_buffers_alloc_sysfs_and_mask+0x60d/0x1570 [industrialio]
 __iio_device_register+0x483/0x1a30 [industrialio]
 ina2xx_probe+0x625/0x980 [ina2xx_adc]

Reported-by: Hulk Robot <hulkci@huawei.com>
Fixes: ee708e6baacd ("iio: buffer: introduce support for attaching more IIO buffers")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
 drivers/iio/industrialio-buffer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
index a95cc2da56be..5f4bd0b73d03 100644
--- a/drivers/iio/industrialio-buffer.c
+++ b/drivers/iio/industrialio-buffer.c
@@ -1616,7 +1616,7 @@ int iio_buffers_alloc_sysfs_and_mask(struct iio_dev *indio_dev)
 		buffer = iio_dev_opaque->attached_buffers[i];
 		ret = __iio_buffer_alloc_sysfs_and_mask(buffer, indio_dev, i);
 		if (ret) {
-			unwind_idx = i;
+			unwind_idx = i - 1;
 			goto error_unwind_sysfs_and_mask;
 		}
 	}
-- 
2.25.1


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

end of thread, other threads:[~2021-10-13  9:53 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-12  9:25 [PATCH] iio: buffer: Fix double-free in iio_buffers_alloc_sysfs_and_mask() Yang Yingliang
2021-10-12 11:36 ` Alexandru Ardelean
2021-10-12 20:30   ` Andy Shevchenko
2021-10-12 17:43     ` Joe Perches
2021-10-12 20:48       ` Andy Shevchenko
2021-10-12 17:55         ` Joe Perches
2021-10-12 20:58           ` Andy Shevchenko
2021-10-13  9:17             ` Yang Yingliang
2021-10-13  9:28               ` Andy Shevchenko
2021-10-13  9:50                 ` Andy Shevchenko
2021-10-13  2:54     ` Yang Yingliang

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

all inboxes | Powered by JetHome®