2009-06-23 00:42:30

by Joseph Cihula

[permalink] [raw]
Subject: [RFC v5][PATCH 3/4] intel_txt: Intel(R) TXT Sx shutdown support

Support for graceful handling of sleep states (S3/S4/S5) after an Intel(R) TXT launch.

Without this patch, attempting to place the system in one of the ACPI sleep
states (S3/S4/S5) will cause the TXT hardware to treat this as an attack and
will cause a system reset, with memory locked. Not only may the subsequent
memory scrub take some time, but the platform will be unable to enter the
requested power state.

This patch calls back into the tboot so that it may properly and securely clean
up system state and clear the secrets-in-memory flag, after which it will place
the system into the requested sleep state using ACPI information passed by the kernel.


arch/x86/kernel/smpboot.c | 6 +++++-
drivers/acpi/acpica/hwsleep.c | 13 +++++++++++++
kernel/cpu.c | 6 +++++-
3 files changed, 23 insertions(+), 2 deletions(-)

Signed-off-by: Joseph Cihula <[email protected]>
Signed-off-by: Shane Wang <[email protected]>

---

diff -uprN -X linus-2.6.git/Documentation/dontdiff linus-2.6.git/arch/x86/kernel/smpboot.c linus-2.6.git-txt/arch/x86/kernel/smpboot.c
--- linus-2.6.git/arch/x86/kernel/smpboot.c 2009-06-19 13:32:12.000000000 -0700
+++ linus-2.6.git-txt/arch/x86/kernel/smpboot.c 2009-06-19 18:41:22.000000000 -0700
@@ -62,6 +62,7 @@
#include <asm/vmi.h>
#include <asm/apic.h>
#include <asm/setup.h>
+#include <asm/tboot.h>
#include <asm/uv/uv.h>
#include <linux/mc146818rtc.h>

@@ -1317,7 +1318,10 @@ void play_dead_common(void)
void native_play_dead(void)
{
play_dead_common();
- wbinvd_halt();
+ if (tboot_in_measured_env())
+ tboot_shutdown(TB_SHUTDOWN_WFS);
+ else
+ wbinvd_halt();
}

#else /* ... !CONFIG_HOTPLUG_CPU */
diff -uprN -X linus-2.6.git/Documentation/dontdiff linus-2.6.git/drivers/acpi/acpica/hwsleep.c linus-2.6.git-txt/drivers/acpi/acpica/hwsleep.c
--- linus-2.6.git/drivers/acpi/acpica/hwsleep.c 2009-06-19 13:32:12.000000000 -0700
+++ linus-2.6.git-txt/drivers/acpi/acpica/hwsleep.c 2009-06-22 01:51:38.000000000 -0700
@@ -45,6 +45,7 @@
#include <acpi/acpi.h>
#include "accommon.h"
#include "actables.h"
+#include <asm/tboot.h>

#define _COMPONENT ACPI_HARDWARE
ACPI_MODULE_NAME("hwsleep")
@@ -342,6 +343,18 @@ acpi_status asmlinkage acpi_enter_sleep_

ACPI_FLUSH_CPU_CACHE();

+ if (tboot_in_measured_env()) {
+ tboot_copy_fadt(&acpi_gbl_FADT);
+ tboot_shared->acpi_sinfo.pm1a_cnt_val = pm1a_control;
+ tboot_shared->acpi_sinfo.pm1b_cnt_val = pm1b_control;
+ /* we always use the 32b wakeup vector */
+ tboot_shared->acpi_sinfo.vector_width = 32;
+ tboot_shared->acpi_sinfo.kernel_s3_resume_vector =
+ acpi_wakeup_address;
+
+ tboot_sleep(sleep_state);
+ }
+
/* Write #2: Write both SLP_TYP + SLP_EN */

status = acpi_hw_write_pm1_control(pm1a_control, pm1b_control);
diff -uprN -X linus-2.6.git/Documentation/dontdiff linus-2.6.git/kernel/cpu.c linus-2.6.git-txt/kernel/cpu.c
--- linus-2.6.git/kernel/cpu.c 2009-06-19 13:32:20.000000000 -0700
+++ linus-2.6.git-txt/kernel/cpu.c 2009-06-19 18:41:22.000000000 -0700
@@ -14,6 +14,7 @@
#include <linux/kthread.h>
#include <linux/stop_machine.h>
#include <linux/mutex.h>
+#include <asm/tboot.h>

#ifdef CONFIG_SMP
/* Serializes the updates to cpu_online_mask, cpu_present_mask */
@@ -379,7 +380,7 @@ static cpumask_var_t frozen_cpus;

int disable_nonboot_cpus(void)
{
- int cpu, first_cpu, error;
+ int cpu, first_cpu, error, num_cpus = 0;

error = stop_machine_create();
if (error)
@@ -394,6 +395,7 @@ int disable_nonboot_cpus(void)
for_each_online_cpu(cpu) {
if (cpu == first_cpu)
continue;
+ num_cpus++;
error = _cpu_down(cpu, 1);
if (!error) {
cpumask_set_cpu(cpu, frozen_cpus);
@@ -404,6 +406,8 @@ int disable_nonboot_cpus(void)
break;
}
}
+ /* ensure all CPUs have gone into wait-for-SIPI */
+ tboot_wait_for_aps(num_cpus);
if (!error) {
BUG_ON(num_online_cpus() > 1);
/* Make sure the CPUs won't be enabled by someone else */


2009-06-27 11:29:43

by Pavel Machek

[permalink] [raw]
Subject: Re: [RFC v5][PATCH 3/4] intel_txt: Intel(R) TXT Sx shutdown support

On Mon 2009-06-22 17:41:38, Joseph Cihula wrote:
> Support for graceful handling of sleep states (S3/S4/S5) after an Intel(R) TXT launch.
>
> Without this patch, attempting to place the system in one of the ACPI sleep
> states (S3/S4/S5) will cause the TXT hardware to treat this as an attack and
> will cause a system reset, with memory locked. Not only may the subsequent
> memory scrub take some time, but the platform will be unable to enter the
> requested power state.
>
> This patch calls back into the tboot so that it may properly and securely clean
> up system state and clear the secrets-in-memory flag, after which it will place
> the system into the requested sleep state using ACPI information passed by the kernel.

I don't get this. In case of hibernation... how do you 'protect' the
data in memory?

This really needs big Documentation/ patch explaining the design
before it can be reviewed properly.

What does it protect? All kernel memory? How does it handle S3? Who
does encryption for hibernation?

--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html