Skip to content

Commit f8fafb6

Browse files
committed
Merge tag 'thermal-6.12-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm
Pull thermal control fixes from Rafael Wysocki: "Address possible use-after-free scenarios during the processing of thermal netlink commands and during thermal zone removal (Rafael Wysocki)" * tag 'thermal-6.12-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm: thermal: core: Free tzp copy along with the thermal zone thermal: core: Reference count the zone in thermal_zone_get_by_id()
2 parents 325354c + 827a075 commit f8fafb6

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

drivers/thermal/thermal_core.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,7 @@ struct thermal_zone_device *thermal_zone_get_by_id(int id)
728728
mutex_lock(&thermal_list_lock);
729729
list_for_each_entry(tz, &thermal_tz_list, node) {
730730
if (tz->id == id) {
731+
get_device(&tz->device);
731732
match = tz;
732733
break;
733734
}
@@ -1605,14 +1606,12 @@ void thermal_zone_device_unregister(struct thermal_zone_device *tz)
16051606
ida_destroy(&tz->ida);
16061607

16071608
device_del(&tz->device);
1608-
1609-
kfree(tz->tzp);
1610-
16111609
put_device(&tz->device);
16121610

16131611
thermal_notify_tz_delete(tz);
16141612

16151613
wait_for_completion(&tz->removal);
1614+
kfree(tz->tzp);
16161615
kfree(tz);
16171616
}
16181617
EXPORT_SYMBOL_GPL(thermal_zone_device_unregister);

drivers/thermal/thermal_core.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@ int for_each_thermal_governor(int (*cb)(struct thermal_governor *, void *),
194194

195195
struct thermal_zone_device *thermal_zone_get_by_id(int id);
196196

197+
DEFINE_CLASS(thermal_zone_get_by_id, struct thermal_zone_device *,
198+
if (_T) put_device(&_T->device), thermal_zone_get_by_id(id), int id)
199+
197200
static inline bool cdev_is_power_actor(struct thermal_cooling_device *cdev)
198201
{
199202
return cdev->ops->get_requested_power && cdev->ops->state2power &&

drivers/thermal/thermal_netlink.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,6 @@ static int thermal_genl_cmd_tz_get_trip(struct param *p)
443443
{
444444
struct sk_buff *msg = p->msg;
445445
const struct thermal_trip_desc *td;
446-
struct thermal_zone_device *tz;
447446
struct nlattr *start_trip;
448447
int id;
449448

@@ -452,7 +451,7 @@ static int thermal_genl_cmd_tz_get_trip(struct param *p)
452451

453452
id = nla_get_u32(p->attrs[THERMAL_GENL_ATTR_TZ_ID]);
454453

455-
tz = thermal_zone_get_by_id(id);
454+
CLASS(thermal_zone_get_by_id, tz)(id);
456455
if (!tz)
457456
return -EINVAL;
458457

@@ -488,15 +487,14 @@ static int thermal_genl_cmd_tz_get_trip(struct param *p)
488487
static int thermal_genl_cmd_tz_get_temp(struct param *p)
489488
{
490489
struct sk_buff *msg = p->msg;
491-
struct thermal_zone_device *tz;
492490
int temp, ret, id;
493491

494492
if (!p->attrs[THERMAL_GENL_ATTR_TZ_ID])
495493
return -EINVAL;
496494

497495
id = nla_get_u32(p->attrs[THERMAL_GENL_ATTR_TZ_ID]);
498496

499-
tz = thermal_zone_get_by_id(id);
497+
CLASS(thermal_zone_get_by_id, tz)(id);
500498
if (!tz)
501499
return -EINVAL;
502500

@@ -514,15 +512,14 @@ static int thermal_genl_cmd_tz_get_temp(struct param *p)
514512
static int thermal_genl_cmd_tz_get_gov(struct param *p)
515513
{
516514
struct sk_buff *msg = p->msg;
517-
struct thermal_zone_device *tz;
518515
int id, ret = 0;
519516

520517
if (!p->attrs[THERMAL_GENL_ATTR_TZ_ID])
521518
return -EINVAL;
522519

523520
id = nla_get_u32(p->attrs[THERMAL_GENL_ATTR_TZ_ID]);
524521

525-
tz = thermal_zone_get_by_id(id);
522+
CLASS(thermal_zone_get_by_id, tz)(id);
526523
if (!tz)
527524
return -EINVAL;
528525

0 commit comments

Comments
 (0)