Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp348651pxb; Mon, 25 Oct 2021 09:26:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxxjS9mgDxvYULsY14EgQPGuwySKK7EGWfhXP+ckxfRO+zxjstLIdweRFMDEx0IObwuBD4G X-Received: by 2002:a17:90b:38c1:: with SMTP id nn1mr6730204pjb.83.1635179218108; Mon, 25 Oct 2021 09:26:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635179218; cv=none; d=google.com; s=arc-20160816; b=pv7dCxZWEF2zAREY3mjnV386Q3JtrAmZ2XeZB6w///9sbnEUKCl2NrHyMIB0VzjMNh xJQOuiYDHK7hv0hN678qUPXoXiuQnKJwpfYs1x0x0IqRTLPdcIEewY1WDrHyL2ta3NYX qMZXCTkHDvCkJZ2iyzucHi9OoALnocMCl9xvrCiZ0AYBOnch0WtD5JgREzQW6mPP5HlQ byqxOsOk5JfeoCfvcw/GbjgJ/mY2lvh7r+3dGdXj8s92A9Li2JB/lgNgXo/jSX58XO1U THtY0xAWqbtpNKyczpiY8rx9bkaPtIoLFwGMvwYJ9KOucnLNajdN0J62y1mkpZR52aQ+ FrsA== 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=9YLgAyXs3K5Wk/mUtAnrMI4Vyi1II+Ednpwsx4xkjsg=; b=hsMgXwDlvcF+WNHxMpjijJKEzt8fO7X7MIP0k61nItiZdVXIUERt9f/utjNeFwA2Yq geZnn8vo4e1Nm8s8i6B39kzgxVwJDctY2rLpmEdGwaZYQXvaMgaDh9yQ6S01JHWl3HmB PlbuzbU73HnaDBpJvA2PIlxQ9QVqN/7hbpYzeNONOmLQnqd45Y3q4RBhGPYuyc+uFDtp OIxKZrDeSXw1Djm3LxeBU2BDfjVJbVxoB3y78S7um1vdL+5FCEjEfVN6ruaFikrxPFMk a3FRSboI6D3lk2bnPxjkhpxU5MpqX6h9uykOOLNnZxpRkudl3m0q9T9XYqLjs3Dirf6b xSYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=SDRT3Mxj; 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 u11si16171998pgh.201.2021.10.25.09.26.44; Mon, 25 Oct 2021 09:26:58 -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=SDRT3Mxj; 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 S233953AbhJYQ1r (ORCPT + 99 others); Mon, 25 Oct 2021 12:27:47 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:26590 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232362AbhJYQ1q (ORCPT ); Mon, 25 Oct 2021 12:27:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635179123; 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=9YLgAyXs3K5Wk/mUtAnrMI4Vyi1II+Ednpwsx4xkjsg=; b=SDRT3MxjxG07l+8aAMGxGHbCCvpdZ1MDJ2m7cstVQmjYcGd4H4YN3HRD4pLvtV74gaGTPf blWx6ezKFlf1PC2KC5lDiLxWr247jM/q+xrLKBU5mYdB7b0jAkxJdRdAnRMcfO3nlgK0tA dPe7uUFIa+04q4/+8TPvk9KJHWR/9fo= 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-445-XUWSV9jrNmSCROQHdAeHxw-1; Mon, 25 Oct 2021 12:25:20 -0400 X-MC-Unique: XUWSV9jrNmSCROQHdAeHxw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3DFB2802682; Mon, 25 Oct 2021 16:25:19 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id CC97E1037F3B; Mon, 25 Oct 2021 16:25:18 +0000 (UTC) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: stable@vger.kernel.org, Marc Orr Subject: [PATCH] KVM: SEV-ES: fix another issue with string I/O VMGEXITs Date: Mon, 25 Oct 2021 12:25:17 -0400 Message-Id: <20211025162517.2152628-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If the guest requests string I/O from the hypervisor via VMGEXIT, SW_EXITINFO2 will contain the REP count. However, sev_es_string_io was incorrectly treating it as the size of the GHCB buffer in bytes. This fixes the "outsw" test in the experimental SEV tests of kvm-unit-tests. Cc: stable@vger.kernel.org Fixes: 7ed9abfe8e9f ("KVM: SVM: Support string IO operations for an SEV-ES guest") Reported-by: Marc Orr Signed-off-by: Paolo Bonzini --- arch/x86/kvm/svm/sev.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index e672493b5d8d..12d29d669cbc 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -2579,11 +2579,16 @@ int sev_handle_vmgexit(struct kvm_vcpu *vcpu) int sev_es_string_io(struct vcpu_svm *svm, int size, unsigned int port, int in) { - if (!setup_vmgexit_scratch(svm, in, svm->vmcb->control.exit_info_2)) + u32 bytes; + + if (unlikely(check_mul_overflow(svm->vmcb->control.exit_info_2, size, &bytes))) + return -EINVAL; + + if (!setup_vmgexit_scratch(svm, in, bytes)) return -EINVAL; - return kvm_sev_es_string_io(&svm->vcpu, size, port, - svm->ghcb_sa, svm->ghcb_sa_len / size, in); + return kvm_sev_es_string_io(&svm->vcpu, size, port, svm->ghcb_sa, + svm->vmcb->control.exit_info_2, in); } void sev_es_init_vmcb(struct vcpu_svm *svm) -- 2.27.0