Skip to content

Commit fa47554

Browse files
YadongQiacrnsi
authored andcommitted
hv: seed: fix potential NULL pointer dereferencing
The 'boot_params' and 'entry' might be dereferenced after they were positively checked for NULL. Refine checking logic to fix the issue. Tracked-On: #2979 Signed-off-by: Qi Yadong <yadong.qi@intel.com> Acked-by: Zhu Bing <bing.zhu@intel.com>
1 parent 334c5ae commit fa47554

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

hypervisor/arch/x86/seed/seed_sbl.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,21 @@ bool parse_seed_sbl(uint64_t addr, struct physical_seed *phy_seed)
6262
{
6363
uint8_t i;
6464
uint8_t dseed_index = 0U;
65-
struct image_boot_params *boot_params;
65+
struct image_boot_params *boot_params = NULL;
6666
struct seed_list_hob *seed_hob = NULL;
67-
struct seed_entry *entry;
68-
struct seed_info *seed_list;
67+
struct seed_entry *entry = NULL;
68+
struct seed_info *seed_list = NULL;
6969
bool status = false;
7070

7171
stac();
7272

7373
boot_params = (struct image_boot_params *)hpa2hva(addr);
7474

75-
if ((boot_params != NULL) || (phy_seed != NULL)) {
75+
if (boot_params != NULL) {
7676
seed_hob = (struct seed_list_hob *)hpa2hva(boot_params->p_seed_list);
7777
}
7878

79-
if (seed_hob != NULL) {
79+
if ((seed_hob != NULL) && (phy_seed != NULL)) {
8080
status = true;
8181

8282
seed_list = phy_seed->seed_list;
@@ -106,9 +106,9 @@ bool parse_seed_sbl(uint64_t addr, struct physical_seed *phy_seed)
106106
/* erase original seed in seed entry */
107107
(void)memset((void *)&entry->seed[0U], 0U, sizeof(struct seed_info));
108108
}
109-
}
110109

111-
entry = (struct seed_entry *)((uint8_t *)entry + entry->seed_entry_size);
110+
entry = (struct seed_entry *)((uint8_t *)entry + entry->seed_entry_size);
111+
}
112112
}
113113

114114
if (status) {

0 commit comments

Comments
 (0)