Message ID | 20250327040435.2470-1-hanchunchao@inspur.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | drm/amd/pp: Fix potential NULL pointer dereference in atomctrl_initialize_mc_reg_table | expand |
[Public] > -----Original Message----- > From: Charles Han <hanchunchao@inspur.com> > Sent: Thursday, March 27, 2025 12:05 AM > To: Feng, Kenneth <Kenneth.Feng@amd.com>; Deucher, Alexander > <Alexander.Deucher@amd.com>; Koenig, Christian > <Christian.Koenig@amd.com>; airlied@gmail.com; simona@ffwll.ch; > sid@itb.spb.ru; Huang, Tim <Tim.Huang@amd.com>; Zhang, Jesse(Jie) > <Jesse.Zhang@amd.com>; linux@treblig.org; Huang, Ray > <Ray.Huang@amd.com>; Rex.Zhu@amd.com; evan.quan@amd.com > Cc: amd-gfx@lists.freedesktop.org; dri-devel@lists.freedesktop.org; Charles Han > <hanchunchao@inspur.com> > Subject: [PATCH] drm/amd/pp: Fix potential NULL pointer dereference in > atomctrl_initialize_mc_reg_table > > The function atomctrl_initialize_mc_reg_table() and > atomctrl_initialize_mc_reg_table_v2_2() does not check the return value of > smu_atom_get_data_table(). If smu_atom_get_data_table() fails to retrieve > vram_info, it returns NULL which is later dereferenced. > > Fixes: b3892e2bb519 ("drm/amd/pp: Use atombios api directly in powerplay (v2)") > Fixes: 5f92b48cf62c ("drm/amd/pm: add mc register table initialization") > Signed-off-by: Charles Han <hanchunchao@inspur.com> Applied. Thanks! Alex > --- > drivers/gpu/drm/amd/pm/powerplay/hwmgr/ppatomctrl.c | 8 ++++++++ > 1 file changed, 8 insertions(+) > > diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/ppatomctrl.c > b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/ppatomctrl.c > index 4bd92fd782be..8d40ed0f0e83 100644 > --- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/ppatomctrl.c > +++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/ppatomctrl.c > @@ -143,6 +143,10 @@ int atomctrl_initialize_mc_reg_table( > vram_info = (ATOM_VRAM_INFO_HEADER_V2_1 *) > smu_atom_get_data_table(hwmgr->adev, > GetIndexIntoMasterTable(DATA, VRAM_Info), &size, > &frev, &crev); > + if (!vram_info) { > + pr_err("Could not retrieve the VramInfo table!"); > + return -EINVAL; > + } > > if (module_index >= vram_info->ucNumOfVRAMModule) { > pr_err("Invalid VramInfo table."); > @@ -180,6 +184,10 @@ int atomctrl_initialize_mc_reg_table_v2_2( > vram_info = (ATOM_VRAM_INFO_HEADER_V2_2 *) > smu_atom_get_data_table(hwmgr->adev, > GetIndexIntoMasterTable(DATA, VRAM_Info), &size, > &frev, &crev); > + if (!vram_info) { > + pr_err("Could not retrieve the VramInfo table!"); > + return -EINVAL; > + } > > if (module_index >= vram_info->ucNumOfVRAMModule) { > pr_err("Invalid VramInfo table."); > -- > 2.43.0
diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/ppatomctrl.c b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/ppatomctrl.c index 4bd92fd782be..8d40ed0f0e83 100644 --- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/ppatomctrl.c +++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/ppatomctrl.c @@ -143,6 +143,10 @@ int atomctrl_initialize_mc_reg_table( vram_info = (ATOM_VRAM_INFO_HEADER_V2_1 *) smu_atom_get_data_table(hwmgr->adev, GetIndexIntoMasterTable(DATA, VRAM_Info), &size, &frev, &crev); + if (!vram_info) { + pr_err("Could not retrieve the VramInfo table!"); + return -EINVAL; + } if (module_index >= vram_info->ucNumOfVRAMModule) { pr_err("Invalid VramInfo table."); @@ -180,6 +184,10 @@ int atomctrl_initialize_mc_reg_table_v2_2( vram_info = (ATOM_VRAM_INFO_HEADER_V2_2 *) smu_atom_get_data_table(hwmgr->adev, GetIndexIntoMasterTable(DATA, VRAM_Info), &size, &frev, &crev); + if (!vram_info) { + pr_err("Could not retrieve the VramInfo table!"); + return -EINVAL; + } if (module_index >= vram_info->ucNumOfVRAMModule) { pr_err("Invalid VramInfo table.");
The function atomctrl_initialize_mc_reg_table() and atomctrl_initialize_mc_reg_table_v2_2() does not check the return value of smu_atom_get_data_table(). If smu_atom_get_data_table() fails to retrieve vram_info, it returns NULL which is later dereferenced. Fixes: b3892e2bb519 ("drm/amd/pp: Use atombios api directly in powerplay (v2)") Fixes: 5f92b48cf62c ("drm/amd/pm: add mc register table initialization") Signed-off-by: Charles Han <hanchunchao@inspur.com> --- drivers/gpu/drm/amd/pm/powerplay/hwmgr/ppatomctrl.c | 8 ++++++++ 1 file changed, 8 insertions(+)