cpufreq: schedutil: Fix tunables_hook cleanup on init failure
Subsystems (2)
PATCH 1/1 cpufreq: schedutil: Fix tunables_hook cleanup on init failure
If sugov_init() fails after registering the tunables_hook to the global list, the hook is not removed before freeing the tunables structure via kobject_put(). This leaves a dangling list entry pointing to freed memory.
Remove the hook from the list in the error path to prevent this.
--- kernel/sched/cpufreq_schedutil.c | 1 + 1 file changed, 1 insertion(+)
kernel/sched/cpufreq_schedutil.c +1 -0
@@ -800,6 +800,7 @@ static int sugov_init(struct cpufreq_policy *policy)return 0 ; fail: +list_del (&sg_policy->tunables_hook);kobject_put (&tunables->attr_set.kobj); policy->governor_data =NULL ;sugov_clear_global_tunables ();
Signature · 1 line
2.34.1
Rafael J. Wysocki
maintainerQuoted 5 lines · Kaushlendra Kumar
If
sugov_init()fails after registering thetunables_hookto the global list, the hook is not removed before freeing the tunables structure viakobject_put(). This leaves a dangling list entry pointing to freed memory.
Except that sugov_init() cannot fail after calling gov_attr_set_get(), so how can it get to the error path with tunables_hook in the list in the first place?
Quoted 1 line
Remove the hook from the list in the error path to prevent this.
There is no bug to fix here AFAICS.
Quoted 10 lines
Signed-off-by Kaushlendra Kumar <[email protected]>--- kernel/sched/cpufreq_schedutil.c | 1 + 1 file changed, 1 insertion(+)kernel/sched/cpufreq_schedutil.c +0
-0
kernel/sched/cpufreq_schedutil.c static int sugov_init(struct cpufreq_policy *policy) · line 803
Quoted 4 lines
kernel/sched/cpufreq_schedutil.c +1
-0@@ -800,6 +800,7 @@ static int sugov_init(struct cpufreq_policy *policy)return 0 ; fail: +list_del (&sg_policy->tunables_hook);
And this change is invalid.
Quoted 4 lines
kernel/sched/cpufreq_schedutil.c +0
-1kobject_put (&tunables->attr_set.kobj); policy->governor_data =NULL ;sugov_clear_global_tunables (); --
Hi Rafael,
Quoted 8 lines · Rafael J. Wysocki
Quoted 5 lines · Kaushlendra Kumar
If
sugov_init()fails after registering thetunables_hookto the global list, the hook is not removed before freeing the tunables structure viakobject_put(). This leaves a dangling list entry pointing to freed memory.
Quoted 8 lines
Except that
sugov_init()cannot fail after callinggov_attr_set_get(), so how can it get to the error path withtunables_hookin the list in the first place?Quoted 1 line
Remove the hook from the list in the error path to prevent this.
There is no bug to fix here AFAICS.
In function sugov_tunables_alloc() tunables_hook is getting added. tunables = sugov_tunables_alloc(sg_policy);
Thanks for the review.
Regards,
Kaushlendra
Rafael J. Wysocki
maintainerQuoted 17 lines · Kaushlendra
Hi Rafael,
Quoted 13 lines · Rafael J. Wysocki
Quoted 5 lines · Kaushlendra Kumar
If
sugov_init()fails after registering thetunables_hookto the global list, the hook is not removed before freeing the tunables structure viakobject_put(). This leaves a dangling list entry pointing to freed memory.Except that
sugov_init()cannot fail after callinggov_attr_set_get(), so how can it get to the error path withtunables_hookin the list in the first place?
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Remove the hook from the list in the error path to prevent this.
There is no bug to fix here AFAICS.
In function
sugov_tunables_alloc()tunables_hookis getting added. tunables =sugov_tunables_alloc(sg_policy);
Yes, which adds tunables_hook in sg_policy to attr_set in tunables. Both tunables and sg_policy are freed in the error path in question.
Where's the bug being fixed then?
Hi Rafael,
Quoted 10 lines · Rafael J. Wysocki
Quoted 3 lines · Kaushlendra
In function
sugov_tunables_alloc()tunables_hookis getting added. tunables =sugov_tunables_alloc(sg_policy);Yes, which adds
tunables_hookinsg_policytoattr_setin tunables. Both tunables andsg_policyare freed in the error path in question.Where's the bug being fixed then?
Agreed. Since both structures are freed, there's no dangling pointer issue. I misunderstood the lifecycle. There is no bug here.
Please disregard this patch.
Regards,
Kaushlendra