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()
6 From: Alan Stern <stern@rowland.harvard.edu>
8 commit a90bca2228c0646fc29a72689d308e5fe03e6d78 upstream.
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
18 Fix the leak by adding an explicit kobject_put() call when kn is NULL.
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>
29 fs/sysfs/file.c | 2 ++
30 1 file changed, 2 insertions(+)
34 @@ -463,6 +463,8 @@ struct kernfs_node *sysfs_break_active_p
35 kn = kernfs_find_and_get(kobj->sd, attr->name);
37 kernfs_break_active_protection(kn);
42 EXPORT_SYMBOL_GPL(sysfs_break_active_protection);