Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp406376imn; Wed, 3 Aug 2022 08:53:27 -0700 (PDT) X-Google-Smtp-Source: AA6agR4C7OwGESH5bk7n5efZ4UjN4x7lD/iS8IvJ/SwiA7OioeRaUMYxDdWhlaHRdtolC1o9PQac X-Received: by 2002:a17:902:f608:b0:16d:20a0:5339 with SMTP id n8-20020a170902f60800b0016d20a05339mr26281734plg.133.1659542007721; Wed, 03 Aug 2022 08:53:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659542007; cv=none; d=google.com; s=arc-20160816; b=qJZWKDOMZ48k3NlbE5Wt5vua1oC1kuF4LmD30bkrX9s9tjwifHC+r3Navi/+zE9Rt8 1KhD6crPBINlEvzT9sjP6YO4KZqa0S786Q0iWY7TQ4ppZHXC/8Kadou5YC15LO711yHo WTZSPnv6aR7Mfi6BZTfEXn4biDkE8mQggtXRy5lIQkC71wc4OVtcI3LJJpEhzEiA5kqv g6FzBcWMuvR/ItmcIy9GAjDxTS0hsAn6ZbTbTzFuTrhacY58tnRB71Sh8lfKXSazs1T+ UkE2OO8wuxwd/t/JRYK0QpkHZp2dVfNMC+X3Rs5WC3zb0jcbaK2ectemr0FOpQyxRbD2 Reqw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=VtSzKXeXuo8UPe5oGViC3ZV9LBnnbbE6LXAjjaS3w3c=; b=oqxN/zZFeldMYjwV9tLDeq+QDmuUV/LskmP2F2Bm3f7bnpWKH6Lz8r0sQxGDbPfJzD EnP8DqNRR1Ni3q11BYUiD1/tHsJWdG9RY3KxSfE9se2zP9QyJHlAMj3Hg1Ikp1oZPu5L 9FynriF8ygaiGNXZN5cHF46B5VE+KRGg1l6zKR09ts2JB9teV4PsKnt6g4BD+m/U7kw7 iB7/NAg4LwhwmKj0AS+aMH5LTKusd/95AJGY3yFFTfMTaeIMWMs3b7VZy3VCnHwJI4Dx MoVhHWglhE3jMEWFoWTmvnh8/7FkftbBoPdthIWN50kEFEN26+PPukp0hNp+XXpOIT/n RCTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="JA8/p8Bp"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q16-20020a056a00151000b00527cbdcec6bsi21163839pfu.150.2022.08.03.08.53.11; Wed, 03 Aug 2022 08:53:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="JA8/p8Bp"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S238151AbiHCPvY (ORCPT + 99 others); Wed, 3 Aug 2022 11:51:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238330AbiHCPu6 (ORCPT ); Wed, 3 Aug 2022 11:50:58 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0EAC65582 for ; Wed, 3 Aug 2022 08:50:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659541847; 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: in-reply-to:in-reply-to:references:references; bh=VtSzKXeXuo8UPe5oGViC3ZV9LBnnbbE6LXAjjaS3w3c=; b=JA8/p8Bph9p43AkK3xlxW73lqMnVBhOoLtBZCgvyZGiS+78ADDHNfP11mLxQ7GuVVjHJz7 u1oczODo1FHMMgaUX/L+PlSE+V+CidyDt7Akr1pte9yPIVVblALjeMcWYUohj5WRFYJQdh vlcywwmueVusZRCMn8amdQe7bQggdIY= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-30-dM8-sA2IPP-VlC_VoGipsQ-1; Wed, 03 Aug 2022 11:50:43 -0400 X-MC-Unique: dM8-sA2IPP-VlC_VoGipsQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6A87E185A794; Wed, 3 Aug 2022 15:50:42 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.194.242]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9A3A21121314; Wed, 3 Aug 2022 15:50:38 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: Borislav Petkov , Dave Hansen , linux-kernel@vger.kernel.org, Wanpeng Li , Maxim Levitsky , Ingo Molnar , Sean Christopherson , x86@kernel.org, Jim Mattson , Kees Cook , Thomas Gleixner , "H. Peter Anvin" , Joerg Roedel , Vitaly Kuznetsov , Paolo Bonzini Subject: [PATCH v3 06/13] KVM: x86: emulator/smm: number of GPRs in the SMRAM image depends on the image format Date: Wed, 3 Aug 2022 18:50:04 +0300 Message-Id: <20220803155011.43721-7-mlevitsk@redhat.com> In-Reply-To: <20220803155011.43721-1-mlevitsk@redhat.com> References: <20220803155011.43721-1-mlevitsk@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 64 bit host, if the guest doesn't have X86_FEATURE_LM, KVM will access 16 gprs to 32-bit smram image, causing out-ouf-bound ram access. On 32 bit host, the rsm_load_state_64/enter_smm_save_state_64 is compiled out, thus access overflow can't happen. Fixes: b443183a25ab61 ("KVM: x86: Reduce the number of emulator GPRs to '8' for 32-bit KVM") Signed-off-by: Maxim Levitsky Reviewed-by: Sean Christopherson --- arch/x86/kvm/emulate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 765ec65b2861ba..18551611cb13af 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c @@ -2473,7 +2473,7 @@ static int rsm_load_state_32(struct x86_emulate_ctxt *ctxt, ctxt->eflags = GET_SMSTATE(u32, smstate, 0x7ff4) | X86_EFLAGS_FIXED; ctxt->_eip = GET_SMSTATE(u32, smstate, 0x7ff0); - for (i = 0; i < NR_EMULATOR_GPRS; i++) + for (i = 0; i < 8; i++) *reg_write(ctxt, i) = GET_SMSTATE(u32, smstate, 0x7fd0 + i * 4); val = GET_SMSTATE(u32, smstate, 0x7fcc); @@ -2530,7 +2530,7 @@ static int rsm_load_state_64(struct x86_emulate_ctxt *ctxt, u16 selector; int i, r; - for (i = 0; i < NR_EMULATOR_GPRS; i++) + for (i = 0; i < 16; i++) *reg_write(ctxt, i) = GET_SMSTATE(u64, smstate, 0x7ff8 - i * 8); ctxt->_eip = GET_SMSTATE(u64, smstate, 0x7f78); -- 2.26.3