Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752579AbbELDQu (ORCPT ); Mon, 11 May 2015 23:16:50 -0400 Received: from mga09.intel.com ([134.134.136.24]:38657 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752233AbbELDQt (ORCPT ); Mon, 11 May 2015 23:16:49 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,411,1427785200"; d="scan'208";a="693421533" Message-ID: <55516FCD.4020503@linux.intel.com> Date: Tue, 12 May 2015 11:13:17 +0800 From: Xiao Guangrong User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: pbonzini@redhat.com CC: gleb@kernel.org, mtosatti@redhat.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] check smap and !cr0.wp References: <1430988242-7186-1-git-send-email-guangrong.xiao@linux.intel.com> In-Reply-To: <1430988242-7186-1-git-send-email-guangrong.xiao@linux.intel.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2203 Lines: 76 Hi Paolo, Could you please apply this patch to kvm-unit-tests if it looks good to you? Thanks! On 05/07/2015 04:44 PM, Xiao Guangrong wrote: > This test case is used to produce the bug that: > > KVM may turn a user page to a kernel page when kernel writes a readonly > user page if CR0.WP = 1. This shadow page entry will be reused after > SMAP is enabled so that kernel is allowed to access this user page > > Signed-off-by: Xiao Guangrong > --- > x86/smap.c | 26 ++++++++++++++++++++++++++ > 1 file changed, 26 insertions(+) > > diff --git a/x86/smap.c b/x86/smap.c > index 042c5aa..66f97b8 100644 > --- a/x86/smap.c > +++ b/x86/smap.c > @@ -48,6 +48,7 @@ asm ("pf_tss:\n" > > #define USER_BASE (1 << 24) > #define USER_VAR(v) (*((__typeof__(&(v))) (((unsigned long)&v) + USER_BASE))) > +#define USER_ADDR(v) ((void *)((unsigned long)(&v) + USER_BASE)) > > static void init_test(int i) > { > @@ -58,6 +59,29 @@ static void init_test(int i) > } > } > > +static void check_smap_nowp(void) > +{ > + test = 0x99; > + > + *get_pte(phys_to_virt(read_cr3()), USER_ADDR(test)) &= ~PTE_WRITE; > + > + write_cr4(read_cr4() & ~X86_CR4_SMAP); > + write_cr0(read_cr0() & ~X86_CR0_WP); > + clac(); > + write_cr3(read_cr3()); > + > + init_test(0); > + USER_VAR(test) = 0x99; > + report("write from user page with SMAP=0, AC=0, WP=0, PTE.U=1 && PTE.W=0", pf_count == 0); > + > + write_cr4(read_cr4() | X86_CR4_SMAP); > + write_cr3(read_cr3()); > + > + init_test(0); > + (void)USER_VAR(test); > + report("read from user page with SMAP=1, AC=0, WP=0, PTE.U=1 && PTE.W=0", pf_count == 1 && save == 0x99); > +} > + > int main(int ac, char **av) > { > unsigned long i; > @@ -150,6 +174,8 @@ int main(int ac, char **av) > report("executing on user page with AC=0", pf_count == 0); > } > > + check_smap_nowp(); > + > // TODO: implicit kernel access from ring 3 (e.g. int) > > return report_summary(); > -- 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/