Received: by 2002:a25:b323:0:0:0:0:0 with SMTP id l35csp1220601ybj; Fri, 20 Sep 2019 07:05:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqw8TY8kJ9PpFoOYHHz+HIXm1u9zrEyt+RaeI347XiKBVWG0w0BnIsOiO9wfCmQo7ohJapvv X-Received: by 2002:a17:906:79ca:: with SMTP id m10mr19177084ejo.292.1568988333628; Fri, 20 Sep 2019 07:05:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568988333; cv=none; d=google.com; s=arc-20160816; b=oIce5V3vH0aGTHX6w8JoqkajAste8v4EKlKRNKxoQEkwgPpZuec8l7rXnKi4KzGN48 3nWbqHVDgFt8MCNXhStDmA6A7txwLT/WFBPGfXOie3+icVLs0iUFFHCNMROiYondTeHb r2QmLAqrVZqYwm08FxtarH9i/3fD7N2vBwNtwc7CZtZvjQKyALhH5T83ubCeJdJ1am2B +Vt50Wf29E3UDUKwEfb3kEjgmJ3VMo9WiqwMRtWPUvg2Fxz0fUyO/ZoEpkNWahl68G/6 OLZqsn2m3LUn5XJj3DpZ//tlJan1+JE6gaZ8azLG3MTOOvqmFpcAb8Zt8sZz0Ai3fkCs /MRQ== 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:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=p3xcVnyogk1jBjxJnHJcv7hX4o9wu8KkV6t3cU0LJyU=; b=Dip0z9oxsW4R8RXAwqHYa0TwDs294ev6nxowjAe3hFg2KQQyAl2vKD0Vv1cLxAYf2y TAl7kfGLQaYzz5DP+NmJtMeuoBZgUzUSTVcXiqWwk6txZHGvio6DpJKeEgmW141YKb7b Tg0arN7jS6LRstEKCZHspPbV8+v33xxAet8nvCMsh66+QZHkyORZgmHPOMBqULxryN5X 1ld5T8wJPbIu4HUW5weZSOWuH3xeK/Grf1LsoB7ZBN2AQpI+5Uf10nrLPHV5dulDnQov GTvBs3hjPvjmjelB+ub5+yqiS/luWTCaTaQot/p+1RL4uVfRGSuxPGWJPLXvsgjiCV7I qygQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xrFIotOo; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k39si1380399edb.52.2019.09.20.07.05.06; Fri, 20 Sep 2019 07:05:33 -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; dkim=pass header.i=@kernel.org header.s=default header.b=xrFIotOo; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404668AbfISWSu (ORCPT + 99 others); Thu, 19 Sep 2019 18:18:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:60388 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2406583AbfISWSo (ORCPT ); Thu, 19 Sep 2019 18:18:44 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5C5EF21927; Thu, 19 Sep 2019 22:18:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1568931523; bh=NZ6dPLLpU+4968Do+DohxPC8whQXj0lNh8egrTRG3KY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xrFIotOocA6f7pUA4ly7wkLsKW1C900DI2u98Hidqscm0yi0JRpJPVZDNeC7DIN2X p5NMyBXdEaXlvIFpFOtnIFNjmPPjPDBPqopbiQg/ETESDj7QLwxr4vJcq4opREh8Qj iPewKSLUwpoSLc5H8KPiAwOYpjeFJay8SF3c7+Uo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, David Hildenbrand , Christian Borntraeger , Janosch Frank , Thomas Huth Subject: [PATCH 4.9 18/74] KVM: s390: Do not leak kernel stack data in the KVM_S390_INTERRUPT ioctl Date: Fri, 20 Sep 2019 00:03:31 +0200 Message-Id: <20190919214806.430318601@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190919214800.519074117@linuxfoundation.org> References: <20190919214800.519074117@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Huth commit 53936b5bf35e140ae27e4bbf0447a61063f400da upstream. 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 random data from the kernel stack which could be leaked to the userspace later. Specifically, the problem exists with the KVM_S390_INT_PFAULT_INIT interrupt: s390int_to_s390irq() does not handle it, and the function __inject_pfault_init() later copies irq->u.ext which contains the random kernel stack data. This data can then be leaked either to the guest memory in __deliver_pfault_init(), or the userspace might retrieve it directly with the KVM_S390_GET_IRQ_STATE ioctl. Fix it by handling that interrupt type in s390int_to_s390irq(), too, and by making sure that the s390irq struct is properly pre-initialized. And while we're at it, make sure that s390int_to_s390irq() now directly returns -EINVAL for unknown interrupt types, so that we immediately get a proper error code in case we add more interrupt types to do_inject_vcpu() without updating s390int_to_s390irq() sometime in the future. Cc: stable@vger.kernel.org Reviewed-by: David Hildenbrand Reviewed-by: Christian Borntraeger Reviewed-by: Janosch Frank Signed-off-by: Thomas Huth Link: https://lore.kernel.org/kvm/20190912115438.25761-1-thuth@redhat.com Signed-off-by: Christian Borntraeger Signed-off-by: Greg Kroah-Hartman --- arch/s390/kvm/interrupt.c | 10 ++++++++++ arch/s390/kvm/kvm-s390.c | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) --- a/arch/s390/kvm/interrupt.c +++ b/arch/s390/kvm/interrupt.c @@ -1652,6 +1652,16 @@ int s390int_to_s390irq(struct kvm_s390_i 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; } --- a/arch/s390/kvm/kvm-s390.c +++ b/arch/s390/kvm/kvm-s390.c @@ -3105,7 +3105,7 @@ long kvm_arch_vcpu_ioctl(struct file *fi } case KVM_S390_INTERRUPT: { struct kvm_s390_interrupt s390int; - struct kvm_s390_irq s390irq; + struct kvm_s390_irq s390irq = {}; r = -EFAULT; if (copy_from_user(&s390int, argp, sizeof(s390int)))