Skip to content

Commit 72a4c41

Browse files
committed
shim: change automatically enable MOK_POLICY_REQUIRE_NX
Currently whether shim enforces NX on its downstream consumers is set at build time. It would be better for this to be automatically detected and enforced. This patch changes the policy to be dynamically detected. In the case where shim has the NX bit set and the system has an appropriate protocol installed *and* appears to be enforcing NX, we enable the MOK policy bit to require NX. Signed-off-by: Peter Jones <pjones@redhat.com>
1 parent 9ebab84 commit 72a4c41

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

include/memattrs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ extern EFI_STATUS update_mem_attrs(uintptr_t addr, uint64_t size,
1313

1414
extern void get_hsi_mem_info(void);
1515
extern char *decode_hsi_bits(UINTN hsi);
16+
extern void set_shim_nx_policy(void);
1617

1718
#endif /* !SHIM_MEMATTRS_H_ */
1819
// vim:fenc=utf-8:tw=75:noet

pe-relocate.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,5 +661,32 @@ get_shim_nx_capability(EFI_HANDLE image_handle)
661661
}
662662
}
663663

664+
static inline bool
665+
hsi_nx_is_enforced(void)
666+
{
667+
return !((hsi_status & SHIM_HSI_STATUS_HEAPX) ||
668+
(hsi_status & SHIM_HSI_STATUS_STACKX) ||
669+
(hsi_status & SHIM_HSI_STATUS_ROW));
670+
}
671+
672+
static inline bool
673+
hsi_api_is_present(void)
674+
{
675+
return (hsi_status & SHIM_HSI_STATUS_HASMAP) ||
676+
((hsi_status & SHIM_HSI_STATUS_HASDSTGMSD &&
677+
hsi_status & SHIM_HSI_STATUS_HASDSTSMSA));
678+
}
679+
680+
void
681+
set_shim_nx_policy(void)
682+
{
683+
if ((hsi_status & SHIM_HSI_STATUS_NX) &&
684+
hsi_nx_is_enforced() &&
685+
hsi_api_is_present())
686+
{
687+
mok_policy |= MOK_POLICY_REQUIRE_NX;
688+
dprint("Enforcing NX policy for all images\n");
689+
}
690+
}
664691

665692
// vim:fenc=utf-8:tw=75:noet

shim.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,6 +1238,7 @@ efi_main (EFI_HANDLE passed_image_handle, EFI_SYSTEM_TABLE *passed_systab)
12381238

12391239
init_openssl();
12401240
get_hsi_mem_info();
1241+
set_shim_nx_policy();
12411242

12421243
efi_status = load_unbundled_trust(global_image_handle);
12431244
if (EFI_ERROR(efi_status)) {

0 commit comments

Comments
 (0)