KVM: x86: selftests: add L1TF exploit test
cover KVM: x86: selftests: add L1TF exploit test
This has been tested on a Google Skylake platform.
One potential issue with this test is that it fails (that is, the exploit succeeds) when using the conditional L1D flush, because the gadget is injected into the hypercall path which doesn't appear to include a flush. If this is unacceptable, we should discuss how to amend the test so that it can be used to evaluate the conditional flush logic as well. This would basically mean simulating some more complicated gadget where the "attacker" has found another way to steer the host kernel towards the target data, instead of just a simple hypercall.
The reason this limitation is tolerable to me is my ulterior motive, i.e. because I am specifically interested in an end-to-end test for Address Space Isolation [0], which is abstracted from these details of the exploit.
Based on kvm/next.
[0] https://lore.kernel.org/all/[email protected]/T/#t
---
Alexandra Sandulescu (1):
KVM: x86: selftests: add an L1TF exploit test
Brendan Jackman (1):
selftests: fix installing nested TEST_GEN_MODS_DIR
tools/testing/selftests/kvm/Makefile.kvm | 7 + tools/testing/selftests/kvm/x86/l1tf_test.c | 633 +++++++++++++++++++++ tools/testing/selftests/kvm/x86/l1tf_test.sh | 10 + .../selftests/kvm/x86/test_modules/Makefile | 10 + .../kvm/x86/test_modules/l1tf_test_helper.c | 92 +++ tools/testing/selftests/lib.mk | 2 +- 6 files changed, 753 insertions(+), 1 deletion(-)
---
base-commit: 6b36119b94d0b2bb8cea9d512017efafd461d6ac
change-id: 20251013-l1tf-test-1bee540cefb4
Best regards,
Signature · 1 line
Brendan Jackman <[email protected]>
PATCH 1/2 selftests: fix installing nested TEST_GEN_MODS_DIR
Currently all users of TEST_GEN_MODS_DIR set it to a single-element path like "test_modules". This means that the $(notdir) call in specified to be a nop.
However in a subsequent patch a user will be added that needs to nest the module directory under an arch-specific subdirectory, which means this $(notdir) breaks the modules installation. So remove it.
--- tools/testing/selftests/lib.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/lib.mk +1 -1
@@ -166,7 +166,7 @@ define INSTALL_RULE $(eval INSTALL_LIST = $(TEST_CUSTOM_PROGS)) $(INSTALL_SINGLE_RULE) $(eval INSTALL_LIST = $(TEST_GEN_PROGS_EXTENDED)) $(INSTALL_SINGLE_RULE) $(eval INSTALL_LIST = $(TEST_GEN_FILES)) $(INSTALL_SINGLE_RULE) - $(eval INSTALL_LIST = $(notdir $(TEST_GEN_MODS_DIR))) $(INSTALL_MODS_RULE) + $(eval INSTALL_LIST = $(TEST_GEN_MODS_DIR)) $(INSTALL_MODS_RULE) $(eval INSTALL_LIST = $(wildcard config settings)) $(INSTALL_SINGLE_RULE) endef
Signature · 1 line
2.50.1
PATCH 2/2 KVM: x86: selftests: add an L1TF exploit test
In reply to Brendan JackmanFrom: Alexandra Sandulescu <[email protected]>
Add a test for basic smoke-checking that L1TF mitigations are doing what they should.
The test sets up the environment for an L1TF exploit executed by a virtual machine. The exploit reads data that belongs to a different process (running on a different physical CPU) at a known physical address.
The test succeeds if it cannot read the victim data correctly, thus suggesting that an L1TF exploit for this threat model is infeasible. The test fails if it correctly reads the victim data as a result of the L1TF exploit.
The test requirements are: the machine is vulnerable to L1TF and the helper kernel module is loaded prior to the test execution. The test should pass when the kernel enables asi (asi=on). Environments where the module can't be loaded (including machines without kprobes support) will SKIP the test.
--- tools/testing/selftests/kvm/Makefile.kvm | 7 + tools/testing/selftests/kvm/x86/l1tf_test.c | 633 +++++++++++++++++++++ tools/testing/selftests/kvm/x86/l1tf_test.sh | 10 + .../selftests/kvm/x86/test_modules/Makefile | 10 + .../kvm/x86/test_modules/l1tf_test_helper.c | 92 +++ 5 files changed, 752 insertions(+)
tools/testing/selftests/kvm/Makefile.kvm +7 -0
@@ -54,6 +54,7 @@ LIBKVM_loongarch += lib/loongarch/exception.S # Non-compiled test targets TEST_PROGS_x86 += x86/nx_huge_pages_test.sh +TEST_PROGS_x86 += x86/l1tf_test.sh # Compiled test targets valid on all architectures with libkvm support TEST_GEN_PROGS_COMMON = demand_paging_test
@@ -152,6 +153,7 @@ TEST_GEN_PROGS_x86 += pre_fault_memory_test # Compiled outputs used by test targets TEST_GEN_PROGS_EXTENDED_x86 += x86/nx_huge_pages_test +TEST_GEN_PROGS_EXTENDED_x86 += x86/l1tf_test TEST_GEN_PROGS_arm64 = $(TEST_GEN_PROGS_COMMON) TEST_GEN_PROGS_arm64 += arm64/aarch32_id_regs
@@ -223,12 +225,17 @@ TEST_GEN_PROGS_loongarch += memslot_modification_stress_test TEST_GEN_PROGS_loongarch += memslot_perf_test TEST_GEN_PROGS_loongarch += set_memory_region_test +TEST_GEN_MODS_DIR_x86 = x86/test_modules/ + SPLIT_TESTS += arch_timer SPLIT_TESTS += get-reg-list TEST_PROGS += $(TEST_PROGS_$(ARCH)) TEST_GEN_PROGS += $(TEST_GEN_PROGS_$(ARCH)) TEST_GEN_PROGS_EXTENDED += $(TEST_GEN_PROGS_EXTENDED_$(ARCH)) +ifneq ($(TEST_GEN_MODS_DIR_$(ARCH)),) + TEST_GEN_MODS_DIR = $(TEST_GEN_MODS_DIR_$(ARCH)) +endif LIBKVM += $(LIBKVM_$(ARCH)) OVERRIDE_TARGETS = 1
tools/testing/selftests/kvm/x86/l1tf_test.c new file +633 -0
633 lines not on this page · raw message
tools/testing/selftests/kvm/x86/l1tf_test.sh new file +10 -0
@@ -0,0 +1,10 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: GPL-2.0 + +insmod x86/test_modules/l1tf_test_helper.ko + +./l1tf_test +status=$? +rmmod l1tf_test_helper + +exit $status
tools/testing/selftests/kvm/x86/test_modules/Makefile new file +10 -0
@@ -0,0 +1,10 @@ +TESTMODS_DIR := $(realpath $(dir $(abspath $(lastword $(MAKEFILE_LIST))))) +KDIR ?= /lib/modules/$(shell uname -r)/build + +obj-m += l1tf_test_helper.o + +modules: + $(Q)$(MAKE) -C $(KDIR) modules KBUILD_EXTMOD=$(TESTMODS_DIR) + +clean: + $(Q)$(MAKE) -C $(KDIR) clean KBUILD_EXTMOD=$(TESTMODS_DIR)
tools/testing/selftests/kvm/x86/test_modules/l1tf_test_helper.c new file +92 -0
92 lines not on this page · raw message
Signature · 1 line
2.50.1
Re: [PATCH 2/2] KVM: x86: selftests: add an L1TF exploit test
Quoted 3 lines · Brendan Jackman
The test requirements are: the machine is vulnerable to L1TF and the helper kernel module is loaded prior to the test execution. The test should pass when the kernel enables asi (asi=on).
Agh, sorry, I missed a bit when scrubbing the commit message, there should not be mentions of ASI in here.