From patchwork Mon Aug 9 14:53:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emanuele Giuseppe Esposito X-Patchwork-Id: 12426727 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.5 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=ham 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 8566AC4338F for ; Mon, 9 Aug 2021 14:54:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5CA0E61077 for ; Mon, 9 Aug 2021 14:54:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235045AbhHIOzO (ORCPT ); Mon, 9 Aug 2021 10:55:14 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:54193 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235126AbhHIOzA (ORCPT ); Mon, 9 Aug 2021 10:55:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628520879; 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=Of72I49nauR2VhDblZZ+5IyF6nFKX4mvsTZhOlXnK2k=; b=b+ypKdAog2JbkTFovp2QJoPbyz0uQDOQrcnuEaSDZFAqBuIKcYLNGyg5iHKtlYmkpl/COA GLphoJkTw8QSTKD6f8Dl/3L0F0camr78U7q1B8JYVJeETTw4bTYvwgHEbaCLcNH0EfoM8w rJdrC93AJE1LUwa81Y1ljrVk42gw2qU= 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-456-4GVZdNtbNf2kvaxqGV2MhQ-1; Mon, 09 Aug 2021 10:54:37 -0400 X-MC-Unique: 4GVZdNtbNf2kvaxqGV2MhQ-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 7A9D910AFE50; Mon, 9 Aug 2021 14:54:24 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.193.220]) by smtp.corp.redhat.com (Postfix) with ESMTP id 62D9B749BB; Mon, 9 Aug 2021 14:53:44 +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 , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , linux-kernel@vger.kernel.org, Emanuele Giuseppe Esposito Subject: [PATCH 0/2] KVM: nSVM: avoid TOC/TOU race when checking vmcb12 Date: Mon, 9 Aug 2021 16:53:41 +0200 Message-Id: <20210809145343.97685-1-eesposit@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Currently there is a TOC/TOU race between the first 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 1) moves the actual check nearer to the usage (from nested_svm_vmrun to enter_svm_guest_mode), possible thanks to the patch "KVM: nSVM: remove useless kvm_clear_*_queue" and 2) adds local variables 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 refactors the code to simplify the second patch, where we move the TOC nearer to the TOU and use local variables. Based-on: <20210802125634.309874-1-pbonzini@redhat.com> Signed-off-by: Emanuele Giuseppe Esposito Emanuele Giuseppe Esposito (2): KVM: nSVM: move nested_vmcb_check_cr3_cr4 logic in nested_vmcb_valid_sregs KVM: nSVM: temporarly save vmcb12's efer, cr0 and cr4 to avoid TOC/TOU races arch/x86/kvm/svm/nested.c | 99 ++++++++++++++++++--------------------- 1 file changed, 45 insertions(+), 54 deletions(-)