This is a note to let you know that I've just added the patch titled iio: trigger: sysfs: fix possible memory leak in iio_sysfs_trig_init() to the 5.10-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: iio-trigger-sysfs-fix-possible-memory-leak-in-iio_sysfs_trig_init.patch and it can be found in the queue-5.10 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From efa17e90e1711bdb084e3954fa44afb6647331c0 Mon Sep 17 00:00:00 2001 From: Yang Yingliang <yangyingliang@xxxxxxxxxx> Date: Sat, 22 Oct 2022 15:42:12 +0800 Subject: iio: trigger: sysfs: fix possible memory leak in iio_sysfs_trig_init() From: Yang Yingliang <yangyingliang@xxxxxxxxxx> commit efa17e90e1711bdb084e3954fa44afb6647331c0 upstream. dev_set_name() allocates memory for name, it need be freed when device_add() fails, call put_device() to give up the reference that hold in device_initialize(), so that it can be freed in kobject_cleanup() when the refcount hit to 0. Fault injection test can trigger this: unreferenced object 0xffff8e8340a7b4c0 (size 32): comm "modprobe", pid 243, jiffies 4294678145 (age 48.845s) hex dump (first 32 bytes): 69 69 6f 5f 73 79 73 66 73 5f 74 72 69 67 67 65 iio_sysfs_trigge 72 00 a7 40 83 8e ff ff 00 86 13 c4 f6 ee ff ff r..@............ backtrace: [<0000000074999de8>] __kmem_cache_alloc_node+0x1e9/0x360 [<00000000497fd30b>] __kmalloc_node_track_caller+0x44/0x1a0 [<000000003636c520>] kstrdup+0x2d/0x60 [<0000000032f84da2>] kobject_set_name_vargs+0x1e/0x90 [<0000000092efe493>] dev_set_name+0x4e/0x70 Fixes: 1f785681a870 ("staging:iio:trigger sysfs userspace trigger rework.") Signed-off-by: Yang Yingliang <yangyingliang@xxxxxxxxxx> Cc: <Stable@xxxxxxxxxxxxxxx> Link: https://lore.kernel.org/r/20221022074212.1386424-1-yangyingliang@xxxxxxxxxx Signed-off-by: Jonathan Cameron <Jonathan.Cameron@xxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- drivers/iio/trigger/iio-trig-sysfs.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) --- a/drivers/iio/trigger/iio-trig-sysfs.c +++ b/drivers/iio/trigger/iio-trig-sysfs.c @@ -209,9 +209,13 @@ static int iio_sysfs_trigger_remove(int static int __init iio_sysfs_trig_init(void) { + int ret; device_initialize(&iio_sysfs_trig_dev); dev_set_name(&iio_sysfs_trig_dev, "iio_sysfs_trigger"); - return device_add(&iio_sysfs_trig_dev); + ret = device_add(&iio_sysfs_trig_dev); + if (ret) + put_device(&iio_sysfs_trig_dev); + return ret; } module_init(iio_sysfs_trig_init); Patches currently in stable-queue which might be from yangyingliang@xxxxxxxxxx are queue-5.10/ata-libata-transport-fix-error-handling-in-ata_tport.patch queue-5.10/iio-adc-at91_adc-fix-possible-memory-leak-in-at91_adc_allocate_trigger.patch queue-5.10/siox-fix-possible-memory-leak-in-siox_device_add.patch queue-5.10/misdn-fix-possible-memory-leak-in-misdn_dsp_element_.patch queue-5.10/xen-pcpu-fix-possible-memory-leak-in-register_pcpu.patch queue-5.10/iio-trigger-sysfs-fix-possible-memory-leak-in-iio_sysfs_trig_init.patch queue-5.10/ata-libata-transport-fix-double-ata_host_put-in-ata_.patch queue-5.10/ata-libata-transport-fix-error-handling-in-ata_tlink.patch queue-5.10/ata-libata-transport-fix-error-handling-in-ata_tdev_.patch