From fb7c9f4990ba68fa75823c76ceb1e8939e0de49c Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Sat, 10 Sep 2022 08:27:18 +0200 Subject: [PATCH] 5.19-stable patches added patches: debugfs-add-debugfs_lookup_and_remove.patch driver-core-fix-driver_set_override-issue-with-empty-strings.patch drm-amd-display-fix-memory-leak-when-using-debugfs_lookup.patch sched-debug-fix-dentry-leak-in-update_sched_domain_debugfs.patch --- ...ebugfs-add-debugfs_lookup_and_remove.patch | 79 +++++++++++++++++++ ...et_override-issue-with-empty-strings.patch | 49 ++++++++++++ ...emory-leak-when-using-debugfs_lookup.patch | 58 ++++++++++++++ ...-leak-in-update_sched_domain_debugfs.patch | 49 ++++++++++++ queue-5.19/series | 4 + 5 files changed, 239 insertions(+) create mode 100644 queue-5.19/debugfs-add-debugfs_lookup_and_remove.patch create mode 100644 queue-5.19/driver-core-fix-driver_set_override-issue-with-empty-strings.patch create mode 100644 queue-5.19/drm-amd-display-fix-memory-leak-when-using-debugfs_lookup.patch create mode 100644 queue-5.19/sched-debug-fix-dentry-leak-in-update_sched_domain_debugfs.patch diff --git a/queue-5.19/debugfs-add-debugfs_lookup_and_remove.patch b/queue-5.19/debugfs-add-debugfs_lookup_and_remove.patch new file mode 100644 index 00000000000..24da4c15758 --- /dev/null +++ b/queue-5.19/debugfs-add-debugfs_lookup_and_remove.patch @@ -0,0 +1,79 @@ +From dec9b2f1e0455a151a7293c367da22ab973f713e Mon Sep 17 00:00:00 2001 +From: Greg Kroah-Hartman +Date: Fri, 2 Sep 2022 16:59:15 +0200 +Subject: debugfs: add debugfs_lookup_and_remove() + +From: Greg Kroah-Hartman + +commit dec9b2f1e0455a151a7293c367da22ab973f713e upstream. + +There is a very common pattern of using +debugfs_remove(debufs_lookup(..)) which results in a dentry leak of the +dentry that was looked up. Instead of having to open-code the correct +pattern of calling dput() on the dentry, create +debugfs_lookup_and_remove() to handle this pattern automatically and +properly without any memory leaks. + +Cc: stable +Reported-by: Kuyo Chang +Tested-by: Kuyo Chang +Link: https://lore.kernel.org/r/YxIaQ8cSinDR881k@kroah.com +Signed-off-by: Greg Kroah-Hartman +--- + fs/debugfs/inode.c | 22 ++++++++++++++++++++++ + include/linux/debugfs.h | 6 ++++++ + 2 files changed, 28 insertions(+) + +--- a/fs/debugfs/inode.c ++++ b/fs/debugfs/inode.c +@@ -745,6 +745,28 @@ void debugfs_remove(struct dentry *dentr + EXPORT_SYMBOL_GPL(debugfs_remove); + + /** ++ * debugfs_lookup_and_remove - lookup a directory or file and recursively remove it ++ * @name: a pointer to a string containing the name of the item to look up. ++ * @parent: a pointer to the parent dentry of the item. ++ * ++ * This is the equlivant of doing something like ++ * debugfs_remove(debugfs_lookup(..)) but with the proper reference counting ++ * handled for the directory being looked up. ++ */ ++void debugfs_lookup_and_remove(const char *name, struct dentry *parent) ++{ ++ struct dentry *dentry; ++ ++ dentry = debugfs_lookup(name, parent); ++ if (!dentry) ++ return; ++ ++ debugfs_remove(dentry); ++ dput(dentry); ++} ++EXPORT_SYMBOL_GPL(debugfs_lookup_and_remove); ++ ++/** + * debugfs_rename - rename a file/directory in the debugfs filesystem + * @old_dir: a pointer to the parent dentry for the renamed object. This + * should be a directory dentry. +--- a/include/linux/debugfs.h ++++ b/include/linux/debugfs.h +@@ -91,6 +91,8 @@ struct dentry *debugfs_create_automount( + void debugfs_remove(struct dentry *dentry); + #define debugfs_remove_recursive debugfs_remove + ++void debugfs_lookup_and_remove(const char *name, struct dentry *parent); ++ + const struct file_operations *debugfs_real_fops(const struct file *filp); + + int debugfs_file_get(struct dentry *dentry); +@@ -225,6 +227,10 @@ static inline void debugfs_remove(struct + static inline void debugfs_remove_recursive(struct dentry *dentry) + { } + ++static inline void debugfs_lookup_and_remove(const char *name, ++ struct dentry *parent) ++{ } ++ + const struct file_operations *debugfs_real_fops(const struct file *filp); + + static inline int debugfs_file_get(struct dentry *dentry) diff --git a/queue-5.19/driver-core-fix-driver_set_override-issue-with-empty-strings.patch b/queue-5.19/driver-core-fix-driver_set_override-issue-with-empty-strings.patch new file mode 100644 index 00000000000..b5a9da33da3 --- /dev/null +++ b/queue-5.19/driver-core-fix-driver_set_override-issue-with-empty-strings.patch @@ -0,0 +1,49 @@ +From 5666a274a6d54372d6b79b1f78682a9d827e679e Mon Sep 17 00:00:00 2001 +From: Greg Kroah-Hartman +Date: Thu, 1 Sep 2022 18:37:34 +0200 +Subject: driver core: fix driver_set_override() issue with empty strings + +From: Greg Kroah-Hartman + +commit 5666a274a6d54372d6b79b1f78682a9d827e679e upstream. + +Python likes to send an empty string for some sysfs files, including the +driver_override field. When commit 23d99baf9d72 ("PCI: Use +driver_set_override() instead of open-coding") moved the PCI core to use +the driver core function instead of hand-rolling their own handler, this +showed up as a regression from some userspace tools, like DPDK. + +Fix this up by actually looking at the length of the string first +instead of trusting that userspace got it correct. + +Fixes: 23d99baf9d72 ("PCI: Use driver_set_override() instead of open-coding") +Cc: Krzysztof Kozlowski +Cc: Bjorn Helgaas +Cc: "Rafael J. Wysocki" +Cc: Andy Shevchenko +Cc: stable +Reported-by: Stephen Hemminger +Tested-by: Huisong Li +Reviewed-by: Stephen Hemminger +Reviewed-by: Krzysztof Kozlowski +Link: https://lore.kernel.org/r/20220901163734.3583106-1-gregkh@linuxfoundation.org +Signed-off-by: Greg Kroah-Hartman +--- + drivers/base/driver.c | 6 ++++++ + 1 file changed, 6 insertions(+) + +--- a/drivers/base/driver.c ++++ b/drivers/base/driver.c +@@ -63,6 +63,12 @@ int driver_set_override(struct device *d + if (len >= (PAGE_SIZE - 1)) + return -EINVAL; + ++ /* ++ * Compute the real length of the string in case userspace sends us a ++ * bunch of \0 characters like python likes to do. ++ */ ++ len = strlen(s); ++ + if (!len) { + /* Empty string passed - clear override */ + device_lock(dev); diff --git a/queue-5.19/drm-amd-display-fix-memory-leak-when-using-debugfs_lookup.patch b/queue-5.19/drm-amd-display-fix-memory-leak-when-using-debugfs_lookup.patch new file mode 100644 index 00000000000..16557ad6a92 --- /dev/null +++ b/queue-5.19/drm-amd-display-fix-memory-leak-when-using-debugfs_lookup.patch @@ -0,0 +1,58 @@ +From cbfac7fa491651c57926c99edeb7495c6c1aeac2 Mon Sep 17 00:00:00 2001 +From: Greg Kroah-Hartman +Date: Fri, 2 Sep 2022 15:01:05 +0200 +Subject: drm/amd/display: fix memory leak when using debugfs_lookup() +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +From: Greg Kroah-Hartman + +commit cbfac7fa491651c57926c99edeb7495c6c1aeac2 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(). + +Cc: Harry Wentland +Cc: Leo Li +Cc: Rodrigo Siqueira +Cc: Alex Deucher +Cc: "Christian König" +Cc: "Pan, Xinhui" +Cc: David Airlie +Cc: Daniel Vetter +Cc: Wayne Lin +Cc: hersen wu +Cc: Wenjing Liu +Cc: Patrik Jakobsson +Cc: Thelford Williams +Cc: Fangzhi Zuo +Cc: Yongzhi Liu +Cc: Mikita Lipski +Cc: Jiapeng Chong +Cc: Bhanuprakash Modem +Cc: Sean Paul +Cc: amd-gfx@lists.freedesktop.org +Cc: dri-devel@lists.freedesktop.org +Cc: stable@vger.kernel.org +Reviewed-by: Rodrigo Siqueira +Signed-off-by: Greg Kroah-Hartman +Signed-off-by: Rodrigo Siqueira +Signed-off-by: Alex Deucher +Signed-off-by: Greg Kroah-Hartman +--- + drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.c ++++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.c +@@ -3188,7 +3188,7 @@ void crtc_debugfs_init(struct drm_crtc * + &crc_win_y_end_fops); + debugfs_create_file_unsafe("crc_win_update", 0644, dir, crtc, + &crc_win_update_fops); +- ++ dput(dir); + } + #endif + /* diff --git a/queue-5.19/sched-debug-fix-dentry-leak-in-update_sched_domain_debugfs.patch b/queue-5.19/sched-debug-fix-dentry-leak-in-update_sched_domain_debugfs.patch new file mode 100644 index 00000000000..9316a2f89e8 --- /dev/null +++ b/queue-5.19/sched-debug-fix-dentry-leak-in-update_sched_domain_debugfs.patch @@ -0,0 +1,49 @@ +From c2e406596571659451f4b95e37ddfd5a8ef1d0dc Mon Sep 17 00:00:00 2001 +From: Greg Kroah-Hartman +Date: Fri, 2 Sep 2022 14:31:07 +0200 +Subject: sched/debug: fix dentry leak in update_sched_domain_debugfs + +From: Greg Kroah-Hartman + +commit c2e406596571659451f4b95e37ddfd5a8ef1d0dc upstream. + +Kuyo reports that the pattern of using debugfs_remove(debugfs_lookup()) +leaks a dentry and with a hotplug stress test, the machine eventually +runs out of memory. + +Fix this up by using the newly created debugfs_lookup_and_remove() call +instead which properly handles the dentry reference counting logic. + +Cc: Major Chen +Cc: stable +Cc: Ingo Molnar +Cc: Peter Zijlstra +Cc: Juri Lelli +Cc: Vincent Guittot +Cc: Dietmar Eggemann +Cc: Steven Rostedt +Cc: Ben Segall +Cc: Mel Gorman +Cc: Daniel Bristot de Oliveira +Cc: Valentin Schneider +Cc: Matthias Brugger +Reported-by: Kuyo Chang +Tested-by: Kuyo Chang +Acked-by: Peter Zijlstra (Intel) +Link: https://lore.kernel.org/r/20220902123107.109274-2-gregkh@linuxfoundation.org +Signed-off-by: Greg Kroah-Hartman +--- + kernel/sched/debug.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +--- a/kernel/sched/debug.c ++++ b/kernel/sched/debug.c +@@ -416,7 +416,7 @@ void update_sched_domain_debugfs(void) + char buf[32]; + + snprintf(buf, sizeof(buf), "cpu%d", cpu); +- debugfs_remove(debugfs_lookup(buf, sd_dentry)); ++ debugfs_lookup_and_remove(buf, sd_dentry); + d_cpu = debugfs_create_dir(buf, sd_dentry); + + i = 0; diff --git a/queue-5.19/series b/queue-5.19/series index 6e629176284..5d09592fadf 100644 --- a/queue-5.19/series +++ b/queue-5.19/series @@ -47,3 +47,7 @@ btrfs-zoned-fix-api-misuse-of-zone-finish-waiting.patch vfio-type1-unpin-zero-pages.patch kprobes-prohibit-probes-in-gate-area.patch perf-risc-v-fix-access-beyond-allocated-array.patch +debugfs-add-debugfs_lookup_and_remove.patch +sched-debug-fix-dentry-leak-in-update_sched_domain_debugfs.patch +drm-amd-display-fix-memory-leak-when-using-debugfs_lookup.patch +driver-core-fix-driver_set_override-issue-with-empty-strings.patch -- 2.47.3