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 X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 73059C3A5A3 for ; Thu, 29 Aug 2019 11:18:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 526192189D for ; Thu, 29 Aug 2019 11:18:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727951AbfH2LSw (ORCPT ); Thu, 29 Aug 2019 07:18:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54710 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726232AbfH2LSw (ORCPT ); Thu, 29 Aug 2019 07:18:52 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2C72B18C426B; Thu, 29 Aug 2019 11:18:52 +0000 (UTC) Received: from gondolin (dhcp-192-222.str.redhat.com [10.33.192.222]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3898D600C1; Thu, 29 Aug 2019 11:18:48 +0000 (UTC) Date: Thu, 29 Aug 2019 13:18:45 +0200 From: Cornelia Huck To: Thomas Huth Cc: Christian Borntraeger , Janosch Frank , kvm@vger.kernel.org, David Hildenbrand , Heiko Carstens , Vasily Gorbik , linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] KVM: s390: Test for bad access register at the start of S390_MEM_OP Message-ID: <20190829131845.5a72231a.cohuck@redhat.com> In-Reply-To: <20190829105356.27805-1-thuth@redhat.com> References: <20190829105356.27805-1-thuth@redhat.com> Organization: Red Hat GmbH MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.62]); Thu, 29 Aug 2019 11:18:52 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org On Thu, 29 Aug 2019 12:53:56 +0200 Thomas Huth wrote: > 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. > > Signed-off-by: Thomas Huth > --- > arch/s390/kvm/kvm-s390.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c > index f329dcb3f44c..725690853cbd 100644 > --- a/arch/s390/kvm/kvm-s390.c > +++ b/arch/s390/kvm/kvm-s390.c > @@ -4255,7 +4255,7 @@ static long kvm_s390_guest_mem_op(struct kvm_vcpu *vcpu, > 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) > return -EINVAL; This also matches the value that ar_translation would return, so seems sane. > > if (mop->size > MEM_OP_MAX_SIZE) Reviewed-by: Cornelia Huck Btw: should Documentation/virt/kvm/api.txt spell out the valid range for ar explicitly?