Skip to content

Commit a90bca2

Browse files
AlanSterngregkh
authored andcommitted
fs: sysfs: Fix reference leak in sysfs_break_active_protection()
The sysfs_break_active_protection() routine has an obvious reference leak in its error path. If the call to kernfs_find_and_get() fails then kn will be NULL, so the companion sysfs_unbreak_active_protection() routine won't get called (and would only cause an access violation by trying to dereference kn->parent if it was called). As a result, the reference to kobj acquired at the start of the function will never be released. Fix the leak by adding an explicit kobject_put() call when kn is NULL. Signed-off-by: Alan Stern <[email protected]> Fixes: 2afc916 ("scsi: sysfs: Introduce sysfs_{un,}break_active_protection()") Cc: Bart Van Assche <[email protected]> Cc: [email protected] Reviewed-by: Bart Van Assche <[email protected]> Acked-by: Tejun Heo <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 4cece76 commit a90bca2

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

fs/sysfs/file.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,8 @@ struct kernfs_node *sysfs_break_active_protection(struct kobject *kobj,
463463
kn = kernfs_find_and_get(kobj->sd, attr->name);
464464
if (kn)
465465
kernfs_break_active_protection(kn);
466+
else
467+
kobject_put(kobj);
466468
return kn;
467469
}
468470
EXPORT_SYMBOL_GPL(sysfs_break_active_protection);

0 commit comments

Comments
 (0)