From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 53FDBC433F5 for ; Fri, 3 Sep 2021 10:21:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3042F60724 for ; Fri, 3 Sep 2021 10:21:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349111AbhICKV6 (ORCPT ); Fri, 3 Sep 2021 06:21:58 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:42283 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349025AbhICKV5 (ORCPT ); Fri, 3 Sep 2021 06:21:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630664456; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=oFjutN94K9gmEDW/+9c5bQZXpnE4pWkZ70awo3wyftQ=; b=G282iCCXM4X1qEWgSluR51N/QZFbIp0jRHoyDfEWkX4qjfwQJ6CBGgm/ItBPaIZgzNZjgr d0dECmK68NqJwAEolRANzBrpFWxBrz4x7XHmDf1CPYT10SM1MTsV1otOQC6Hizy4yA5TuM SiJlNG3zlDZvUhbr41X3itqdooWnvRM= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-438-Ee7czsVxPgyUsqbdtL0lSA-1; Fri, 03 Sep 2021 06:20:53 -0400 X-MC-Unique: Ee7czsVxPgyUsqbdtL0lSA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CC24F501E0; Fri, 3 Sep 2021 10:20:51 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.193.161]) by smtp.corp.redhat.com (Postfix) with ESMTP id 088BF5D9C6; Fri, 3 Sep 2021 10:20:46 +0000 (UTC) From: Emanuele Giuseppe Esposito To: kvm@vger.kernel.org Cc: Paolo Bonzini , Maxim Levitsky , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , linux-kernel@vger.kernel.org, Emanuele Giuseppe Esposito Subject: [RFC PATCH 0/3] KVM: nSVM: avoid TOC/TOU race when checking vmcb12 Date: Fri, 3 Sep 2021 12:20:36 +0200 Message-Id: <20210903102039.55422-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently there is a TOC/TOU race between the check of vmcb12's efer, cr0 and cr4 registers and the later save of their values in svm_set_*, because the guest could modify the values in the meanwhile. To solve this issue, this serie introuces and uses svm->nested.save structure in enter_svm_guest_mode to save the current value of efer, cr0 and cr4 and later use these to set the vcpu->arch.* state. Patch 1 just refactor the code to simplify the next two patches, patch 2 introduces svm->nested.save to cache the efer, cr0 and cr4 fields and in patch 3 we use it to avoid TOC/TOU races. Signed-off-by: Emanuele Giuseppe Esposito --- v1 -> RFC: - use svm->nested.save instead of local variables. - not dependent anymore from "KVM: nSVM: remove useless kvm_clear_*_queue" - simplified patches, we just use the struct and not move the check nearer to the TOU. Emanuele Giuseppe Esposito (3): KVM: nSVM: move nested_vmcb_check_cr3_cr4 logic in nested_vmcb_valid_sregs nSVM: introduce smv->nested.save to cache save area fields nSVM: use svm->nested.save to load vmcb12 registers and avoid TOC/TOU races arch/x86/kvm/svm/nested.c | 82 ++++++++++++++++++++------------------- arch/x86/kvm/svm/svm.c | 1 + arch/x86/kvm/svm/svm.h | 3 ++ 3 files changed, 47 insertions(+), 39 deletions(-) -- 2.27.0