Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp2501159ybe; Thu, 12 Sep 2019 10:18:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqzlgkqwjkKVfjddqhohR+o2jmkVjB7nLQXF6BMmPr7j1t7bMG96nWozfrlwimwl8kf/M/0F X-Received: by 2002:aa7:df83:: with SMTP id b3mr45271500edy.238.1568308731884; Thu, 12 Sep 2019 10:18:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568308731; cv=none; d=google.com; s=arc-20160816; b=JM6QFp2NfQJ96XanSbrIyBi4uvUP9KgtnKXh8l61KKxgCwjmmeL7Hx1FoDYwpBtH49 O0WoZ4lusu09jxvBF5n235zpgpfVb8DnLqhKhNaVKd2JBoLjO3V90wk8MswZocsIRk3y uC4lBrNhJDJ9qgULhDw41hEnDUKhTdMc/ZaEiqrIcNVcx8LONU8s3MltgfvrssD6fdOk 80ETLUBbzAFG1Srv2BHYznAeO6p9JPPIxk41eDBBlMBD8SGx7fpn+WRvdm0B8X8u1KEo v2Z49SJLvujT+nyltqV5U9qv0GADcFix9570RlcljpEbHrG2PHgrfoxr+dYyltuTVaJS 8fkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:organization:autocrypt:openpgp:from:references:cc:to :subject; bh=wgYI6wWm7sMAtReZsWNk5h1Tt6YfE3BbH0gjBFRnrS0=; b=qB+9oKF/P7UvLSwkWf7Nv8UWXQfyG2O+RAvGEmDBTM5f6+QP2XwbE8d7O6lkJvwaVh RzWghq+BTAzg1Qh6HpkLvUCfvDINvKhPqzSob4d5z09WKAp2CI1rlO+zCZSaUBAjQ6C7 turKFtynESO13JZ2KtqC1yQ46eFJDLdeev4klHf9M/u8RaSKFsvlnNKaM3mij3l7vXoE sdVM5S+HtLWOMkp6obnZ3SbiIr9IevvSltEdrYjjFm7F7TkaDSYPl09UIXSNRqQF56HK dD5zZToXtdgf3M1Nm+Nr/2qKYzbldfHMxttIBeHmJdJ+bIiKBatBta725GxI3yXAu6ZV M3HA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k25si17520372edd.209.2019.09.12.10.18.25; Thu, 12 Sep 2019 10:18:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731291AbfILLXp (ORCPT + 99 others); Thu, 12 Sep 2019 07:23:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:32834 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730982AbfILLXp (ORCPT ); Thu, 12 Sep 2019 07:23:45 -0400 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 mx1.redhat.com (Postfix) with ESMTPS id C44018A1C83; Thu, 12 Sep 2019 11:23:44 +0000 (UTC) Received: from thuth.remote.csb (ovpn-204-41.brq.redhat.com [10.40.204.41]) by smtp.corp.redhat.com (Postfix) with ESMTP id 83F051001944; Thu, 12 Sep 2019 11:23:39 +0000 (UTC) Subject: Re: [PATCH] KVM: s390: Do not leak kernel stack data in the KVM_S390_INTERRUPT ioctl To: Christian Borntraeger , David Hildenbrand , Janosch Frank , kvm@vger.kernel.org Cc: Cornelia Huck , linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org References: <20190912090050.20295-1-thuth@redhat.com> <6905df78-95f0-3d6d-aaae-910cd2d7a232@redhat.com> <253e67f6-0a41-13e8-4ca2-c651d5fcdb69@redhat.com> From: Thomas Huth Openpgp: preference=signencrypt Autocrypt: addr=thuth@redhat.com; prefer-encrypt=mutual; keydata= mQINBFH7eUwBEACzyOXKU+5Pcs6wNpKzrlJwzRl3VGZt95VCdb+FgoU9g11m7FWcOafrVRwU yYkTm9+7zBUc0sW5AuPGR/dp3pSLX/yFWsA/UB4nJsHqgDvDU7BImSeiTrnpMOTXb7Arw2a2 4CflIyFqjCpfDM4MuTmzTjXq4Uov1giGE9X6viNo1pxyEpd7PanlKNnf4PqEQp06X4IgUacW tSGj6Gcns1bCuHV8OPWLkf4hkRnu8hdL6i60Yxz4E6TqlrpxsfYwLXgEeswPHOA6Mn4Cso9O 0lewVYfFfsmokfAVMKWzOl1Sr0KGI5T9CpmRfAiSHpthhHWnECcJFwl72NTi6kUcUzG4se81 O6n9d/kTj7pzTmBdfwuOZ0YUSqcqs0W+l1NcASSYZQaDoD3/SLk+nqVeCBB4OnYOGhgmIHNW 0CwMRO/GK+20alxzk//V9GmIM2ACElbfF8+Uug3pqiHkVnKqM7W9/S1NH2qmxB6zMiJUHlTH gnVeZX0dgH27mzstcF786uPcdEqS0KJuxh2kk5IvUSL3Qn3ZgmgdxBMyCPciD/1cb7/Ahazr 3ThHQXSHXkH/aDXdfLsKVuwDzHLVSkdSnZdt5HHh75/NFHxwaTlydgfHmFFwodK8y/TjyiGZ zg2Kje38xnz8zKn9iesFBCcONXS7txENTzX0z80WKBhK+XSFJwARAQABtB5UaG9tYXMgSHV0 aCA8dGh1dGhAcmVkaGF0LmNvbT6JAjgEEwECACIFAlVgX6oCGwMGCwkIBwMCBhUIAgkKCwQW AgMBAh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xF30bn Organization: Red Hat Message-ID: <239c8d0f-40fb-264a-bc10-445931a3cd9a@redhat.com> Date: Thu, 12 Sep 2019 13:23:38 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.69]); Thu, 12 Sep 2019 11:23:44 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 12/09/2019 12.52, Christian Borntraeger wrote: > > > On 12.09.19 11:20, Thomas Huth wrote: >> On 12/09/2019 11.14, David Hildenbrand wrote: >>> On 12.09.19 11:00, Thomas Huth wrote: >>>> When the userspace program runs the KVM_S390_INTERRUPT ioctl to inject >>>> an interrupt, we convert them from the legacy struct kvm_s390_interrupt >>>> to the new struct kvm_s390_irq via the s390int_to_s390irq() function. >>>> However, this function does not take care of all types of interrupts >>>> that we can inject into the guest later (see do_inject_vcpu()). Since we >>>> do not clear out the s390irq values before calling s390int_to_s390irq(), >>>> there is a chance that we copy unwanted data from the kernel stack >>>> into the guest memory later if the interrupt data has not been properly >>>> initialized by s390int_to_s390irq(). >>>> >>>> Specifically, the problem exists with the KVM_S390_INT_PFAULT_INIT >>>> interrupt: s390int_to_s390irq() does not handle it, but the function >>>> __deliver_pfault_init() will later copy the uninitialized stack data >>>> from the ext.ext_params2 into the guest memory. >>>> >>>> Fix it by handling that interrupt type in s390int_to_s390irq(), too. >>>> And while we're at it, make sure that s390int_to_s390irq() now >>>> directly returns -EINVAL for unknown interrupt types, so that we >>>> do not run into this problem again in case we add more interrupt >>>> types to do_inject_vcpu() sometime in the future. >>>> >>>> Signed-off-by: Thomas Huth >>>> --- >>>> arch/s390/kvm/interrupt.c | 10 ++++++++++ >>>> 1 file changed, 10 insertions(+) >>>> >>>> diff --git a/arch/s390/kvm/interrupt.c b/arch/s390/kvm/interrupt.c >>>> index 3e7efdd9228a..165dea4c7f19 100644 >>>> --- a/arch/s390/kvm/interrupt.c >>>> +++ b/arch/s390/kvm/interrupt.c >>>> @@ -1960,6 +1960,16 @@ int s390int_to_s390irq(struct kvm_s390_interrupt *s390int, >>>> case KVM_S390_MCHK: >>>> irq->u.mchk.mcic = s390int->parm64; >>>> break; >>>> + case KVM_S390_INT_PFAULT_INIT: >>>> + irq->u.ext.ext_params = s390int->parm; >>>> + irq->u.ext.ext_params2 = s390int->parm64; >>>> + break; >>>> + case KVM_S390_RESTART: >>>> + case KVM_S390_INT_CLOCK_COMP: >>>> + case KVM_S390_INT_CPU_TIMER: >>>> + break; >>>> + default: >>>> + return -EINVAL; >>>> } >>>> return 0; >>>> } >>>> >>> >>> Wouldn't a safe fix be to initialize the struct to zero in the caller? >> >> That's of course possible, too. But that means that we always have to >> zero out the whole structure, so that's a little bit more of overhead >> (well, it likely doesn't matter for such a legacy ioctl). > > Yes doing something like > > diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c > index c19a24e940a1..b1f6f434af5d 100644 > --- a/arch/s390/kvm/kvm-s390.c > +++ b/arch/s390/kvm/kvm-s390.c > @@ -4332,7 +4332,7 @@ long kvm_arch_vcpu_async_ioctl(struct file *filp, > } > case KVM_S390_INTERRUPT: { > struct kvm_s390_interrupt s390int; > - struct kvm_s390_irq s390irq; > + struct kvm_s390_irq s390irq = {}; > > if (copy_from_user(&s390int, argp, sizeof(s390int))) > return -EFAULT; > > would certainly be ok as well, but I don't think that it's urgently necessary, but ok, if you all prefer to have it, too, I can add it to my patch. >> But the more important question: Do we then still care of fixing the >> PFAULT_INIT interrupt here? Since it requires a parameter, the "case >> KVM_S390_INT_PFAULT_INIT:" part would be required here anyway. > > as long as we we this interface we should fix it and we should do the > pfault thing correctly. > Maybe we should start to deprecate this interface and remove it. Hmm, we already talked about deprecating support for pre-3.15 kernel stuff in the past (see https://wiki.qemu.org/ChangeLog/2.12#Future_incompatible_changes for example), since this has been broken in QEMU since quite a while, but the new KVM_S390_IRQ replacement has just been introduced with kernel 4.1 ... so removing this KVM_S390_INTERRUPT ioctl any time soon sounds wrong to me, we might break some userspace programs that are still there in the wild... Thomas