Message ID | 20250411004203.2932899-1-lizhi.xu@windriver.com |
---|---|
State | New |
Headers | show |
Series | software node: Prevent link creation failure from causing kobj reference count imbalance | expand |
On Fri, Apr 11, 2025 at 08:42:02AM +0800, Lizhi Xu wrote: > 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] Please, reduce this to ~5-7 lines only. This is how Submitting Patches document recommends to put backtraces in the commit messages: https://www.kernel.org/doc/html/latest/process/submitting-patches.html#backtraces-in-commit-messages > Fixes: 9eb59204d519 ("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 Where is the positive result of it? I can't find the respective log. To me this one https://syzkaller.appspot.com/x/report.txt?x=158af070580000 doesn't sound as a useful report as I don't know if this patch fixes one regression and introduced another. Dmitry?
diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c index b1726a3515f6..5c78fa6ae772 100644 --- a/drivers/base/swnode.c +++ b/drivers/base/swnode.c @@ -1080,6 +1080,7 @@ void software_node_notify(struct device *dev) if (!swnode) return; + kobject_get(&swnode->kobj); ret = sysfs_create_link(&dev->kobj, &swnode->kobj, "software_node"); if (ret) return; @@ -1089,8 +1090,6 @@ void software_node_notify(struct device *dev) sysfs_remove_link(&dev->kobj, "software_node"); return; } - - kobject_get(&swnode->kobj); } void software_node_notify_remove(struct device *dev)