Skip to contentSkip to conversation

efi_loader: run CreateEvent() notify function based on flags

PATCH New Jonathan Gray 3 participants 8 messages Mar 12, 2017 – Jul 3, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 efi_loader: run CreateEvent() notify function based on flags

The UEFI specification states that the tpl, function and context arguments are to be ignored if neither EVT_NOTIFY_WAIT or EVT_NOTIFY_SIGNAL are specified. This matches observed behaviour with an AMI EDK2 based UEFI implementation.

Skip calling the notify function if neither flag is present.

---
 include/efi_api.h             | 3 +++
 lib/efi_loader/efi_boottime.c | 4 +++-
 2 files changed, 6 insertions(+), 1 deletion(-)
include/efi_api.h +3 -0
index 5c3836a51b..f071b36b53 100644
@@ -28,6 +28,9 @@ enum efi_event_type {
 	EFI_TIMER_RELATIVE = 2
 };
 
+#define EVT_NOTIFY_WAIT		0x00000100
+#define EVT_NOTIFY_SIGNAL	0x00000200
+
 /* EFI Boot Services table */
 struct efi_boot_services {
 	struct efi_table_hdr hdr;
lib/efi_loader/efi_boottime.c +3 -1
index 51080cbeed..eb5946a959 100644
@@ -210,7 +210,9 @@ void efi_timer_check(void)
 		/* Triggering! */
 		if (efi_event.trigger_type == EFI_TIMER_PERIODIC)
 			efi_event.trigger_next += efi_event.trigger_time / 10;
-		efi_event.notify_function(&efi_event, efi_event.notify_context);
+		if (efi_event.type & (EVT_NOTIFY_WAIT | EVT_NOTIFY_SIGNAL))
+			efi_event.notify_function(&efi_event,
+			                          efi_event.notify_context);
 	}
 
 	WATCHDOG_RESET();
Signature · 1 line
2.12.0
#1 lore raw

PATCH 2/2 efi_loader: check CreateEvent() parameters

Add some of the invalid parameter checks described in the UEFI specification for CreateEvent(). This does not include checking the validity of the type and tpl parameters.

---
 lib/efi_loader/efi_boottime.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
lib/efi_loader/efi_boottime.c +10 -0
index eb5946a959..7172b690a5 100644
@@ -189,6 +189,16 @@ static efi_status_t EFIAPI efi_create_event(
 		return EFI_EXIT(EFI_OUT_OF_RESOURCES);
 	}
 
+	if (event == NULL)
+		return EFI_EXIT(EFI_INVALID_PARAMETER);
+
+	if ((type & EVT_NOTIFY_SIGNAL) && (type & EVT_NOTIFY_WAIT))
+		return EFI_EXIT(EFI_INVALID_PARAMETER);
+
+	if ((type & (EVT_NOTIFY_SIGNAL|EVT_NOTIFY_WAIT)) &&
+	     notify_function == NULL)
+		return EFI_EXIT(EFI_INVALID_PARAMETER);
+
 	efi_event.type = type;
 	efi_event.notify_tpl = notify_tpl;
 	efi_event.notify_function = notify_function;
Signature · 1 line
2.12.0
#2 lore raw

PATCH 2/2 efi_loader: check CreateEvent() parameters

Quoted 21 lines · Jonathan Gray

Add some of the invalid parameter checks described in the UEFI specification for CreateEvent(). This does not include checking the validity of the type and tpl parameters.

---
 lib/efi_loader/efi_boottime.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
lib/efi_loader/efi_boottime.c +3 -0
index eb5946a959..7172b690a5 100644
@@ -189,6 +189,16 @@ static efi_status_t EFIAPI efi_create_event(
 		return EFI_EXIT(EFI_OUT_OF_RESOURCES);
 	}
 
+	if (event == NULL)
+		return EFI_EXIT(EFI_INVALID_PARAMETER);
+

lib/efi_loader/efi_boottime.c static efi_status_t EFIAPI efi_create_event( · line 204

Quoted 10 lines
lib/efi_loader/efi_boottime.c +7 -0
+	if ((type & EVT_NOTIFY_SIGNAL) && (type & EVT_NOTIFY_WAIT))
+		return EFI_EXIT(EFI_INVALID_PARAMETER);
+
+	if ((type & (EVT_NOTIFY_SIGNAL|EVT_NOTIFY_WAIT)) &&
+	     notify_function == NULL)
+		return EFI_EXIT(EFI_INVALID_PARAMETER);
+
 	efi_event.type = type;
 	efi_event.notify_tpl = notify_tpl;
 	efi_event.notify_function = notify_function;

In case of EVT_NOTIFY_WAIT we should also check if the event is already in the signaled state. But this flag is not implemented yet.

#3 lore raw

[U-Boot] Pull request: efi_loader: check CreateEvent() parameters

Dear Tom,

could you, please, consider pulling

[U-Boot,1/2] efi_loader: run CreateEvent() notify function based on flags
https://patchwork.ozlabs.org/patch/737793/

[U-Boot,2/2] efi_loader: check CreateEvent() parameters
https://patchwork.ozlabs.org/patch/737794/

I have reviewed the patches and tested loading grub via EFI on an Odroid C2 based on git HEAD (8d6040c725bfa40fba1bd6b5f356ee713c1ac7d1).

Best regards

Heinrich Schuchardt

Quoted 38 lines · Heinrich Schuchardt
Quoted 21 lines · Jonathan Gray

Add some of the invalid parameter checks described in the UEFI specification for CreateEvent(). This does not include checking the validity of the type and tpl parameters.

---
 lib/efi_loader/efi_boottime.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
lib/efi_loader/efi_boottime.c +3 -0
index eb5946a959..7172b690a5 100644
@@ -189,6 +189,16 @@ static efi_status_t EFIAPI efi_create_event(
 		return EFI_EXIT(EFI_OUT_OF_RESOURCES);
 	}
 
+	if (event == NULL)
+		return EFI_EXIT(EFI_INVALID_PARAMETER);
+

lib/efi_loader/efi_boottime.c static efi_status_t EFIAPI efi_create_event( · line 204

Quoted 10 lines
lib/efi_loader/efi_boottime.c +7 -0
+	if ((type & EVT_NOTIFY_SIGNAL) && (type & EVT_NOTIFY_WAIT))
+		return EFI_EXIT(EFI_INVALID_PARAMETER);
+
+	if ((type & (EVT_NOTIFY_SIGNAL|EVT_NOTIFY_WAIT)) &&
+	     notify_function == NULL)
+		return EFI_EXIT(EFI_INVALID_PARAMETER);
+
 	efi_event.type = type;
 	efi_event.notify_tpl = notify_tpl;
 	efi_event.notify_function = notify_function;

In case of EVT_NOTIFY_WAIT we should also check if the event is already in the signaled state. But this flag is not implemented yet.

#4 lore raw

[U-Boot] Pull request: efi_loader: check CreateEvent() parameters

Hi Heinrich,

Thanks a lot for the reminder email. I'll get them integrated asap.

Alex

Quoted 56 lines · Heinrich Schuchardt

Dear Tom,

could you, please, consider pulling

[U-Boot,1/2] efi_loader: run CreateEvent() notify function based on flags
https://patchwork.ozlabs.org/patch/737793/

[U-Boot,2/2] efi_loader: check CreateEvent() parameters
https://patchwork.ozlabs.org/patch/737794/

I have reviewed the patches and tested loading grub via EFI on an Odroid C2 based on git HEAD (8d6040c725bfa40fba1bd6b5f356ee713c1ac7d1).

Best regards

Heinrich Schuchardt

Quoted 37 lines · Heinrich Schuchardt
Quoted 21 lines · Jonathan Gray

Add some of the invalid parameter checks described in the UEFI specification for CreateEvent(). This does not include checking the validity of the type and tpl parameters.

---
  lib/efi_loader/efi_boottime.c | 10 ++++++++++
  1 file changed, 10 insertions(+)
lib/efi_loader/efi_boottime.c +3 -0
index eb5946a959..7172b690a5 100644
@@ -189,6 +189,16 @@ static efi_status_t EFIAPI efi_create_event(
  		return EFI_EXIT(EFI_OUT_OF_RESOURCES);
  	}
 
+	if (event == NULL)
+		return EFI_EXIT(EFI_INVALID_PARAMETER);
+

lib/efi_loader/efi_boottime.c static efi_status_t EFIAPI efi_create_event( · line 204

Quoted 10 lines
lib/efi_loader/efi_boottime.c +7 -0
+	if ((type & EVT_NOTIFY_SIGNAL) && (type & EVT_NOTIFY_WAIT))
+		return EFI_EXIT(EFI_INVALID_PARAMETER);
+
+	if ((type & (EVT_NOTIFY_SIGNAL|EVT_NOTIFY_WAIT)) &&
+	     notify_function == NULL)
+		return EFI_EXIT(EFI_INVALID_PARAMETER);
+
  	efi_event.type = type;
  	efi_event.notify_tpl = notify_tpl;
  	efi_event.notify_function = notify_function;

In case of EVT_NOTIFY_WAIT we should also check if the event is already in the signaled state. But this flag is not implemented yet.

#6 lore raw

PATCH 1/2 efi_loader: run CreateEvent() notify function based on flags

In reply to Jonathan Gray
Quoted 8 lines · Jonathan Gray

The UEFI specification states that the tpl, function and context arguments are to be ignored if neither EVT_NOTIFY_WAIT or EVT_NOTIFY_SIGNAL are specified. This matches observed behaviour with an AMI EDK2 based UEFI implementation.

Skip calling the notify function if neither flag is present.

In case of EVT_NOTIFY_WAIT we should also check if the event is already in the signaled state. But this flag is not implemented yet. Couldn't you implement that flag first?

Quoted 35 lines
---
 include/efi_api.h             | 3 +++
 lib/efi_loader/efi_boottime.c | 4 +++-
 2 files changed, 6 insertions(+), 1 deletion(-)
include/efi_api.h +3 -0
index 5c3836a51b..f071b36b53 100644
@@ -28,6 +28,9 @@ enum efi_event_type {
 	EFI_TIMER_RELATIVE = 2
 };
 
+#define EVT_NOTIFY_WAIT		0x00000100
+#define EVT_NOTIFY_SIGNAL	0x00000200
+
 /* EFI Boot Services table */
 struct efi_boot_services {
 	struct efi_table_hdr hdr;
lib/efi_loader/efi_boottime.c +3 -1
index 51080cbeed..eb5946a959 100644
@@ -210,7 +210,9 @@ void efi_timer_check(void)
 		/* Triggering! */
 		if (efi_event.trigger_type == EFI_TIMER_PERIODIC)
 			efi_event.trigger_next += efi_event.trigger_time / 10;
-		efi_event.notify_function(&efi_event, efi_event.notify_context);
+		if (efi_event.type & (EVT_NOTIFY_WAIT | EVT_NOTIFY_SIGNAL))
+			efi_event.notify_function(&efi_event,
+			                          efi_event.notify_context);
 	}
 
 	WATCHDOG_RESET();
#7 lore raw

PATCH 1/2 efi_loader: run CreateEvent() notify function based on flags

In reply to Jonathan Gray
Quoted 9 lines

The UEFI specification states that the tpl, function and context arguments are to be ignored if neither EVT_NOTIFY_WAIT or EVT_NOTIFY_SIGNAL are specified. This matches observed behaviour with an AMI EDK2 based UEFI implementation.

Skip calling the notify function if neither flag is present.

Thanks, applied to efi-next

Alex