drm/amd/pm: Fix memory some memory corruption
PATCH 1/1 drm/amd/pm: Fix memory some memory corruption
The "od_table" is a pointer to a large struct, but this code is doing pointer math as if it were pointing to bytes. It results in writing far outside the struct.
--- drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c | 4 ++-- drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +2 -2
@@ -1535,7 +1535,7 @@ static int smu_v13_0_0_od_edit_dpm_table(struct smu_context *smu,* settings. Thus we do not cache it. */ offset_of_featurectrlmask = offsetof(OverDriveTable_t , FeatureCtrlMask); -if (memcmp (od_table + offset_of_featurectrlmask, +if (memcmp ((u8 *)od_table + offset_of_featurectrlmask, table_context->user_overdrive_table + offset_of_featurectrlmask,sizeof (OverDriveTableExternal_t) - offset_of_featurectrlmask)) {smu_v13_0_0_dump_od_table (smu, od_table);
@@ -1548,7 +1548,7 @@ static int smu_v13_0_0_od_edit_dpm_table(struct smu_context *smu, od_table->OverDriveTable.FeatureCtrlMask =0 ;memcpy (table_context->user_overdrive_table + offset_of_featurectrlmask, - od_table + offset_of_featurectrlmask, + (u8 *)od_table + offset_of_featurectrlmask,sizeof (OverDriveTableExternal_t) - offset_of_featurectrlmask); if (!memcmp(table_context->user_overdrive_table,
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +2 -2
@@ -1524,7 +1524,7 @@ static int smu_v13_0_7_od_edit_dpm_table(struct smu_context *smu,* settings. Thus we do not cache it. */ offset_of_featurectrlmask = offsetof(OverDriveTable_t , FeatureCtrlMask); -if (memcmp (od_table + offset_of_featurectrlmask, +if (memcmp ((u8 *)od_table + offset_of_featurectrlmask, table_context->user_overdrive_table + offset_of_featurectrlmask,sizeof (OverDriveTableExternal_t) - offset_of_featurectrlmask)) {smu_v13_0_7_dump_od_table (smu, od_table);
@@ -1537,7 +1537,7 @@ static int smu_v13_0_7_od_edit_dpm_table(struct smu_context *smu, od_table->OverDriveTable.FeatureCtrlMask =0 ;memcpy (table_context->user_overdrive_table + offset_of_featurectrlmask, - od_table + offset_of_featurectrlmask, + (u8 *)od_table + offset_of_featurectrlmask,sizeof (OverDriveTableExternal_t) - offset_of_featurectrlmask); if (!memcmp(table_context->user_overdrive_table,
Signature · 1 line
2.39.2
[AMD Official Use Only - General]
Thanks for catching this.
Quoted 87 lines
-----Original Message-----
From: Dan Carpenter <[email protected]>
Sent: Tuesday, June 6, 2023 4:34 PM
To: Quan, Evan <[email protected]>
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Pan, Xinhui <[email protected]>; David Airlie <[email protected]>; Daniel Vetter <[email protected]>; Lazar, Lijo <[email protected]>; Zhang, Hawking <[email protected]>; Feng, Kenneth <[email protected]>; Li, Candice <[email protected]>; Chai, Thomas <[email protected]>; Wang, Yang(Kevin) <[email protected]>; Zhang, Horatio <[email protected]>; [email protected]; [email protected]
Subject: [PATCH] drm/amd/pm: Fix memory some memory corruptionThe "
od_table" is a pointer to a large struct, but this code is doing pointer math as if it were pointing to bytes. It results in writing far outside the struct.Fixes f0a0c659fb96 ("drm/amd/pm: fulfill the OD support for SMU13.0.0")Fixes e3afa4f988b3 ("drm/amd/pm: fulfill the OD support for SMU13.0.7")Signed-off-by Dan Carpenter <[email protected]>--- drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c | 4 ++-- drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +1
-1@@ -1535,7 +1535,7 @@ static int smu_v13_0_0_od_edit_dpm_table(structsmu_context *smu, * settings. Thus we do not cache it. */ offset_of_featurectrlmask = offsetof(OverDriveTable_t , FeatureCtrlMask); - if (memcmp(od_table + offset_of_featurectrlmask, + if (memcmp((u8 *)od_table + offset_of_featurectrlmask, table_context->user_overdrive_table +
offset_of_featurectrlmask,
sizeof(OverDriveTableExternal_t)-offset_of_featurectrlmask)) { smu_v13_0_0_dump_od_table(smu, od_table); @@ -1548,7 +1548,7 @@ static int smu_v13_0_0_od_edit_dpm_table(struct
smu_context*smu,od_table->OverDriveTable.FeatureCtrlMask = 0; memcpy(table_context->user_overdrive_table +
offset_of_featurectrlmask,drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +1
-1- od_table + offset_of_featurectrlmask, + (u8 *)od_table + offset_of_featurectrlmask, sizeof(OverDriveTableExternal_t) -
offset_of_featurectrlmask);if (!memcmp(table_context->user_overdrive_table,drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +1
-1@@ -1524,7 +1524,7 @@ static int smu_v13_0_7_od_edit_dpm_table(structsmu_context *smu, * settings. Thus we do not cache it. */ offset_of_featurectrlmask = offsetof(OverDriveTable_t , FeatureCtrlMask); - if (memcmp(od_table + offset_of_featurectrlmask, + if (memcmp((u8 *)od_table + offset_of_featurectrlmask, table_context->user_overdrive_table +
offset_of_featurectrlmask,
sizeof(OverDriveTableExternal_t)-offset_of_featurectrlmask)) { smu_v13_0_7_dump_od_table(smu, od_table); @@ -1537,7 +1537,7 @@ static int smu_v13_0_7_od_edit_dpm_table(struct
smu_context*smu,od_table->OverDriveTable.FeatureCtrlMask = 0; memcpy(table_context->user_overdrive_table +
offset_of_featurectrlmask,drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +1
-1- od_table + offset_of_featurectrlmask, + (u8 *)od_table + offset_of_featurectrlmask, sizeof(OverDriveTableExternal_t) -
offset_of_featurectrlmask);if (!memcmp(table_context->user_overdrive_table,--
2.39.2
Alex Deucher
AppliedApplied. Thanks!
Alex
Quoted 94 lines · Evan
[AMD Official Use Only - General]
Thanks for catching this.
Reviewed-by Evan Quan <[email protected]>Quoted 87 lines
-----Original Message-----
From: Dan Carpenter <[email protected]>
Sent: Tuesday, June 6, 2023 4:34 PM
To: Quan, Evan <[email protected]>
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Pan, Xinhui <[email protected]>; David Airlie <[email protected]>; Daniel Vetter <[email protected]>; Lazar, Lijo <[email protected]>; Zhang, Hawking <[email protected]>; Feng, Kenneth <[email protected]>; Li, Candice <[email protected]>; Chai, Thomas <[email protected]>; Wang, Yang(Kevin) <[email protected]>; Zhang, Horatio <[email protected]>; [email protected]; [email protected]
Subject: [PATCH] drm/amd/pm: Fix memory some memory corruptionThe "
od_table" is a pointer to a large struct, but this code is doing pointer math as if it were pointing to bytes. It results in writing far outside the struct.Fixes f0a0c659fb96 ("drm/amd/pm: fulfill the OD support for SMU13.0.0")Fixes e3afa4f988b3 ("drm/amd/pm: fulfill the OD support for SMU13.0.7")Signed-off-by Dan Carpenter <[email protected]>--- drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c | 4 ++-- drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +1
-1@@ -1535,7 +1535,7 @@ static int smu_v13_0_0_od_edit_dpm_table(structsmu_context *smu, * settings. Thus we do not cache it. */ offset_of_featurectrlmask = offsetof(OverDriveTable_t , FeatureCtrlMask); - if (memcmp(od_table + offset_of_featurectrlmask, + if (memcmp((u8 *)od_table + offset_of_featurectrlmask, table_context->user_overdrive_table +
offset_of_featurectrlmask,
sizeof(OverDriveTableExternal_t)-offset_of_featurectrlmask)) { smu_v13_0_0_dump_od_table(smu, od_table); @@ -1548,7 +1548,7 @@ static int smu_v13_0_0_od_edit_dpm_table(struct
smu_context*smu,od_table->OverDriveTable.FeatureCtrlMask = 0; memcpy(table_context->user_overdrive_table +
offset_of_featurectrlmask,drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +1
-1- od_table + offset_of_featurectrlmask, + (u8 *)od_table + offset_of_featurectrlmask, sizeof(OverDriveTableExternal_t) -
offset_of_featurectrlmask);if (!memcmp(table_context->user_overdrive_table,drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +1
-1@@ -1524,7 +1524,7 @@ static int smu_v13_0_7_od_edit_dpm_table(structsmu_context *smu, * settings. Thus we do not cache it. */ offset_of_featurectrlmask = offsetof(OverDriveTable_t , FeatureCtrlMask); - if (memcmp(od_table + offset_of_featurectrlmask, + if (memcmp((u8 *)od_table + offset_of_featurectrlmask, table_context->user_overdrive_table +
offset_of_featurectrlmask,
sizeof(OverDriveTableExternal_t)-offset_of_featurectrlmask)) { smu_v13_0_7_dump_od_table(smu, od_table); @@ -1537,7 +1537,7 @@ static int smu_v13_0_7_od_edit_dpm_table(struct
smu_context*smu,od_table->OverDriveTable.FeatureCtrlMask = 0; memcpy(table_context->user_overdrive_table +
offset_of_featurectrlmask,drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +1
-1- od_table + offset_of_featurectrlmask, + (u8 *)od_table + offset_of_featurectrlmask, sizeof(OverDriveTableExternal_t) -
offset_of_featurectrlmask);if (!memcmp(table_context->user_overdrive_table,--
2.39.2