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 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EB7EAC433FE for ; Mon, 1 Nov 2021 10:27:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D3E6C61058 for ; Mon, 1 Nov 2021 10:27:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232161AbhKAKaQ (ORCPT ); Mon, 1 Nov 2021 06:30:16 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:49261 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232097AbhKAKaN (ORCPT ); Mon, 1 Nov 2021 06:30:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635762459; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=2uCAdP1QdrurNg3VYXaeroiWVBLb/WhdrZPNJcrlkas=; b=MQzhnsEEl4mSJQx7nykcpC1Gkaq9Sn2kse3zTfcLtk2SMeJn6j5PTz63LOTRYZFzu4svXh qTgFl/xEHUVefzOwvjd7r6nBq7mzopa29eMGUIviuY63kFOlz+UdJqmTqla2mqIlkC/+ow NLvC0mgTXgO2c3+9CXETogYxESCz1Gw= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-6-mA7IfEoaMNyEoJg3Y3jqug-1; Mon, 01 Nov 2021 06:27:38 -0400 X-MC-Unique: mA7IfEoaMNyEoJg3Y3jqug-1 Received: by mail-ed1-f69.google.com with SMTP id w11-20020a05640234cb00b003e0cd525777so10429327edc.12 for ; Mon, 01 Nov 2021 03:27:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=2uCAdP1QdrurNg3VYXaeroiWVBLb/WhdrZPNJcrlkas=; b=B7u3iazddYnLp3iXDNZxc3WkPlkia333P8jPJgxiB8AYJYoe7YicX7/OfOGDN7QkHy DY4JolXl8OQ9uASK1J0kV4+TKkVqGhiNs97jzJnzuaQDFnQfKkIGYYTawla660nT0Mgz ec9mNdAppe+HK7TGuLdhixXVlsCUVkcSpfCXsMyk+BC4PKVgBP34G3v/aEXpJZ6kaNhp d/KgkWwbijjmrJemXyYcBVxn/SXYQJb/qaIlgOyyfDFda93J3ezq5UbXlOcEGhncKws7 q3nf1jJGR33DchUB47YALy23ASMSKYrreSG/aUV3dMYgNvCgEJb+K2d7sYcyoc6APN/r KyIQ== X-Gm-Message-State: AOAM532bxKXW/PfK7s8MX1kTL/Nu+apsa0UyNKqU5XQEwNO+sOrxMkPW oB/jr73SOyhHFmrO/85hj0D/f6c1g6itZXUhfMBJOybMt8ZG1DFI762esYEQpDuMCtngIhrTww+ b+xvSSQO3uUH3d/Qxzb+NrGIT X-Received: by 2002:a17:907:3e0a:: with SMTP id hp10mr5140870ejc.318.1635762456899; Mon, 01 Nov 2021 03:27:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzjZIaZvRfLbelCks3Bnp4YpkcYtDKg2/JML94gJgBsswZs4QJjAUtfEbZjra2xURRbQh3eqA== X-Received: by 2002:a17:907:3e0a:: with SMTP id hp10mr5140840ejc.318.1635762456689; Mon, 01 Nov 2021 03:27:36 -0700 (PDT) Received: from vitty.brq.redhat.com (g-server-2.ign.cz. [91.219.240.2]) by smtp.gmail.com with ESMTPSA id z9sm9254464edb.70.2021.11.01.03.27.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 03:27:36 -0700 (PDT) From: Vitaly Kuznetsov To: Sean Christopherson Cc: Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, Ajay Garg , Paolo Bonzini , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , Wei Liu , Dexuan Cui , Arnd Bergmann Subject: Re: [PATCH v2 7/8] KVM: x86: Reject fixeds-size Hyper-V hypercalls with non-zero "var_cnt" In-Reply-To: <20211030000800.3065132-8-seanjc@google.com> References: <20211030000800.3065132-1-seanjc@google.com> <20211030000800.3065132-8-seanjc@google.com> Date: Mon, 01 Nov 2021 11:27:34 +0100 Message-ID: <87y268jhm1.fsf@vitty.brq.redhat.com> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-hyperv@vger.kernel.org Sean Christopherson writes: > Reject Hyper-V hypercalls if the guest specifies a non-zero variable size > header (var_cnt in KVM) for a hypercall that has a fixed header size. > Per the TLFS: > > It is illegal to specify a non-zero variable header size for a > hypercall that is not explicitly documented as accepting variable sized > input headers. In such a case the hypercall will result in a return > code of HV_STATUS_INVALID_HYPERCALL_INPUT. > > Signed-off-by: Sean Christopherson > --- > arch/x86/kvm/hyperv.c | 17 +++++++++++------ > 1 file changed, 11 insertions(+), 6 deletions(-) > > diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c > index 3d83d6a5d337..ad455df850c9 100644 > --- a/arch/x86/kvm/hyperv.c > +++ b/arch/x86/kvm/hyperv.c > @@ -2241,14 +2241,14 @@ int kvm_hv_hypercall(struct kvm_vcpu *vcpu) > > switch (hc.code) { > case HVCALL_NOTIFY_LONG_SPIN_WAIT: > - if (unlikely(hc.rep)) { > + if (unlikely(hc.rep || hc.var_cnt)) { > ret = HV_STATUS_INVALID_HYPERCALL_INPUT; > break; > } > kvm_vcpu_on_spin(vcpu, true); > break; > case HVCALL_SIGNAL_EVENT: > - if (unlikely(hc.rep)) { > + if (unlikely(hc.rep || hc.var_cnt)) { > ret = HV_STATUS_INVALID_HYPERCALL_INPUT; > break; > } > @@ -2258,7 +2258,7 @@ int kvm_hv_hypercall(struct kvm_vcpu *vcpu) > fallthrough; /* maybe userspace knows this conn_id */ > case HVCALL_POST_MESSAGE: > /* don't bother userspace if it has no way to handle it */ > - if (unlikely(hc.rep || !to_hv_synic(vcpu)->active)) { > + if (unlikely(hc.rep || hc.var_cnt || !to_hv_synic(vcpu)->active)) { > ret = HV_STATUS_INVALID_HYPERCALL_INPUT; > break; > } > @@ -2271,14 +2271,14 @@ int kvm_hv_hypercall(struct kvm_vcpu *vcpu) > kvm_hv_hypercall_complete_userspace; > return 0; > case HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST: > - if (unlikely(!hc.rep_cnt || hc.rep_idx)) { > + if (unlikely(!hc.rep_cnt || hc.rep_idx || hc.var_cnt)) { > ret = HV_STATUS_INVALID_HYPERCALL_INPUT; > break; > } > ret = kvm_hv_flush_tlb(vcpu, &hc, false); > break; > case HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE: > - if (unlikely(hc.rep)) { > + if (unlikely(hc.rep || hc.var_cnt)) { > ret = HV_STATUS_INVALID_HYPERCALL_INPUT; > break; > } > @@ -2299,7 +2299,7 @@ int kvm_hv_hypercall(struct kvm_vcpu *vcpu) > ret = kvm_hv_flush_tlb(vcpu, &hc, true); > break; > case HVCALL_SEND_IPI: > - if (unlikely(hc.rep)) { > + if (unlikely(hc.rep || hc.var_cnt)) { > ret = HV_STATUS_INVALID_HYPERCALL_INPUT; > break; > } > @@ -2331,6 +2331,11 @@ int kvm_hv_hypercall(struct kvm_vcpu *vcpu) > ret = HV_STATUS_OPERATION_DENIED; > break; > } > + if (unlikely(hc.var_cnt)) { > + ret = HV_STATUS_INVALID_HYPERCALL_INPUT; > + break; > + } > + Probably true for HVCALL_RESET_DEBUG_SESSION but I'm not sure about HVCALL_POST_DEBUG_DATA/HVCALL_RETRIEVE_DEBUG_DATA (note 'fallthrough' above) -- these are not described well in TLFS. > vcpu->run->exit_reason = KVM_EXIT_HYPERV; > vcpu->run->hyperv.type = KVM_EXIT_HYPERV_HCALL; > vcpu->run->hyperv.u.hcall.input = hc.param; -- Vitaly