Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760010AbaGPCtM (ORCPT ); Tue, 15 Jul 2014 22:49:12 -0400 Received: from mail-pa0-f54.google.com ([209.85.220.54]:55653 "EHLO mail-pa0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759208AbaGPCsj (ORCPT ); Tue, 15 Jul 2014 22:48:39 -0400 From: Andy Lutomirski To: kvm@vger.kernel.org, "H. Peter Anvin" , "Theodore Ts'o" , linux-kernel@vger.kernel.org, Kees Cook , x86@kernel.org Cc: Daniel Borkmann , Srivatsa Vaddagiri , Raghavendra K T , Andy Lutomirski Subject: [PATCH 4/4] x86,kaslr: Use MSR_KVM_GET_RNG_SEED for KASLR if available Date: Tue, 15 Jul 2014 19:48:10 -0700 Message-Id: <14a475cbeaf73ac45e6073f83c4e1386cd7f6a2b.1405477965.git.luto@amacapital.net> X-Mailer: git-send-email 1.9.3 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It's considerably better than any of the alternatives on KVM. Signed-off-by: Andy Lutomirski --- arch/x86/boot/compressed/aslr.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/arch/x86/boot/compressed/aslr.c b/arch/x86/boot/compressed/aslr.c index fc6091a..8583f0e 100644 --- a/arch/x86/boot/compressed/aslr.c +++ b/arch/x86/boot/compressed/aslr.c @@ -5,6 +5,8 @@ #include #include +#include + #include #include #include @@ -15,6 +17,22 @@ static const char build_str[] = UTS_RELEASE " (" LINUX_COMPILE_BY "@" LINUX_COMPILE_HOST ") (" LINUX_COMPILER ") " UTS_VERSION; +static bool kvm_para_has_feature(unsigned int feature) +{ + u32 kvm_base; + u32 features; + + if (!has_cpuflag(X86_FEATURE_HYPERVISOR)) + return false; + + kvm_base = hypervisor_cpuid_base("KVMKVMKVM\0\0\0", KVM_CPUID_FEATURES); + if (!kvm_base) + return false; + + features = cpuid_eax(kvm_base | KVM_CPUID_FEATURES); + return features & (1UL << feature); +} + #define I8254_PORT_CONTROL 0x43 #define I8254_PORT_COUNTER0 0x40 #define I8254_CMD_READBACK 0xC0 @@ -81,6 +99,15 @@ static unsigned long get_random_long(void) } } + if (kvm_para_has_feature(KVM_FEATURE_GET_RNG_SEED)) { + u64 seed; + + debug_putstr(" MSR_KVM_GET_RNG_SEED"); + rdmsrl(MSR_KVM_GET_RNG_SEED, seed); + random ^= (unsigned long)seed; + use_i8254 = false; + } + if (has_cpuflag(X86_FEATURE_TSC)) { debug_putstr(" RDTSC"); rdtscll(raw); -- 1.9.3 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/