Skip to content

Commit bc2c464

Browse files
Lizhi Xugregkh
authored andcommitted
software node: Prevent link creation failure from causing kobj reference count imbalance
syzbot reported a uaf in software_node_notify_remove. [1] When any of the two sysfs_create_link() in software_node_notify() fails, the swnode->kobj reference count will not increase normally, which will cause swnode to be released incorrectly due to the imbalance of kobj reference count when executing software_node_notify_remove(). Increase the reference count of kobj before creating the link to avoid uaf. [1] BUG: KASAN: slab-use-after-free in software_node_notify_remove+0x1bc/0x1c0 drivers/base/swnode.c:1108 Read of size 1 at addr ffff888033c08908 by task syz-executor105/5844 Freed by task 5844: software_node_notify_remove+0x159/0x1c0 drivers/base/swnode.c:1106 device_platform_notify_remove drivers/base/core.c:2387 [inline] Fixes: 9eb5920 ("iommufd/selftest: Add set_dev_pasid in mock iommu") Reported-by: syzbot+2ff22910687ee0dfd48e@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=2ff22910687ee0dfd48e Tested-by: syzbot+2ff22910687ee0dfd48e@syzkaller.appspotmail.com Signed-off-by: Lizhi Xu <lizhi.xu@windriver.com> Reviewed-by: Sakari Ailus <sakari.ailus@linux.intel.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Link: https://lore.kernel.org/r/20250414071123.1228331-1-lizhi.xu@windriver.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 1ae5e4c commit bc2c464

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

drivers/base/swnode.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,6 +1080,7 @@ void software_node_notify(struct device *dev)
10801080
if (!swnode)
10811081
return;
10821082

1083+
kobject_get(&swnode->kobj);
10831084
ret = sysfs_create_link(&dev->kobj, &swnode->kobj, "software_node");
10841085
if (ret)
10851086
return;
@@ -1089,8 +1090,6 @@ void software_node_notify(struct device *dev)
10891090
sysfs_remove_link(&dev->kobj, "software_node");
10901091
return;
10911092
}
1092-
1093-
kobject_get(&swnode->kobj);
10941093
}
10951094

10961095
void software_node_notify_remove(struct device *dev)

0 commit comments

Comments
 (0)