]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-6.8/fs-sysfs-fix-reference-leak-in-sysfs_break_active_protection.patch
6.8-stable patches
[thirdparty/kernel/stable-queue.git] / queue-6.8 / fs-sysfs-fix-reference-leak-in-sysfs_break_active_protection.patch
1 From a90bca2228c0646fc29a72689d308e5fe03e6d78 Mon Sep 17 00:00:00 2001
2 From: Alan Stern <stern@rowland.harvard.edu>
3 Date: Wed, 13 Mar 2024 17:43:41 -0400
4 Subject: fs: sysfs: Fix reference leak in sysfs_break_active_protection()
5
6 From: Alan Stern <stern@rowland.harvard.edu>
7
8 commit a90bca2228c0646fc29a72689d308e5fe03e6d78 upstream.
9
10 The sysfs_break_active_protection() routine has an obvious reference
11 leak in its error path. If the call to kernfs_find_and_get() fails then
12 kn will be NULL, so the companion sysfs_unbreak_active_protection()
13 routine won't get called (and would only cause an access violation by
14 trying to dereference kn->parent if it was called). As a result, the
15 reference to kobj acquired at the start of the function will never be
16 released.
17
18 Fix the leak by adding an explicit kobject_put() call when kn is NULL.
19
20 Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
21 Fixes: 2afc9166f79b ("scsi: sysfs: Introduce sysfs_{un,}break_active_protection()")
22 Cc: Bart Van Assche <bvanassche@acm.org>
23 Cc: stable@vger.kernel.org
24 Reviewed-by: Bart Van Assche <bvanassche@acm.org>
25 Acked-by: Tejun Heo <tj@kernel.org>
26 Link: https://lore.kernel.org/r/8a4d3f0f-c5e3-4b70-a188-0ca433f9e6f9@rowland.harvard.edu
27 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
28 ---
29 fs/sysfs/file.c | 2 ++
30 1 file changed, 2 insertions(+)
31
32 --- a/fs/sysfs/file.c
33 +++ b/fs/sysfs/file.c
34 @@ -463,6 +463,8 @@ struct kernfs_node *sysfs_break_active_p
35 kn = kernfs_find_and_get(kobj->sd, attr->name);
36 if (kn)
37 kernfs_break_active_protection(kn);
38 + else
39 + kobject_put(kobj);
40 return kn;
41 }
42 EXPORT_SYMBOL_GPL(sysfs_break_active_protection);