Skip to contentSkip to conversation

efi_loader: HII protocols: fix new_package_list()

PATCH New Heinrich Schuchardt 4 participants 5 messages Feb 28, 2019 – Mar 2, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 efi_loader: HII protocols: fix new_package_list()

In new_package_list() we call new_packagelist() to create a new package list. Next we try to add the packages which fails for form packages. Due to this error we call free_packagelist(). Now in free_packagelist() list_del() is called for an uninitialized field hii->link. This leads to changing random memory addresses.

To solve the problem move the initialization of hii->link to new_packagelist().

---
@Takahiro:
Please, review the patch.

---
 lib/efi_loader/efi_hii.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/efi_loader/efi_hii.c +1 -1
index d63d2d84184..0ed4b196333 100644
@@ -343,6 +343,7 @@ static struct efi_hii_packagelist *new_packagelist(void)
 	struct efi_hii_packagelist *hii;
 
 	hii = malloc(sizeof(*hii));
+	list_add_tail(&hii->link, &efi_package_lists);
 	hii->max_string_id = 0;
 	INIT_LIST_HEAD(&hii->string_tables);
 	INIT_LIST_HEAD(&hii->guid_list);
@@ -465,7 +466,6 @@ new_package_list(const struct efi_hii_database_protocol *this,
 	}
 
 	hii->driver_handle = driver_handle;
-	list_add_tail(&hii->link, &efi_package_lists);
 	*handle = hii;
 
 	return EFI_EXIT(EFI_SUCCESS);
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/1 efi_loader: HII protocols: fix new_package_list()

Quoted 6 lines · Heinrich Schuchardt

In new_package_list() we call new_packagelist() to create a new package list. Next we try to add the packages which fails for form packages. Due to this error we call free_packagelist(). Now in free_packagelist() list_del() is called for an uninitialized field hii->link. This leads to changing random memory addresses.

Quoted 7 lines

To solve the problem move the initialization of hii->link to new_packagelist().

---
@Takahiro:
Please, review the patch.

Good catch, thank you.

Quoted 27 lines
---
 lib/efi_loader/efi_hii.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/efi_loader/efi_hii.c +1 -1
index d63d2d84184..0ed4b196333 100644
@@ -343,6 +343,7 @@ static struct efi_hii_packagelist *new_packagelist(void)
 	struct efi_hii_packagelist *hii;
 
 	hii = malloc(sizeof(*hii));
+	list_add_tail(&hii->link, &efi_package_lists);
 	hii->max_string_id = 0;
 	INIT_LIST_HEAD(&hii->string_tables);
 	INIT_LIST_HEAD(&hii->guid_list);
@@ -465,7 +466,6 @@ new_package_list(const struct efi_hii_database_protocol *this,
 	}
 
 	hii->driver_handle = driver_handle;
-	list_add_tail(&hii->link, &efi_package_lists);
 	*handle = hii;
 
 	return EFI_EXIT(EFI_SUCCESS);
Signature · 1 line
2.20.1
#2 lore raw

PATCH 1/1 efi_loader: HII protocols: fix new_package_list()

Quoted 10 lines · AKASHI Takahiro
Quoted 9 lines · Heinrich Schuchardt

In new_package_list() we call new_packagelist() to create a new package list. Next we try to add the packages which fails for form packages. Due to this error we call free_packagelist(). Now in free_packagelist() list_del() is called for an uninitialized field hii->link. This leads to changing random memory addresses.

To solve the problem move the initialization of hii->link to new_packagelist().

Quoted 8 lines
Quoted 4 lines

---
@Takahiro:
Please, review the patch.

Good catch, thank you.

With this patch I no longer experience an error when booting my Odroid C2 via iPXE from an iSCSI disk. So I think in v2019.07 we will can enable the HII protocols by default.

Best regards

Heinrich

#3 lore raw

PATCH 1/1 efi_loader: HII protocols: fix new_package_list()

In reply to Heinrich Schuchardt
Quoted 22 lines · Heinrich Schuchardt

In new_package_list() we call new_packagelist() to create a new package list. Next we try to add the packages which fails for form packages. Due to this error we call free_packagelist(). Now in free_packagelist() list_del() is called for an uninitialized field hii->link. This leads to changing random memory addresses.

To solve the problem move the initialization of hii->link to new_packagelist().

---
@Takahiro:
Please, review the patch.

---
 lib/efi_loader/efi_hii.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/efi_loader/efi_hii.c +0 -0
index d63d2d84184..0ed4b196333 100644

lib/efi_loader/efi_hii.c static struct efi_hii_packagelist *new_packagelist(void) · line 346

Quoted 4 lines
lib/efi_loader/efi_hii.c +1 -0
@@ -343,6 +343,7 @@ static struct efi_hii_packagelist *new_packagelist(void)
 	struct efi_hii_packagelist *hii;
 
 	hii = malloc(sizeof(*hii));
+	list_add_tail(&hii->link, &efi_package_lists);

Why in new_packagelist() and not in new_package_list()?

Alex

Quoted 11 lines
lib/efi_loader/efi_hii.c +0 -1
 	hii->max_string_id = 0;
 	INIT_LIST_HEAD(&hii->string_tables);
 	INIT_LIST_HEAD(&hii->guid_list);
@@ -465,7 +466,6 @@ new_package_list(const struct efi_hii_database_protocol *this,
 	}
 
 	hii->driver_handle = driver_handle;
-	list_add_tail(&hii->link, &efi_package_lists);
 	*handle = hii;
 
 	return EFI_EXIT(EFI_SUCCESS);
#4 lore raw

PATCH 1/1 efi_loader: HII protocols: fix new_package_list()

Quoted 26 lines · Alexander Graf
Quoted 24 lines · Heinrich Schuchardt

In new_package_list() we call new_packagelist() to create a new package list. Next we try to add the packages which fails for form packages. Due to this error we call free_packagelist(). Now in free_packagelist() list_del() is called for an uninitialized field hii->link. This leads to changing random memory addresses.

To solve the problem move the initialization of hii->link to new_packagelist().

---
@Takahiro:
Please, review the patch.

---
 lib/efi_loader/efi_hii.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/efi_loader/efi_hii.c +0 -0
index d63d2d84184..0ed4b196333 100644
@@ -343,6 +343,7 @@ static struct efi_hii_packagelist *new_packagelist(void)
 	struct efi_hii_packagelist *hii;
 
Quoted 5 lines

lib/efi_loader/efi_hii.c static struct efi_hii_packagelist *new_packagelist(void) · line 346

Quoted 2 lines
lib/efi_loader/efi_hii.c +1 -0
 	hii = malloc(sizeof(*hii));
+	list_add_tail(&hii->link, &efi_package_lists);

Why in new_packagelist() and not in new_package_list()?

The important thing is that we do not call list_del() before list_add_tail().

new_packagelist() is only called by new_package_list(). So you could move any line of new_packagelist() to new_package_list().

But I see new_packagelist as the counterpart of free_packagelist(). So it seems natural to put list_add_tail() into new_packagelist() to match the list_del() in free_packagelist().

Anything specific you dislike about it?

Best regards

Heinrich

Quoted 21 lines

Alex

lib/efi_loader/efi_hii.c new_package_list(const struct efi_hii_database_protocol *this, · line 471

Quoted 11 lines
lib/efi_loader/efi_hii.c +0 -1
 	hii->max_string_id = 0;
 	INIT_LIST_HEAD(&hii->string_tables);
 	INIT_LIST_HEAD(&hii->guid_list);
@@ -465,7 +466,6 @@ new_package_list(const struct efi_hii_database_protocol *this,
 	}
 
 	hii->driver_handle = driver_handle;
-	list_add_tail(&hii->link, &efi_package_lists);
 	*handle = hii;
 
 	return EFI_EXIT(EFI_SUCCESS);

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
https://lists.denx.de/listinfo/u-boot