Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp339581pxb; Fri, 3 Sep 2021 03:22:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzUXDDNp/WNgyF2nTMbL/oVyAcJjlbcKhpBEmiz3/CDRoBCnwUlawS+IepVzI4xKi+0SU5i X-Received: by 2002:aa7:c1ca:: with SMTP id d10mr3250453edp.294.1630664577753; Fri, 03 Sep 2021 03:22:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630664577; cv=none; d=google.com; s=arc-20160816; b=zdUDbJe6ZjZaADlKYd9thxsY60i2bqxip6Vzdtw57tNnPVkx9iHmvAQOST3AOGJMEQ NtOxXNKPcnFCEXX54VZJat7yeRLCdn5buNl7HvYSxkDpgR/I6E35RCd7FYScBwafyS9J GVj2Y2cgmVlHFChKZouEBHV2LjvzdmQuKgAfrDr5p+wu+qYdCwKFU3yIip7hx/Z3HCvc dpcPBb4HR648YIjUX/RwOKhEhBE2XCe7QytWbGjDg4IkItx+pLrNpKetNBLzGepJL4s6 86fi3GxIrXWYykaLlUY7wUwK/7h5lWj8tsHAZRZ1okFwwpReAB7JPcv6Bo1+OtXTYbpV I2dw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=oFjutN94K9gmEDW/+9c5bQZXpnE4pWkZ70awo3wyftQ=; b=QEJiWRZyUA1Ocbxhly7c+caCsRpivNl1vwgJYsfmbfaLDWoFikL2Hzzo1Gsach8+IA Av+u8ZAuGt4Bu/7Hd9MWaSKHS3IpbB7EUHTJ5yI0FA726e1B1qkmxCCdYkkmmiBwy81r ER3QkQSHThZ25Z4vZVcCNeyyC3wVEcCyIbtiKEFDB3nAYljTlwtP5vVEnqFs50cO3VUN s4acpYc8bcGKFrci3dg54mSS7ebwpSgbaLrG6ROO2sKPm7gEeMrekkjeZYcm96zgGbhX 38dJRYCHQm8dNL7FlhgurXHkyG84TCt+8hPLfIfMBSW81+kVVDo97aa1zpZGFqEAuYIF WHTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=G282iCCX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b8si4908683edd.29.2021.09.03.03.22.31; Fri, 03 Sep 2021 03:22:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=G282iCCX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349107AbhICKV5 (ORCPT + 99 others); Fri, 3 Sep 2021 06:21:57 -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