All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] x86/xen/efi: Initialize UEFI secure boot state during dom0 boot
@ 2018-04-03 14:39 Daniel Kiper
  2018-04-03 15:44 ` James Bottomley
  2018-04-03 15:44 ` James Bottomley
  0 siblings, 2 replies; 16+ messages in thread
From: Daniel Kiper @ 2018-04-03 14:39 UTC (permalink / raw)
  To: linux-efi, linux-kernel, x86, xen-devel
  Cc: ard.biesheuvel, boris.ostrovsky, eric.snowberg, hpa, jgross,
	konrad.wilk, mingo, tglx

Initialize UEFI secure boot state during dom0 boot. Otherwise the kernel
may not even know that it runs on secure boot enabled platform.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
---
 arch/x86/xen/efi.c                        |   57 +++++++++++++++++++++++++++++
 drivers/firmware/efi/libstub/secureboot.c |    3 ++
 2 files changed, 60 insertions(+)

diff --git a/arch/x86/xen/efi.c b/arch/x86/xen/efi.c
index a18703b..1804b27 100644
--- a/arch/x86/xen/efi.c
+++ b/arch/x86/xen/efi.c
@@ -115,6 +115,61 @@ static efi_system_table_t __init *xen_efi_probe(void)
 	return &efi_systab_xen;
 }
 
+/*
+ * Determine whether we're in secure boot mode.
+ *
+ * Please keep the logic in sync with
+ * drivers/firmware/efi/libstub/secureboot.c:efi_get_secureboot().
+ */
+static enum efi_secureboot_mode xen_efi_get_secureboot(void)
+{
+	static efi_guid_t efi_variable_guid = EFI_GLOBAL_VARIABLE_GUID;
+	static efi_guid_t shim_guid = EFI_SHIM_LOCK_GUID;
+	efi_status_t status;
+	u8 moksbstate, secboot, setupmode;
+	unsigned long size;
+
+	size = sizeof(secboot);
+	status = efi.get_variable(L"SecureBoot", &efi_variable_guid,
+				  NULL, &size, &secboot);
+
+	if (status == EFI_NOT_FOUND)
+		return efi_secureboot_mode_disabled;
+
+	if (status != EFI_SUCCESS)
+		goto out_efi_err;
+
+	size = sizeof(setupmode);
+	status = efi.get_variable(L"SetupMode", &efi_variable_guid,
+				  NULL, &size, &setupmode);
+
+	if (status != EFI_SUCCESS)
+		goto out_efi_err;
+
+	if (secboot == 0 || setupmode == 1)
+		return efi_secureboot_mode_disabled;
+
+	/* See if a user has put the shim into insecure mode. */
+	size = sizeof(moksbstate);
+	status = efi.get_variable(L"MokSBStateRT", &shim_guid,
+				  NULL, &size, &moksbstate);
+
+	/* If it fails, we don't care why. Default to secure. */
+	if (status != EFI_SUCCESS)
+		goto secure_boot_enabled;
+
+	if (moksbstate == 1)
+		return efi_secureboot_mode_disabled;
+
+ secure_boot_enabled:
+	pr_info("UEFI Secure Boot is enabled.\n");
+	return efi_secureboot_mode_enabled;
+
+ out_efi_err:
+	pr_err("Could not determine UEFI Secure Boot status.\n");
+	return efi_secureboot_mode_unknown;
+}
+
 void __init xen_efi_init(void)
 {
 	efi_system_table_t *efi_systab_xen;
@@ -129,6 +184,8 @@ void __init xen_efi_init(void)
 	boot_params.efi_info.efi_systab = (__u32)__pa(efi_systab_xen);
 	boot_params.efi_info.efi_systab_hi = (__u32)(__pa(efi_systab_xen) >> 32);
 
+	boot_params.secure_boot = xen_efi_get_secureboot();
+
 	set_bit(EFI_BOOT, &efi.flags);
 	set_bit(EFI_PARAVIRT, &efi.flags);
 	set_bit(EFI_64BIT, &efi.flags);
diff --git a/drivers/firmware/efi/libstub/secureboot.c b/drivers/firmware/efi/libstub/secureboot.c
index 8f07eb4..72d9dfb 100644
--- a/drivers/firmware/efi/libstub/secureboot.c
+++ b/drivers/firmware/efi/libstub/secureboot.c
@@ -30,6 +30,9 @@
 
 /*
  * Determine whether we're in secure boot mode.
+ *
+ * Please keep the logic in sync with
+ * arch/x86/xen/efi.c:xen_efi_get_secureboot().
  */
 enum efi_secureboot_mode efi_get_secureboot(efi_system_table_t *sys_table_arg)
 {
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH v2] x86/xen/efi: Initialize UEFI secure boot state during dom0 boot
  2018-04-03 14:39 [PATCH v2] x86/xen/efi: Initialize UEFI secure boot state during dom0 boot Daniel Kiper
@ 2018-04-03 15:44 ` James Bottomley
  2018-04-03 16:07   ` Daniel Kiper
  2018-04-03 16:07   ` Daniel Kiper
  2018-04-03 15:44 ` James Bottomley
  1 sibling, 2 replies; 16+ messages in thread
From: James Bottomley @ 2018-04-03 15:44 UTC (permalink / raw)
  To: Daniel Kiper, linux-efi, linux-kernel, x86, xen-devel
  Cc: ard.biesheuvel, boris.ostrovsky, eric.snowberg, hpa, jgross,
	konrad.wilk, mingo, tglx

On Tue, 2018-04-03 at 16:39 +0200, Daniel Kiper wrote:
> Initialize UEFI secure boot state during dom0 boot. Otherwise the
> kernel
> may not even know that it runs on secure boot enabled platform.
> 
> Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
> ---
>  arch/x86/xen/efi.c                        |   57
> +++++++++++++++++++++++++++++
>  drivers/firmware/efi/libstub/secureboot.c |    3 ++
>  2 files changed, 60 insertions(+)
> 
> diff --git a/arch/x86/xen/efi.c b/arch/x86/xen/efi.c
> index a18703b..1804b27 100644
> --- a/arch/x86/xen/efi.c
> +++ b/arch/x86/xen/efi.c
> @@ -115,6 +115,61 @@ static efi_system_table_t __init
> *xen_efi_probe(void)
>  	return &efi_systab_xen;
>  }
>  
> +/*
> + * Determine whether we're in secure boot mode.
> + *
> + * Please keep the logic in sync with
> + * drivers/firmware/efi/libstub/secureboot.c:efi_get_secureboot().
> + */
> +static enum efi_secureboot_mode xen_efi_get_secureboot(void)
> +{
> +	static efi_guid_t efi_variable_guid =
> EFI_GLOBAL_VARIABLE_GUID;
> +	static efi_guid_t shim_guid = EFI_SHIM_LOCK_GUID;
> +	efi_status_t status;
> +	u8 moksbstate, secboot, setupmode;
> +	unsigned long size;
> +
> +	size = sizeof(secboot);
> +	status = efi.get_variable(L"SecureBoot", &efi_variable_guid,
> +				  NULL, &size, &secboot);
> +
> +	if (status == EFI_NOT_FOUND)
> +		return efi_secureboot_mode_disabled;
> +
> +	if (status != EFI_SUCCESS)
> +		goto out_efi_err;
> +
> +	size = sizeof(setupmode);
> +	status = efi.get_variable(L"SetupMode", &efi_variable_guid,
> +				  NULL, &size, &setupmode);
> +
> +	if (status != EFI_SUCCESS)
> +		goto out_efi_err;
> +
> +	if (secboot == 0 || setupmode == 1)
> +		return efi_secureboot_mode_disabled;
> +
> +	/* See if a user has put the shim into insecure mode. */
> +	size = sizeof(moksbstate);
> +	status = efi.get_variable(L"MokSBStateRT", &shim_guid,
> +				  NULL, &size, &moksbstate);
> +
> +	/* If it fails, we don't care why. Default to secure. */
> +	if (status != EFI_SUCCESS)
> +		goto secure_boot_enabled;
> +
> +	if (moksbstate == 1)
> +		return efi_secureboot_mode_disabled;
> +
> + secure_boot_enabled:
> +	pr_info("UEFI Secure Boot is enabled.\n");
> +	return efi_secureboot_mode_enabled;
> +
> + out_efi_err:
> +	pr_err("Could not determine UEFI Secure Boot status.\n");
> +	return efi_secureboot_mode_unknown;
> +}
> +

This looks like a bad idea: you're duplicating the secure boot check in

drivers/firmware/efi/libstub/secureboot.c

Which is an implementation of policy.  If we have to have policy in the
kernel, it should really only be in one place to prevent drift; why
can't you simply use the libstub efi_get_secureboot() so we're not
duplicating the implementation of policy?

James

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2] x86/xen/efi: Initialize UEFI secure boot state during dom0 boot
  2018-04-03 14:39 [PATCH v2] x86/xen/efi: Initialize UEFI secure boot state during dom0 boot Daniel Kiper
  2018-04-03 15:44 ` James Bottomley
@ 2018-04-03 15:44 ` James Bottomley
  1 sibling, 0 replies; 16+ messages in thread
From: James Bottomley @ 2018-04-03 15:44 UTC (permalink / raw)
  To: Daniel Kiper, linux-efi, linux-kernel, x86, xen-devel
  Cc: jgross, eric.snowberg, ard.biesheuvel, mingo, hpa, boris.ostrovsky, tglx

On Tue, 2018-04-03 at 16:39 +0200, Daniel Kiper wrote:
> Initialize UEFI secure boot state during dom0 boot. Otherwise the
> kernel
> may not even know that it runs on secure boot enabled platform.
> 
> Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
> ---
>  arch/x86/xen/efi.c                        |   57
> +++++++++++++++++++++++++++++
>  drivers/firmware/efi/libstub/secureboot.c |    3 ++
>  2 files changed, 60 insertions(+)
> 
> diff --git a/arch/x86/xen/efi.c b/arch/x86/xen/efi.c
> index a18703b..1804b27 100644
> --- a/arch/x86/xen/efi.c
> +++ b/arch/x86/xen/efi.c
> @@ -115,6 +115,61 @@ static efi_system_table_t __init
> *xen_efi_probe(void)
>  	return &efi_systab_xen;
>  }
>  
> +/*
> + * Determine whether we're in secure boot mode.
> + *
> + * Please keep the logic in sync with
> + * drivers/firmware/efi/libstub/secureboot.c:efi_get_secureboot().
> + */
> +static enum efi_secureboot_mode xen_efi_get_secureboot(void)
> +{
> +	static efi_guid_t efi_variable_guid =
> EFI_GLOBAL_VARIABLE_GUID;
> +	static efi_guid_t shim_guid = EFI_SHIM_LOCK_GUID;
> +	efi_status_t status;
> +	u8 moksbstate, secboot, setupmode;
> +	unsigned long size;
> +
> +	size = sizeof(secboot);
> +	status = efi.get_variable(L"SecureBoot", &efi_variable_guid,
> +				  NULL, &size, &secboot);
> +
> +	if (status == EFI_NOT_FOUND)
> +		return efi_secureboot_mode_disabled;
> +
> +	if (status != EFI_SUCCESS)
> +		goto out_efi_err;
> +
> +	size = sizeof(setupmode);
> +	status = efi.get_variable(L"SetupMode", &efi_variable_guid,
> +				  NULL, &size, &setupmode);
> +
> +	if (status != EFI_SUCCESS)
> +		goto out_efi_err;
> +
> +	if (secboot == 0 || setupmode == 1)
> +		return efi_secureboot_mode_disabled;
> +
> +	/* See if a user has put the shim into insecure mode. */
> +	size = sizeof(moksbstate);
> +	status = efi.get_variable(L"MokSBStateRT", &shim_guid,
> +				  NULL, &size, &moksbstate);
> +
> +	/* If it fails, we don't care why. Default to secure. */
> +	if (status != EFI_SUCCESS)
> +		goto secure_boot_enabled;
> +
> +	if (moksbstate == 1)
> +		return efi_secureboot_mode_disabled;
> +
> + secure_boot_enabled:
> +	pr_info("UEFI Secure Boot is enabled.\n");
> +	return efi_secureboot_mode_enabled;
> +
> + out_efi_err:
> +	pr_err("Could not determine UEFI Secure Boot status.\n");
> +	return efi_secureboot_mode_unknown;
> +}
> +

This looks like a bad idea: you're duplicating the secure boot check in

drivers/firmware/efi/libstub/secureboot.c

Which is an implementation of policy.  If we have to have policy in the
kernel, it should really only be in one place to prevent drift; why
can't you simply use the libstub efi_get_secureboot() so we're not
duplicating the implementation of policy?

James


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2] x86/xen/efi: Initialize UEFI secure boot state during dom0 boot
  2018-04-03 15:44 ` James Bottomley
@ 2018-04-03 16:07   ` Daniel Kiper
  2018-04-03 17:00     ` James Bottomley
  2018-04-03 17:00     ` James Bottomley
  2018-04-03 16:07   ` Daniel Kiper
  1 sibling, 2 replies; 16+ messages in thread
From: Daniel Kiper @ 2018-04-03 16:07 UTC (permalink / raw)
  To: James Bottomley
  Cc: linux-efi, linux-kernel, x86, xen-devel, ard.biesheuvel,
	boris.ostrovsky, eric.snowberg, hpa, jgross, konrad.wilk, mingo,
	tglx

On Tue, Apr 03, 2018 at 08:44:41AM -0700, James Bottomley wrote:
> On Tue, 2018-04-03 at 16:39 +0200, Daniel Kiper wrote:
> > Initialize UEFI secure boot state during dom0 boot. Otherwise the
> > kernel
> > may not even know that it runs on secure boot enabled platform.
> >
> > Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
> > ---
> >  arch/x86/xen/efi.c                        |   57
> > +++++++++++++++++++++++++++++
> >  drivers/firmware/efi/libstub/secureboot.c |    3 ++
> >  2 files changed, 60 insertions(+)
> >
> > diff --git a/arch/x86/xen/efi.c b/arch/x86/xen/efi.c
> > index a18703b..1804b27 100644
> > --- a/arch/x86/xen/efi.c
> > +++ b/arch/x86/xen/efi.c
> > @@ -115,6 +115,61 @@ static efi_system_table_t __init
> > *xen_efi_probe(void)
> >  	return &efi_systab_xen;
> >  }
> >  
> > +/*
> > + * Determine whether we're in secure boot mode.
> > + *
> > + * Please keep the logic in sync with
> > + * drivers/firmware/efi/libstub/secureboot.c:efi_get_secureboot().
> > + */
> > +static enum efi_secureboot_mode xen_efi_get_secureboot(void)
> > +{
> > +	static efi_guid_t efi_variable_guid =
> > EFI_GLOBAL_VARIABLE_GUID;
> > +	static efi_guid_t shim_guid = EFI_SHIM_LOCK_GUID;
> > +	efi_status_t status;
> > +	u8 moksbstate, secboot, setupmode;
> > +	unsigned long size;
> > +
> > +	size = sizeof(secboot);
> > +	status = efi.get_variable(L"SecureBoot", &efi_variable_guid,
> > +				  NULL, &size, &secboot);
> > +
> > +	if (status == EFI_NOT_FOUND)
> > +		return efi_secureboot_mode_disabled;
> > +
> > +	if (status != EFI_SUCCESS)
> > +		goto out_efi_err;
> > +
> > +	size = sizeof(setupmode);
> > +	status = efi.get_variable(L"SetupMode", &efi_variable_guid,
> > +				  NULL, &size, &setupmode);
> > +
> > +	if (status != EFI_SUCCESS)
> > +		goto out_efi_err;
> > +
> > +	if (secboot == 0 || setupmode == 1)
> > +		return efi_secureboot_mode_disabled;
> > +
> > +	/* See if a user has put the shim into insecure mode. */
> > +	size = sizeof(moksbstate);
> > +	status = efi.get_variable(L"MokSBStateRT", &shim_guid,
> > +				  NULL, &size, &moksbstate);
> > +
> > +	/* If it fails, we don't care why. Default to secure. */
> > +	if (status != EFI_SUCCESS)
> > +		goto secure_boot_enabled;
> > +
> > +	if (moksbstate == 1)
> > +		return efi_secureboot_mode_disabled;
> > +
> > + secure_boot_enabled:
> > +	pr_info("UEFI Secure Boot is enabled.\n");
> > +	return efi_secureboot_mode_enabled;
> > +
> > + out_efi_err:
> > +	pr_err("Could not determine UEFI Secure Boot status.\n");
> > +	return efi_secureboot_mode_unknown;
> > +}
> > +
>
> This looks like a bad idea: you're duplicating the secure boot check in
>
> drivers/firmware/efi/libstub/secureboot.c
>
> Which is an implementation of policy.  If we have to have policy in the
> kernel, it should really only be in one place to prevent drift; why
> can't you simply use the libstub efi_get_secureboot() so we're not
> duplicating the implementation of policy?

Well, here is the first version of this patch: https://lkml.org/lkml/2018/1/9/496
Ard did not like it. I was not happy too. In general both approaches are not perfect.
More you can find in the discussion around this patchset. If you have better idea
how to do that I am happy to implement it.

Daniel

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2] x86/xen/efi: Initialize UEFI secure boot state during dom0 boot
  2018-04-03 15:44 ` James Bottomley
  2018-04-03 16:07   ` Daniel Kiper
@ 2018-04-03 16:07   ` Daniel Kiper
  1 sibling, 0 replies; 16+ messages in thread
From: Daniel Kiper @ 2018-04-03 16:07 UTC (permalink / raw)
  To: James Bottomley
  Cc: jgross, eric.snowberg, linux-efi, ard.biesheuvel, x86,
	linux-kernel, mingo, hpa, xen-devel, boris.ostrovsky, tglx

On Tue, Apr 03, 2018 at 08:44:41AM -0700, James Bottomley wrote:
> On Tue, 2018-04-03 at 16:39 +0200, Daniel Kiper wrote:
> > Initialize UEFI secure boot state during dom0 boot. Otherwise the
> > kernel
> > may not even know that it runs on secure boot enabled platform.
> >
> > Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
> > ---
> >  arch/x86/xen/efi.c                        |   57
> > +++++++++++++++++++++++++++++
> >  drivers/firmware/efi/libstub/secureboot.c |    3 ++
> >  2 files changed, 60 insertions(+)
> >
> > diff --git a/arch/x86/xen/efi.c b/arch/x86/xen/efi.c
> > index a18703b..1804b27 100644
> > --- a/arch/x86/xen/efi.c
> > +++ b/arch/x86/xen/efi.c
> > @@ -115,6 +115,61 @@ static efi_system_table_t __init
> > *xen_efi_probe(void)
> >  	return &efi_systab_xen;
> >  }
> >  
> > +/*
> > + * Determine whether we're in secure boot mode.
> > + *
> > + * Please keep the logic in sync with
> > + * drivers/firmware/efi/libstub/secureboot.c:efi_get_secureboot().
> > + */
> > +static enum efi_secureboot_mode xen_efi_get_secureboot(void)
> > +{
> > +	static efi_guid_t efi_variable_guid =
> > EFI_GLOBAL_VARIABLE_GUID;
> > +	static efi_guid_t shim_guid = EFI_SHIM_LOCK_GUID;
> > +	efi_status_t status;
> > +	u8 moksbstate, secboot, setupmode;
> > +	unsigned long size;
> > +
> > +	size = sizeof(secboot);
> > +	status = efi.get_variable(L"SecureBoot", &efi_variable_guid,
> > +				  NULL, &size, &secboot);
> > +
> > +	if (status == EFI_NOT_FOUND)
> > +		return efi_secureboot_mode_disabled;
> > +
> > +	if (status != EFI_SUCCESS)
> > +		goto out_efi_err;
> > +
> > +	size = sizeof(setupmode);
> > +	status = efi.get_variable(L"SetupMode", &efi_variable_guid,
> > +				  NULL, &size, &setupmode);
> > +
> > +	if (status != EFI_SUCCESS)
> > +		goto out_efi_err;
> > +
> > +	if (secboot == 0 || setupmode == 1)
> > +		return efi_secureboot_mode_disabled;
> > +
> > +	/* See if a user has put the shim into insecure mode. */
> > +	size = sizeof(moksbstate);
> > +	status = efi.get_variable(L"MokSBStateRT", &shim_guid,
> > +				  NULL, &size, &moksbstate);
> > +
> > +	/* If it fails, we don't care why. Default to secure. */
> > +	if (status != EFI_SUCCESS)
> > +		goto secure_boot_enabled;
> > +
> > +	if (moksbstate == 1)
> > +		return efi_secureboot_mode_disabled;
> > +
> > + secure_boot_enabled:
> > +	pr_info("UEFI Secure Boot is enabled.\n");
> > +	return efi_secureboot_mode_enabled;
> > +
> > + out_efi_err:
> > +	pr_err("Could not determine UEFI Secure Boot status.\n");
> > +	return efi_secureboot_mode_unknown;
> > +}
> > +
>
> This looks like a bad idea: you're duplicating the secure boot check in
>
> drivers/firmware/efi/libstub/secureboot.c
>
> Which is an implementation of policy.  If we have to have policy in the
> kernel, it should really only be in one place to prevent drift; why
> can't you simply use the libstub efi_get_secureboot() so we're not
> duplicating the implementation of policy?

Well, here is the first version of this patch: https://lkml.org/lkml/2018/1/9/496
Ard did not like it. I was not happy too. In general both approaches are not perfect.
More you can find in the discussion around this patchset. If you have better idea
how to do that I am happy to implement it.

Daniel

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2] x86/xen/efi: Initialize UEFI secure boot state during dom0 boot
  2018-04-03 16:07   ` Daniel Kiper
  2018-04-03 17:00     ` James Bottomley
@ 2018-04-03 17:00     ` James Bottomley
  2018-04-04 10:38       ` Daniel Kiper
  2018-04-04 10:38       ` Daniel Kiper
  1 sibling, 2 replies; 16+ messages in thread
From: James Bottomley @ 2018-04-03 17:00 UTC (permalink / raw)
  To: Daniel Kiper
  Cc: linux-efi, linux-kernel, x86, xen-devel, ard.biesheuvel,
	boris.ostrovsky, eric.snowberg, hpa, jgross, konrad.wilk, mingo,
	tglx

On Tue, 2018-04-03 at 18:07 +0200, Daniel Kiper wrote:
> On Tue, Apr 03, 2018 at 08:44:41AM -0700, James Bottomley wrote:
> > 
> > On Tue, 2018-04-03 at 16:39 +0200, Daniel Kiper wrote:
> > > 
> > > Initialize UEFI secure boot state during dom0 boot. Otherwise the
> > > kernel may not even know that it runs on secure boot enabled
> > > platform.
> > > 
> > > Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
> > > ---
> > >  arch/x86/xen/efi.c                        |   57
> > > +++++++++++++++++++++++++++++
> > >  drivers/firmware/efi/libstub/secureboot.c |    3 ++
> > >  2 files changed, 60 insertions(+)
> > > 
> > > diff --git a/arch/x86/xen/efi.c b/arch/x86/xen/efi.c
> > > index a18703b..1804b27 100644
> > > --- a/arch/x86/xen/efi.c
> > > +++ b/arch/x86/xen/efi.c
> > > @@ -115,6 +115,61 @@ static efi_system_table_t __init
> > > *xen_efi_probe(void)
> > >  	return &efi_systab_xen;
> > >  }
> > >  
> > > +/*
> > > + * Determine whether we're in secure boot mode.
> > > + *
> > > + * Please keep the logic in sync with
> > > + *
> > > drivers/firmware/efi/libstub/secureboot.c:efi_get_secureboot().
> > > + */
> > > +static enum efi_secureboot_mode xen_efi_get_secureboot(void)
> > > +{
> > > +	static efi_guid_t efi_variable_guid =
> > > EFI_GLOBAL_VARIABLE_GUID;
> > > +	static efi_guid_t shim_guid = EFI_SHIM_LOCK_GUID;
> > > +	efi_status_t status;
> > > +	u8 moksbstate, secboot, setupmode;
> > > +	unsigned long size;
> > > +
> > > +	size = sizeof(secboot);
> > > +	status = efi.get_variable(L"SecureBoot",
> > > &efi_variable_guid,
> > > +				  NULL, &size, &secboot);
> > > +
> > > +	if (status == EFI_NOT_FOUND)
> > > +		return efi_secureboot_mode_disabled;
> > > +
> > > +	if (status != EFI_SUCCESS)
> > > +		goto out_efi_err;
> > > +
> > > +	size = sizeof(setupmode);
> > > +	status = efi.get_variable(L"SetupMode",
> > > &efi_variable_guid,
> > > +				  NULL, &size, &setupmode);
> > > +
> > > +	if (status != EFI_SUCCESS)
> > > +		goto out_efi_err;
> > > +
> > > +	if (secboot == 0 || setupmode == 1)
> > > +		return efi_secureboot_mode_disabled;
> > > +
> > > +	/* See if a user has put the shim into insecure mode. */
> > > +	size = sizeof(moksbstate);
> > > +	status = efi.get_variable(L"MokSBStateRT", &shim_guid,
> > > +				  NULL, &size, &moksbstate);
> > > +
> > > +	/* If it fails, we don't care why. Default to secure. */
> > > +	if (status != EFI_SUCCESS)
> > > +		goto secure_boot_enabled;
> > > +
> > > +	if (moksbstate == 1)
> > > +		return efi_secureboot_mode_disabled;
> > > +
> > > + secure_boot_enabled:
> > > +	pr_info("UEFI Secure Boot is enabled.\n");
> > > +	return efi_secureboot_mode_enabled;
> > > +
> > > + out_efi_err:
> > > +	pr_err("Could not determine UEFI Secure Boot
> > > status.\n");
> > > +	return efi_secureboot_mode_unknown;
> > > +}
> > > +
> > 
> > This looks like a bad idea: you're duplicating the secure boot
> > check in
> > 
> > drivers/firmware/efi/libstub/secureboot.c
> > 
> > Which is an implementation of policy.  If we have to have policy in
> > the kernel, it should really only be in one place to prevent drift;
> > why can't you simply use the libstub efi_get_secureboot() so we're
> > not duplicating the implementation of policy?
> 
> Well, here is the first version of this patch:
> https://lkml.org/lkml/2018/1/9/496 Ard did not like it. I was not
> happy too. In general both approaches are not perfect. More you can
> find in the discussion around this patchset. If you have better idea
> how to do that I am happy to implement it.

One way might be simply to have the pre exit-boot-services code lay
down a variable containing the state which you pick up, rather than you
calling efi code separately and trying to use the insecure RT
variables.  That way there's a uniform view of the internal kernel
secure boot state that everyone can use.

James

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2] x86/xen/efi: Initialize UEFI secure boot state during dom0 boot
  2018-04-03 16:07   ` Daniel Kiper
@ 2018-04-03 17:00     ` James Bottomley
  2018-04-03 17:00     ` James Bottomley
  1 sibling, 0 replies; 16+ messages in thread
From: James Bottomley @ 2018-04-03 17:00 UTC (permalink / raw)
  To: Daniel Kiper
  Cc: jgross, eric.snowberg, linux-efi, ard.biesheuvel, x86,
	linux-kernel, mingo, hpa, xen-devel, boris.ostrovsky, tglx

On Tue, 2018-04-03 at 18:07 +0200, Daniel Kiper wrote:
> On Tue, Apr 03, 2018 at 08:44:41AM -0700, James Bottomley wrote:
> > 
> > On Tue, 2018-04-03 at 16:39 +0200, Daniel Kiper wrote:
> > > 
> > > Initialize UEFI secure boot state during dom0 boot. Otherwise the
> > > kernel may not even know that it runs on secure boot enabled
> > > platform.
> > > 
> > > Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
> > > ---
> > >  arch/x86/xen/efi.c                        |   57
> > > +++++++++++++++++++++++++++++
> > >  drivers/firmware/efi/libstub/secureboot.c |    3 ++
> > >  2 files changed, 60 insertions(+)
> > > 
> > > diff --git a/arch/x86/xen/efi.c b/arch/x86/xen/efi.c
> > > index a18703b..1804b27 100644
> > > --- a/arch/x86/xen/efi.c
> > > +++ b/arch/x86/xen/efi.c
> > > @@ -115,6 +115,61 @@ static efi_system_table_t __init
> > > *xen_efi_probe(void)
> > >  	return &efi_systab_xen;
> > >  }
> > >  
> > > +/*
> > > + * Determine whether we're in secure boot mode.
> > > + *
> > > + * Please keep the logic in sync with
> > > + *
> > > drivers/firmware/efi/libstub/secureboot.c:efi_get_secureboot().
> > > + */
> > > +static enum efi_secureboot_mode xen_efi_get_secureboot(void)
> > > +{
> > > +	static efi_guid_t efi_variable_guid =
> > > EFI_GLOBAL_VARIABLE_GUID;
> > > +	static efi_guid_t shim_guid = EFI_SHIM_LOCK_GUID;
> > > +	efi_status_t status;
> > > +	u8 moksbstate, secboot, setupmode;
> > > +	unsigned long size;
> > > +
> > > +	size = sizeof(secboot);
> > > +	status = efi.get_variable(L"SecureBoot",
> > > &efi_variable_guid,
> > > +				  NULL, &size, &secboot);
> > > +
> > > +	if (status == EFI_NOT_FOUND)
> > > +		return efi_secureboot_mode_disabled;
> > > +
> > > +	if (status != EFI_SUCCESS)
> > > +		goto out_efi_err;
> > > +
> > > +	size = sizeof(setupmode);
> > > +	status = efi.get_variable(L"SetupMode",
> > > &efi_variable_guid,
> > > +				  NULL, &size, &setupmode);
> > > +
> > > +	if (status != EFI_SUCCESS)
> > > +		goto out_efi_err;
> > > +
> > > +	if (secboot == 0 || setupmode == 1)
> > > +		return efi_secureboot_mode_disabled;
> > > +
> > > +	/* See if a user has put the shim into insecure mode. */
> > > +	size = sizeof(moksbstate);
> > > +	status = efi.get_variable(L"MokSBStateRT", &shim_guid,
> > > +				  NULL, &size, &moksbstate);
> > > +
> > > +	/* If it fails, we don't care why. Default to secure. */
> > > +	if (status != EFI_SUCCESS)
> > > +		goto secure_boot_enabled;
> > > +
> > > +	if (moksbstate == 1)
> > > +		return efi_secureboot_mode_disabled;
> > > +
> > > + secure_boot_enabled:
> > > +	pr_info("UEFI Secure Boot is enabled.\n");
> > > +	return efi_secureboot_mode_enabled;
> > > +
> > > + out_efi_err:
> > > +	pr_err("Could not determine UEFI Secure Boot
> > > status.\n");
> > > +	return efi_secureboot_mode_unknown;
> > > +}
> > > +
> > 
> > This looks like a bad idea: you're duplicating the secure boot
> > check in
> > 
> > drivers/firmware/efi/libstub/secureboot.c
> > 
> > Which is an implementation of policy.  If we have to have policy in
> > the kernel, it should really only be in one place to prevent drift;
> > why can't you simply use the libstub efi_get_secureboot() so we're
> > not duplicating the implementation of policy?
> 
> Well, here is the first version of this patch:
> https://lkml.org/lkml/2018/1/9/496 Ard did not like it. I was not
> happy too. In general both approaches are not perfect. More you can
> find in the discussion around this patchset. If you have better idea
> how to do that I am happy to implement it.

One way might be simply to have the pre exit-boot-services code lay
down a variable containing the state which you pick up, rather than you
calling efi code separately and trying to use the insecure RT
variables.  That way there's a uniform view of the internal kernel
secure boot state that everyone can use.

James


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2] x86/xen/efi: Initialize UEFI secure boot state during dom0 boot
  2018-04-03 17:00     ` James Bottomley
  2018-04-04 10:38       ` Daniel Kiper
@ 2018-04-04 10:38       ` Daniel Kiper
  2018-04-11  8:56         ` Daniel Kiper
  2018-04-11  8:56         ` Daniel Kiper
  1 sibling, 2 replies; 16+ messages in thread
From: Daniel Kiper @ 2018-04-04 10:38 UTC (permalink / raw)
  To: James Bottomley
  Cc: linux-efi, linux-kernel, x86, xen-devel, ard.biesheuvel,
	boris.ostrovsky, eric.snowberg, hpa, jgross, konrad.wilk, mingo,
	tglx

On Tue, Apr 03, 2018 at 10:00:52AM -0700, James Bottomley wrote:
> On Tue, 2018-04-03 at 18:07 +0200, Daniel Kiper wrote:
> > On Tue, Apr 03, 2018 at 08:44:41AM -0700, James Bottomley wrote:

[...]

> > > This looks like a bad idea: you're duplicating the secure boot
> > > check in
> > >
> > > drivers/firmware/efi/libstub/secureboot.c
> > >
> > > Which is an implementation of policy.  If we have to have policy in
> > > the kernel, it should really only be in one place to prevent drift;
> > > why can't you simply use the libstub efi_get_secureboot() so we're
> > > not duplicating the implementation of policy?
> >
> > Well, here is the first version of this patch:
> > https://lkml.org/lkml/2018/1/9/496 Ard did not like it. I was not
> > happy too. In general both approaches are not perfect. More you can
> > find in the discussion around this patchset. If you have better idea
> > how to do that I am happy to implement it.
>
> One way might be simply to have the pre exit-boot-services code lay
> down a variable containing the state which you pick up, rather than you

Do you mean variable in kernel proper or something like that? If yes this
is not possible. EFI Linux stub is not executed in Xen dom0. All UEFI
infrastructure is owned and operated by Xen. Dom0 kernel can access some
stuff in UEFI, including variables, via hypercall. However, when dom0
runs only UEFI runtime services are available.

> calling efi code separately and trying to use the insecure RT

I am not sure why they are insecure.

> variables.  That way there's a uniform view of the internal kernel
> secure boot state that everyone can use.

That would be perfect but I have a feeling that in form proposed above
it is not possible.

Daniel

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2] x86/xen/efi: Initialize UEFI secure boot state during dom0 boot
  2018-04-03 17:00     ` James Bottomley
@ 2018-04-04 10:38       ` Daniel Kiper
  2018-04-04 10:38       ` Daniel Kiper
  1 sibling, 0 replies; 16+ messages in thread
From: Daniel Kiper @ 2018-04-04 10:38 UTC (permalink / raw)
  To: James Bottomley
  Cc: jgross, eric.snowberg, linux-efi, ard.biesheuvel, x86,
	linux-kernel, mingo, hpa, xen-devel, boris.ostrovsky, tglx

On Tue, Apr 03, 2018 at 10:00:52AM -0700, James Bottomley wrote:
> On Tue, 2018-04-03 at 18:07 +0200, Daniel Kiper wrote:
> > On Tue, Apr 03, 2018 at 08:44:41AM -0700, James Bottomley wrote:

[...]

> > > This looks like a bad idea: you're duplicating the secure boot
> > > check in
> > >
> > > drivers/firmware/efi/libstub/secureboot.c
> > >
> > > Which is an implementation of policy.  If we have to have policy in
> > > the kernel, it should really only be in one place to prevent drift;
> > > why can't you simply use the libstub efi_get_secureboot() so we're
> > > not duplicating the implementation of policy?
> >
> > Well, here is the first version of this patch:
> > https://lkml.org/lkml/2018/1/9/496 Ard did not like it. I was not
> > happy too. In general both approaches are not perfect. More you can
> > find in the discussion around this patchset. If you have better idea
> > how to do that I am happy to implement it.
>
> One way might be simply to have the pre exit-boot-services code lay
> down a variable containing the state which you pick up, rather than you

Do you mean variable in kernel proper or something like that? If yes this
is not possible. EFI Linux stub is not executed in Xen dom0. All UEFI
infrastructure is owned and operated by Xen. Dom0 kernel can access some
stuff in UEFI, including variables, via hypercall. However, when dom0
runs only UEFI runtime services are available.

> calling efi code separately and trying to use the insecure RT

I am not sure why they are insecure.

> variables.  That way there's a uniform view of the internal kernel
> secure boot state that everyone can use.

That would be perfect but I have a feeling that in form proposed above
it is not possible.

Daniel

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2] x86/xen/efi: Initialize UEFI secure boot state during dom0 boot
  2018-04-04 10:38       ` Daniel Kiper
  2018-04-11  8:56         ` Daniel Kiper
@ 2018-04-11  8:56         ` Daniel Kiper
  2018-04-16  8:15           ` Ard Biesheuvel
  2018-04-16  8:15           ` Ard Biesheuvel
  1 sibling, 2 replies; 16+ messages in thread
From: Daniel Kiper @ 2018-04-11  8:56 UTC (permalink / raw)
  To: james.bottomley, ard.biesheuvel
  Cc: linux-efi, linux-kernel, x86, xen-devel, boris.ostrovsky,
	eric.snowberg, hpa, jgross, konrad.wilk, mingo, tglx

On Wed, Apr 04, 2018 at 12:38:24PM +0200, Daniel Kiper wrote:
> On Tue, Apr 03, 2018 at 10:00:52AM -0700, James Bottomley wrote:
> > On Tue, 2018-04-03 at 18:07 +0200, Daniel Kiper wrote:
> > > On Tue, Apr 03, 2018 at 08:44:41AM -0700, James Bottomley wrote:
>
> [...]
>
> > > > This looks like a bad idea: you're duplicating the secure boot
> > > > check in
> > > >
> > > > drivers/firmware/efi/libstub/secureboot.c
> > > >
> > > > Which is an implementation of policy.  If we have to have policy in
> > > > the kernel, it should really only be in one place to prevent drift;
> > > > why can't you simply use the libstub efi_get_secureboot() so we're
> > > > not duplicating the implementation of policy?
> > >
> > > Well, here is the first version of this patch:
> > > https://lkml.org/lkml/2018/1/9/496 Ard did not like it. I was not
> > > happy too. In general both approaches are not perfect. More you can
> > > find in the discussion around this patchset. If you have better idea
> > > how to do that I am happy to implement it.
> >
> > One way might be simply to have the pre exit-boot-services code lay
> > down a variable containing the state which you pick up, rather than you
>
> Do you mean variable in kernel proper or something like that? If yes this
> is not possible. EFI Linux stub is not executed in Xen dom0. All UEFI
> infrastructure is owned and operated by Xen. Dom0 kernel can access some
> stuff in UEFI, including variables, via hypercall. However, when dom0
> runs only UEFI runtime services are available.
>
> > calling efi code separately and trying to use the insecure RT
>
> I am not sure why they are insecure.
>
> > variables.  That way there's a uniform view of the internal kernel
> > secure boot state that everyone can use.
>
> That would be perfect but I have a feeling that in form proposed above
> it is not possible.

Ping?

Daniel

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2] x86/xen/efi: Initialize UEFI secure boot state during dom0 boot
  2018-04-04 10:38       ` Daniel Kiper
@ 2018-04-11  8:56         ` Daniel Kiper
  2018-04-11  8:56         ` Daniel Kiper
  1 sibling, 0 replies; 16+ messages in thread
From: Daniel Kiper @ 2018-04-11  8:56 UTC (permalink / raw)
  To: james.bottomley, ard.biesheuvel
  Cc: jgross, eric.snowberg, linux-efi, x86, linux-kernel, mingo, hpa,
	xen-devel, boris.ostrovsky, tglx

On Wed, Apr 04, 2018 at 12:38:24PM +0200, Daniel Kiper wrote:
> On Tue, Apr 03, 2018 at 10:00:52AM -0700, James Bottomley wrote:
> > On Tue, 2018-04-03 at 18:07 +0200, Daniel Kiper wrote:
> > > On Tue, Apr 03, 2018 at 08:44:41AM -0700, James Bottomley wrote:
>
> [...]
>
> > > > This looks like a bad idea: you're duplicating the secure boot
> > > > check in
> > > >
> > > > drivers/firmware/efi/libstub/secureboot.c
> > > >
> > > > Which is an implementation of policy.  If we have to have policy in
> > > > the kernel, it should really only be in one place to prevent drift;
> > > > why can't you simply use the libstub efi_get_secureboot() so we're
> > > > not duplicating the implementation of policy?
> > >
> > > Well, here is the first version of this patch:
> > > https://lkml.org/lkml/2018/1/9/496 Ard did not like it. I was not
> > > happy too. In general both approaches are not perfect. More you can
> > > find in the discussion around this patchset. If you have better idea
> > > how to do that I am happy to implement it.
> >
> > One way might be simply to have the pre exit-boot-services code lay
> > down a variable containing the state which you pick up, rather than you
>
> Do you mean variable in kernel proper or something like that? If yes this
> is not possible. EFI Linux stub is not executed in Xen dom0. All UEFI
> infrastructure is owned and operated by Xen. Dom0 kernel can access some
> stuff in UEFI, including variables, via hypercall. However, when dom0
> runs only UEFI runtime services are available.
>
> > calling efi code separately and trying to use the insecure RT
>
> I am not sure why they are insecure.
>
> > variables.  That way there's a uniform view of the internal kernel
> > secure boot state that everyone can use.
>
> That would be perfect but I have a feeling that in form proposed above
> it is not possible.

Ping?

Daniel

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2] x86/xen/efi: Initialize UEFI secure boot state during dom0 boot
  2018-04-11  8:56         ` Daniel Kiper
  2018-04-16  8:15           ` Ard Biesheuvel
@ 2018-04-16  8:15           ` Ard Biesheuvel
  2018-04-16  9:04             ` Daniel Kiper
  2018-04-16  9:04             ` Daniel Kiper
  1 sibling, 2 replies; 16+ messages in thread
From: Ard Biesheuvel @ 2018-04-16  8:15 UTC (permalink / raw)
  To: Daniel Kiper
  Cc: James Bottomley, linux-efi, Linux Kernel Mailing List,
	the arch/x86 maintainers, xen-devel, Boris Ostrovsky,
	eric.snowberg, H. Peter Anvin, Juergen Gross,
	Konrad Rzeszutek Wilk, Ingo Molnar, Thomas Gleixner

On 11 April 2018 at 10:56, Daniel Kiper <daniel.kiper@oracle.com> wrote:
> On Wed, Apr 04, 2018 at 12:38:24PM +0200, Daniel Kiper wrote:
>> On Tue, Apr 03, 2018 at 10:00:52AM -0700, James Bottomley wrote:
>> > On Tue, 2018-04-03 at 18:07 +0200, Daniel Kiper wrote:
>> > > On Tue, Apr 03, 2018 at 08:44:41AM -0700, James Bottomley wrote:
>>
>> [...]
>>
>> > > > This looks like a bad idea: you're duplicating the secure boot
>> > > > check in
>> > > >
>> > > > drivers/firmware/efi/libstub/secureboot.c
>> > > >
>> > > > Which is an implementation of policy.  If we have to have policy in
>> > > > the kernel, it should really only be in one place to prevent drift;
>> > > > why can't you simply use the libstub efi_get_secureboot() so we're
>> > > > not duplicating the implementation of policy?
>> > >
>> > > Well, here is the first version of this patch:
>> > > https://lkml.org/lkml/2018/1/9/496 Ard did not like it. I was not
>> > > happy too. In general both approaches are not perfect. More you can
>> > > find in the discussion around this patchset. If you have better idea
>> > > how to do that I am happy to implement it.
>> >
>> > One way might be simply to have the pre exit-boot-services code lay
>> > down a variable containing the state which you pick up, rather than you
>>
>> Do you mean variable in kernel proper or something like that? If yes this
>> is not possible. EFI Linux stub is not executed in Xen dom0. All UEFI
>> infrastructure is owned and operated by Xen. Dom0 kernel can access some
>> stuff in UEFI, including variables, via hypercall. However, when dom0
>> runs only UEFI runtime services are available.
>>
>> > calling efi code separately and trying to use the insecure RT
>>
>> I am not sure why they are insecure.
>>
>> > variables.  That way there's a uniform view of the internal kernel
>> > secure boot state that everyone can use.
>>
>> That would be perfect but I have a feeling that in form proposed above
>> it is not possible.
>
> Ping?
>

(apologies if this is a duplicate email - I thought I had replied
already but I don't see it in my sent folder)

Queued in efi/next - thanks.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2] x86/xen/efi: Initialize UEFI secure boot state during dom0 boot
  2018-04-11  8:56         ` Daniel Kiper
@ 2018-04-16  8:15           ` Ard Biesheuvel
  2018-04-16  8:15           ` Ard Biesheuvel
  1 sibling, 0 replies; 16+ messages in thread
From: Ard Biesheuvel @ 2018-04-16  8:15 UTC (permalink / raw)
  To: Daniel Kiper
  Cc: Juergen Gross, eric.snowberg, linux-efi,
	the arch/x86 maintainers, Linux Kernel Mailing List,
	James Bottomley, Ingo Molnar, H. Peter Anvin, xen-devel,
	Boris Ostrovsky, Thomas Gleixner

On 11 April 2018 at 10:56, Daniel Kiper <daniel.kiper@oracle.com> wrote:
> On Wed, Apr 04, 2018 at 12:38:24PM +0200, Daniel Kiper wrote:
>> On Tue, Apr 03, 2018 at 10:00:52AM -0700, James Bottomley wrote:
>> > On Tue, 2018-04-03 at 18:07 +0200, Daniel Kiper wrote:
>> > > On Tue, Apr 03, 2018 at 08:44:41AM -0700, James Bottomley wrote:
>>
>> [...]
>>
>> > > > This looks like a bad idea: you're duplicating the secure boot
>> > > > check in
>> > > >
>> > > > drivers/firmware/efi/libstub/secureboot.c
>> > > >
>> > > > Which is an implementation of policy.  If we have to have policy in
>> > > > the kernel, it should really only be in one place to prevent drift;
>> > > > why can't you simply use the libstub efi_get_secureboot() so we're
>> > > > not duplicating the implementation of policy?
>> > >
>> > > Well, here is the first version of this patch:
>> > > https://lkml.org/lkml/2018/1/9/496 Ard did not like it. I was not
>> > > happy too. In general both approaches are not perfect. More you can
>> > > find in the discussion around this patchset. If you have better idea
>> > > how to do that I am happy to implement it.
>> >
>> > One way might be simply to have the pre exit-boot-services code lay
>> > down a variable containing the state which you pick up, rather than you
>>
>> Do you mean variable in kernel proper or something like that? If yes this
>> is not possible. EFI Linux stub is not executed in Xen dom0. All UEFI
>> infrastructure is owned and operated by Xen. Dom0 kernel can access some
>> stuff in UEFI, including variables, via hypercall. However, when dom0
>> runs only UEFI runtime services are available.
>>
>> > calling efi code separately and trying to use the insecure RT
>>
>> I am not sure why they are insecure.
>>
>> > variables.  That way there's a uniform view of the internal kernel
>> > secure boot state that everyone can use.
>>
>> That would be perfect but I have a feeling that in form proposed above
>> it is not possible.
>
> Ping?
>

(apologies if this is a duplicate email - I thought I had replied
already but I don't see it in my sent folder)

Queued in efi/next - thanks.

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2] x86/xen/efi: Initialize UEFI secure boot state during dom0 boot
  2018-04-16  8:15           ` Ard Biesheuvel
  2018-04-16  9:04             ` Daniel Kiper
@ 2018-04-16  9:04             ` Daniel Kiper
  1 sibling, 0 replies; 16+ messages in thread
From: Daniel Kiper @ 2018-04-16  9:04 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: James Bottomley, linux-efi, Linux Kernel Mailing List,
	the arch/x86 maintainers, xen-devel, Boris Ostrovsky,
	eric.snowberg, H. Peter Anvin, Juergen Gross,
	Konrad Rzeszutek Wilk, Ingo Molnar, Thomas Gleixner

On Mon, Apr 16, 2018 at 10:15:15AM +0200, Ard Biesheuvel wrote:
> On 11 April 2018 at 10:56, Daniel Kiper <daniel.kiper@oracle.com> wrote:
> > On Wed, Apr 04, 2018 at 12:38:24PM +0200, Daniel Kiper wrote:
> >> On Tue, Apr 03, 2018 at 10:00:52AM -0700, James Bottomley wrote:
> >> > On Tue, 2018-04-03 at 18:07 +0200, Daniel Kiper wrote:
> >> > > On Tue, Apr 03, 2018 at 08:44:41AM -0700, James Bottomley wrote:
> >>
> >> [...]
> >>
> >> > > > This looks like a bad idea: you're duplicating the secure boot
> >> > > > check in
> >> > > >
> >> > > > drivers/firmware/efi/libstub/secureboot.c
> >> > > >
> >> > > > Which is an implementation of policy.  If we have to have policy in
> >> > > > the kernel, it should really only be in one place to prevent drift;
> >> > > > why can't you simply use the libstub efi_get_secureboot() so we're
> >> > > > not duplicating the implementation of policy?
> >> > >
> >> > > Well, here is the first version of this patch:
> >> > > https://lkml.org/lkml/2018/1/9/496 Ard did not like it. I was not
> >> > > happy too. In general both approaches are not perfect. More you can
> >> > > find in the discussion around this patchset. If you have better idea
> >> > > how to do that I am happy to implement it.
> >> >
> >> > One way might be simply to have the pre exit-boot-services code lay
> >> > down a variable containing the state which you pick up, rather than you
> >>
> >> Do you mean variable in kernel proper or something like that? If yes this
> >> is not possible. EFI Linux stub is not executed in Xen dom0. All UEFI
> >> infrastructure is owned and operated by Xen. Dom0 kernel can access some
> >> stuff in UEFI, including variables, via hypercall. However, when dom0
> >> runs only UEFI runtime services are available.
> >>
> >> > calling efi code separately and trying to use the insecure RT
> >>
> >> I am not sure why they are insecure.
> >>
> >> > variables.  That way there's a uniform view of the internal kernel
> >> > secure boot state that everyone can use.
> >>
> >> That would be perfect but I have a feeling that in form proposed above
> >> it is not possible.
> >
> > Ping?
> >
>
> (apologies if this is a duplicate email - I thought I had replied
> already but I don't see it in my sent folder)
>
> Queued in efi/next - thanks.

Thanks a lot!

Daniel

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2] x86/xen/efi: Initialize UEFI secure boot state during dom0 boot
  2018-04-16  8:15           ` Ard Biesheuvel
@ 2018-04-16  9:04             ` Daniel Kiper
  2018-04-16  9:04             ` Daniel Kiper
  1 sibling, 0 replies; 16+ messages in thread
From: Daniel Kiper @ 2018-04-16  9:04 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: Juergen Gross, eric.snowberg, linux-efi,
	the arch/x86 maintainers, Linux Kernel Mailing List,
	James Bottomley, Ingo Molnar, H. Peter Anvin, xen-devel,
	Boris Ostrovsky, Thomas Gleixner

On Mon, Apr 16, 2018 at 10:15:15AM +0200, Ard Biesheuvel wrote:
> On 11 April 2018 at 10:56, Daniel Kiper <daniel.kiper@oracle.com> wrote:
> > On Wed, Apr 04, 2018 at 12:38:24PM +0200, Daniel Kiper wrote:
> >> On Tue, Apr 03, 2018 at 10:00:52AM -0700, James Bottomley wrote:
> >> > On Tue, 2018-04-03 at 18:07 +0200, Daniel Kiper wrote:
> >> > > On Tue, Apr 03, 2018 at 08:44:41AM -0700, James Bottomley wrote:
> >>
> >> [...]
> >>
> >> > > > This looks like a bad idea: you're duplicating the secure boot
> >> > > > check in
> >> > > >
> >> > > > drivers/firmware/efi/libstub/secureboot.c
> >> > > >
> >> > > > Which is an implementation of policy.  If we have to have policy in
> >> > > > the kernel, it should really only be in one place to prevent drift;
> >> > > > why can't you simply use the libstub efi_get_secureboot() so we're
> >> > > > not duplicating the implementation of policy?
> >> > >
> >> > > Well, here is the first version of this patch:
> >> > > https://lkml.org/lkml/2018/1/9/496 Ard did not like it. I was not
> >> > > happy too. In general both approaches are not perfect. More you can
> >> > > find in the discussion around this patchset. If you have better idea
> >> > > how to do that I am happy to implement it.
> >> >
> >> > One way might be simply to have the pre exit-boot-services code lay
> >> > down a variable containing the state which you pick up, rather than you
> >>
> >> Do you mean variable in kernel proper or something like that? If yes this
> >> is not possible. EFI Linux stub is not executed in Xen dom0. All UEFI
> >> infrastructure is owned and operated by Xen. Dom0 kernel can access some
> >> stuff in UEFI, including variables, via hypercall. However, when dom0
> >> runs only UEFI runtime services are available.
> >>
> >> > calling efi code separately and trying to use the insecure RT
> >>
> >> I am not sure why they are insecure.
> >>
> >> > variables.  That way there's a uniform view of the internal kernel
> >> > secure boot state that everyone can use.
> >>
> >> That would be perfect but I have a feeling that in form proposed above
> >> it is not possible.
> >
> > Ping?
> >
>
> (apologies if this is a duplicate email - I thought I had replied
> already but I don't see it in my sent folder)
>
> Queued in efi/next - thanks.

Thanks a lot!

Daniel

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH v2] x86/xen/efi: Initialize UEFI secure boot state during dom0 boot
@ 2018-04-03 14:39 Daniel Kiper
  0 siblings, 0 replies; 16+ messages in thread
From: Daniel Kiper @ 2018-04-03 14:39 UTC (permalink / raw)
  To: linux-efi, linux-kernel, x86, xen-devel
  Cc: jgross, eric.snowberg, ard.biesheuvel, mingo, hpa, boris.ostrovsky, tglx

Initialize UEFI secure boot state during dom0 boot. Otherwise the kernel
may not even know that it runs on secure boot enabled platform.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
---
 arch/x86/xen/efi.c                        |   57 +++++++++++++++++++++++++++++
 drivers/firmware/efi/libstub/secureboot.c |    3 ++
 2 files changed, 60 insertions(+)

diff --git a/arch/x86/xen/efi.c b/arch/x86/xen/efi.c
index a18703b..1804b27 100644
--- a/arch/x86/xen/efi.c
+++ b/arch/x86/xen/efi.c
@@ -115,6 +115,61 @@ static efi_system_table_t __init *xen_efi_probe(void)
 	return &efi_systab_xen;
 }
 
+/*
+ * Determine whether we're in secure boot mode.
+ *
+ * Please keep the logic in sync with
+ * drivers/firmware/efi/libstub/secureboot.c:efi_get_secureboot().
+ */
+static enum efi_secureboot_mode xen_efi_get_secureboot(void)
+{
+	static efi_guid_t efi_variable_guid = EFI_GLOBAL_VARIABLE_GUID;
+	static efi_guid_t shim_guid = EFI_SHIM_LOCK_GUID;
+	efi_status_t status;
+	u8 moksbstate, secboot, setupmode;
+	unsigned long size;
+
+	size = sizeof(secboot);
+	status = efi.get_variable(L"SecureBoot", &efi_variable_guid,
+				  NULL, &size, &secboot);
+
+	if (status == EFI_NOT_FOUND)
+		return efi_secureboot_mode_disabled;
+
+	if (status != EFI_SUCCESS)
+		goto out_efi_err;
+
+	size = sizeof(setupmode);
+	status = efi.get_variable(L"SetupMode", &efi_variable_guid,
+				  NULL, &size, &setupmode);
+
+	if (status != EFI_SUCCESS)
+		goto out_efi_err;
+
+	if (secboot == 0 || setupmode == 1)
+		return efi_secureboot_mode_disabled;
+
+	/* See if a user has put the shim into insecure mode. */
+	size = sizeof(moksbstate);
+	status = efi.get_variable(L"MokSBStateRT", &shim_guid,
+				  NULL, &size, &moksbstate);
+
+	/* If it fails, we don't care why. Default to secure. */
+	if (status != EFI_SUCCESS)
+		goto secure_boot_enabled;
+
+	if (moksbstate == 1)
+		return efi_secureboot_mode_disabled;
+
+ secure_boot_enabled:
+	pr_info("UEFI Secure Boot is enabled.\n");
+	return efi_secureboot_mode_enabled;
+
+ out_efi_err:
+	pr_err("Could not determine UEFI Secure Boot status.\n");
+	return efi_secureboot_mode_unknown;
+}
+
 void __init xen_efi_init(void)
 {
 	efi_system_table_t *efi_systab_xen;
@@ -129,6 +184,8 @@ void __init xen_efi_init(void)
 	boot_params.efi_info.efi_systab = (__u32)__pa(efi_systab_xen);
 	boot_params.efi_info.efi_systab_hi = (__u32)(__pa(efi_systab_xen) >> 32);
 
+	boot_params.secure_boot = xen_efi_get_secureboot();
+
 	set_bit(EFI_BOOT, &efi.flags);
 	set_bit(EFI_PARAVIRT, &efi.flags);
 	set_bit(EFI_64BIT, &efi.flags);
diff --git a/drivers/firmware/efi/libstub/secureboot.c b/drivers/firmware/efi/libstub/secureboot.c
index 8f07eb4..72d9dfb 100644
--- a/drivers/firmware/efi/libstub/secureboot.c
+++ b/drivers/firmware/efi/libstub/secureboot.c
@@ -30,6 +30,9 @@
 
 /*
  * Determine whether we're in secure boot mode.
+ *
+ * Please keep the logic in sync with
+ * arch/x86/xen/efi.c:xen_efi_get_secureboot().
  */
 enum efi_secureboot_mode efi_get_secureboot(efi_system_table_t *sys_table_arg)
 {
-- 
1.7.10.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2018-04-16  9:05 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-03 14:39 [PATCH v2] x86/xen/efi: Initialize UEFI secure boot state during dom0 boot Daniel Kiper
2018-04-03 15:44 ` James Bottomley
2018-04-03 16:07   ` Daniel Kiper
2018-04-03 17:00     ` James Bottomley
2018-04-03 17:00     ` James Bottomley
2018-04-04 10:38       ` Daniel Kiper
2018-04-04 10:38       ` Daniel Kiper
2018-04-11  8:56         ` Daniel Kiper
2018-04-11  8:56         ` Daniel Kiper
2018-04-16  8:15           ` Ard Biesheuvel
2018-04-16  8:15           ` Ard Biesheuvel
2018-04-16  9:04             ` Daniel Kiper
2018-04-16  9:04             ` Daniel Kiper
2018-04-03 16:07   ` Daniel Kiper
2018-04-03 15:44 ` James Bottomley
2018-04-03 14:39 Daniel Kiper

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.