This is a note to let you know that I've just added the patch titled mm/damon/dbgfs: fix memory leak when using debugfs_lookup() to the 5.15-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: mm-damon-dbgfs-fix-memory-leak-when-using-debugfs_lookup.patch and it can be found in the queue-5.15 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From 1552fd3ef7dbe07208b8ae84a0a6566adf7dfc9d Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> Date: Fri, 2 Sep 2022 19:11:49 +0000 Subject: mm/damon/dbgfs: fix memory leak when using debugfs_lookup() From: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> commit 1552fd3ef7dbe07208b8ae84a0a6566adf7dfc9d upstream. When calling debugfs_lookup() the result must have dput() called on it, otherwise the memory will leak over time. Fix this up by properly calling dput(). Link: https://lkml.kernel.org/r/20220902191149.112434-1-sj@xxxxxxxxxx Fixes: 75c1c2b53c78b ("mm/damon/dbgfs: support multiple contexts") Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> Signed-off-by: SeongJae Park <sj@xxxxxxxxxx> Cc: <stable@xxxxxxxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- mm/damon/dbgfs.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) --- a/mm/damon/dbgfs.c +++ b/mm/damon/dbgfs.c @@ -443,6 +443,7 @@ static int dbgfs_rm_context(char *name) struct dentry *root, *dir, **new_dirs; struct damon_ctx **new_ctxs; int i, j; + int ret = 0; if (damon_nr_running_ctxs()) return -EBUSY; @@ -457,14 +458,16 @@ static int dbgfs_rm_context(char *name) new_dirs = kmalloc_array(dbgfs_nr_ctxs - 1, sizeof(*dbgfs_dirs), GFP_KERNEL); - if (!new_dirs) - return -ENOMEM; + if (!new_dirs) { + ret = -ENOMEM; + goto out_dput; + } new_ctxs = kmalloc_array(dbgfs_nr_ctxs - 1, sizeof(*dbgfs_ctxs), GFP_KERNEL); if (!new_ctxs) { - kfree(new_dirs); - return -ENOMEM; + ret = -ENOMEM; + goto out_new_dirs; } for (i = 0, j = 0; i < dbgfs_nr_ctxs; i++) { @@ -484,7 +487,13 @@ static int dbgfs_rm_context(char *name) dbgfs_ctxs = new_ctxs; dbgfs_nr_ctxs--; - return 0; + goto out_dput; + +out_new_dirs: + kfree(new_dirs); +out_dput: + dput(dir); + return ret; } static ssize_t dbgfs_rm_context_write(struct file *file, Patches currently in stable-queue which might be from gregkh@xxxxxxxxxxxxxxxxxxx are queue-5.15/thunderbolt-explicitly-reset-plug-events-delay-back-to-usb4-spec-value.patch queue-5.15/clk-ingenic-tcu-properly-enable-registers-before-accessing-timers.patch queue-5.15/mm-damon-dbgfs-fix-memory-leak-when-using-debugfs_lookup.patch queue-5.15/drm-amdgpu-add-amdgpu-suspend-resume-code-path-under-sriov.patch queue-5.15/can-c_can-don-t-cache-tx-messages-for-c_can-cores.patch queue-5.15/mmc-moxart-fix-4-bit-bus-width-and-remove-8-bit-bus-width.patch queue-5.15/revert-firmware-arm_scmi-add-clock-management-to-the-scmi-power-domain.patch queue-5.15/uas-ignore-uas-for-thinkplus-chips.patch queue-5.15/usb-typec-ucsi-remove-incorrect-warning.patch queue-5.15/drm-i915-gt-restrict-forced-preemption-to-the-active-context.patch queue-5.15/net-usb-qmi_wwan-add-new-usb-id-for-dell-branded-em7455.patch queue-5.15/uas-add-no-uas-quirk-for-hiksemi-usb_disk.patch queue-5.15/usb-storage-add-hiksemi-usb3-fw-to-ignore_uas.patch queue-5.15/mmc-hsq-fix-data-stomping-during-mmc-recovery.patch queue-5.15/net-mt7531-only-do-pll-once-after-the-reset.patch queue-5.15/libata-add-ata_horkage_nolpm-for-pioneer-bdr-207m-and-bdr-205.patch queue-5.15/x86-sgx-do-not-fail-on-incomplete-sanitization-on-premature-stop-of-ksgxd.patch queue-5.15/input-snvs_pwrkey-fix-snvs_hpvidr1-register-address.patch queue-5.15/powerpc-64s-radix-don-t-need-to-broadcast-ipi-for-radix-pmd-collapse-flush.patch queue-5.15/vduse-prevent-uninitialized-memory-accesses.patch queue-5.15/arm-dts-integrator-tag-pci-host-with-device_type.patch queue-5.15/ntfs-fix-bug_on-in-ntfs_lookup_inode_by_name.patch