Skip to contentSkip to conversation

platform/x86: ISST: fix use after free problem in tpmi_sst_dev_remove()

PATCH In review Su Hui 2 participants 2 messages May 20, 2024

Subsystems (3)
lore
Share & tools
lore

Su Hui

author
#0 lore raw

PATCH 1/1 platform/x86: ISST: fix use after free problem in tpmi_sst_dev_remove()

clang static checker (scan-build) warning:
drivers/platform/x86/intel/speed_select_if/isst_tpmi_core.c:1614:24:
Use of memory after it is freed.

Using 'tpmi_sst->package_id' after releasing 'tpmi_sst' causes this problem. Change the order of releasing 'tpmi_sst' to fix this.

Fixes 9d1d36268f3d ("platform/x86: ISST: Support partitioned systems")
---
 drivers/platform/x86/intel/speed_select_if/isst_tpmi_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/platform/x86/intel/speed_select_if/isst_tpmi_core.c +1 -1
index 7bac7841ff0a..7fa360073f6e 100644
@@ -1610,8 +1610,8 @@ void tpmi_sst_dev_remove(struct auxiliary_device *auxdev)
 	tpmi_sst->partition_mask_current &= ~BIT(plat_info->partition);
 	/* Free the package instance when the all partitions are removed */
 	if (!tpmi_sst->partition_mask_current) {
-		kfree(tpmi_sst);
 		isst_common.sst_inst[tpmi_sst->package_id] = NULL;
+		kfree(tpmi_sst);
 	}
 	mutex_unlock(&isst_tpmi_dev_lock);
 }
Signature · 1 line
2.30.2
#1 lore raw

Hi Su Hui,

Quoted 7 lines · Su Hui

clang static checker (scan-build) warning:
drivers/platform/x86/intel/speed_select_if/isst_tpmi_core.c:1614:24:
Use of memory after it is freed.

Using 'tpmi_sst->package_id' after releasing 'tpmi_sst' causes this problem. Change the order of releasing 'tpmi_sst' to fix this.

This is fixed by me already.
Ref: https://lore.kernel.org/all/[email protected]/

Thanks,
Harshit

Quoted 20 lines
Fixes 9d1d36268f3d ("platform/x86: ISST: Support partitioned systems")
---
  drivers/platform/x86/intel/speed_select_if/isst_tpmi_core.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/platform/x86/intel/speed_select_if/isst_tpmi_core.c +1 -1
index 7bac7841ff0a..7fa360073f6e 100644
@@ -1610,8 +1610,8 @@ void tpmi_sst_dev_remove(struct auxiliary_device *auxdev)
  	tpmi_sst->partition_mask_current &= ~BIT(plat_info->partition);
  	/* Free the package instance when the all partitions are removed */
  	if (!tpmi_sst->partition_mask_current) {
-		kfree(tpmi_sst);
  		isst_common.sst_inst[tpmi_sst->package_id] = NULL;
+		kfree(tpmi_sst);
  	}
  	mutex_unlock(&isst_tpmi_dev_lock);
  }