Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp2082410ybp; Thu, 10 Oct 2019 01:52:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqxJXkeGECe+zC2BrsA40yiusrNLHl+DfEUeHN213jgf0lia1fNVWetoF9wa1Svuz1LK1N54 X-Received: by 2002:a17:906:7212:: with SMTP id m18mr7006485ejk.88.1570697572251; Thu, 10 Oct 2019 01:52:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570697572; cv=none; d=google.com; s=arc-20160816; b=tZ+mSQoUTXIMhX7qYD/R2F3NkHN9sdoZ1nKKpbuX981atNN+S1cp+M0IsC2QcotbXM 5R4yKAKtgl/vCmyxqC4DFQxlLDdWAUR7RTNSmeFrePdKdrnbTwN5/IDmw3BaBqnyqyLs +gZs73qoHU8JVWzlswbGfUAMhf5fE4qXU+yB2ZNNrDiUcJogn6UjLaW7/DIPDEJY+RrZ Ixq8rRbyq5rhMgtCLwTvbMNeUIgwBNYO50zxJD5FoIW83qcPNOuZD1rHhhVG11135mET MY6thljvgL9Fh3oqPemsgs9PAVb6auEm2dR8n4iMs+xEdKMcW4GJd4kUr9AX4CN/QMGM O1SA== 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=f6qlW+5AzNohDefZ/m8rli88S059/bLfNBUBsokc3iY=; b=rmBITPJICfqCJeJmY6WHeytre0bUWfcdi8KQCkA/KHuSaAqL9nE+i2KlJMJJa6i2ji U/MA4eC+7qdSPV5flUz8w/JxOrp1pMA44yY5xZLFmpbO99IzPLFp6CJEKIQEP1RgyhFQ DWWY118J5lAPaamYI0qYgNs3LlDaHV6IT8ez9FgPQuZcdCl3W002wVhCJ4oxozSnrZ0m QWL00B5QTQNXN+OgbDSTjZgT4YVP9ZugJ+iWOdavlsjkwwqwk8kNAmKzOQgTl9XvpcfA cqChl3XAXxY23TF6ED3jVxFD82WbezctSy5ZrOxckOetNGxw/2AXBVoZ2qjZm47mAgPp urDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="kprpTS/N"; 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 x29si3133371eda.297.2019.10.10.01.52.29; Thu, 10 Oct 2019 01:52:52 -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="kprpTS/N"; 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 S2388911AbfJJIuT (ORCPT + 99 others); Thu, 10 Oct 2019 04:50:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:57176 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389934AbfJJIuR (ORCPT ); Thu, 10 Oct 2019 04:50:17 -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 41EF2208C3; Thu, 10 Oct 2019 08:50:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570697416; bh=w1PhsVc2NzNNsICY5Y3TgMZHDcsd8nJISnDVyMqOqn4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kprpTS/N7jeYIrq850CJ7b4Qj8WUkXtT7HR9cY9QV46W4nCuBt8wPLNq8hToM+G0N gnSM8BuC1bh7o9xVX9hRpjIBiVcF9zf6AYSJtrovE38BPFb5P0AuHdxMFPcqw1Q53o IrSChHMTOvFclXdEkEAilcvBpdlOU/ZcLPuhqshE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Thomas Huth , Cornelia Huck , Janosch Frank , David Hildenbrand , Christian Borntraeger Subject: [PATCH 4.14 02/61] KVM: s390: Test for bad access register and size at the start of S390_MEM_OP Date: Thu, 10 Oct 2019 10:36:27 +0200 Message-Id: <20191010083450.699295630@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191010083449.500442342@linuxfoundation.org> References: <20191010083449.500442342@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 a13b03bbb4575b350b46090af4dfd30e735aaed1 upstream. If the KVM_S390_MEM_OP ioctl is called with an access register >= 16, then there is certainly a bug in the calling userspace application. We check for wrong access registers, but only if the vCPU was already in the access register mode before (i.e. the SIE block has recorded it). The check is also buried somewhere deep in the calling chain (in the function ar_translation()), so this is somewhat hard to find. It's better to always report an error to the userspace in case this field is set wrong, and it's safer in the KVM code if we block wrong values here early instead of relying on a check somewhere deep down the calling chain, so let's add another check to kvm_s390_guest_mem_op() directly. We also should check that the "size" is non-zero here (thanks to Janosch Frank for the hint!). If we do not check the size, we could call vmalloc() with this 0 value, and this will cause a kernel warning. Signed-off-by: Thomas Huth Link: https://lkml.kernel.org/r/20190829122517.31042-1-thuth@redhat.com Reviewed-by: Cornelia Huck Reviewed-by: Janosch Frank Reviewed-by: David Hildenbrand Cc: stable@vger.kernel.org Signed-off-by: Christian Borntraeger Signed-off-by: Greg Kroah-Hartman --- arch/s390/kvm/kvm-s390.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/arch/s390/kvm/kvm-s390.c +++ b/arch/s390/kvm/kvm-s390.c @@ -3658,7 +3658,7 @@ static long kvm_s390_guest_mem_op(struct const u64 supported_flags = KVM_S390_MEMOP_F_INJECT_EXCEPTION | KVM_S390_MEMOP_F_CHECK_ONLY; - if (mop->flags & ~supported_flags) + if (mop->flags & ~supported_flags || mop->ar >= NUM_ACRS || !mop->size) return -EINVAL; if (mop->size > MEM_OP_MAX_SIZE)