Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp2239841ybl; Thu, 29 Aug 2019 05:41:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqwR1krW3zzQ8LkasY5FldRaaIZY0aOS6lWKv2/yF0HR8zQV5ACdULoDoZzLxt3gKQtUjlqh X-Received: by 2002:a17:90a:1cb:: with SMTP id 11mr9670158pjd.109.1567082495067; Thu, 29 Aug 2019 05:41:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567082495; cv=none; d=google.com; s=arc-20160816; b=zVCY7P0FjAEC76By7N2GiIG7f78nIQLgi8JXbBzfDHXK7jIiF8U8fGVSLNBAGg/vXs hBqn7LjTlCNyGikx+0tbdr/UVFLxarkBLoOSrIEvdbJa7Sd9Lqqh0DrBsEFHDQWLtPE2 phuRVAJ2nJOaCYqB+2c+yWmTwqO7syKHkp0ktH/ktNxfWzMisGTesEeOlV/DjnAb6iHA QitJviDgXISDjQ4BwhUWmz+FDGVbEN+fmosLEicRaGEeTpRutoIclttq78RqHLmdYlJP lZOFYqPh4R7fAHHQw4kM+tIQ15wSh9rYOGU3xhXp0Ygzt9QNLDwEbnqW54kZZb0jjKQa sttg== 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 :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=dO86VuduOozXvPtcuAdlxfY5Ss2LnEMDLLCBk7iqte8=; b=TUwqJp0CdS5XNffvpSBy2Na01Bbjod7UfNn3aVWpvUNxgfLfFLMU4SXFuBhir4jxd1 u5GFfmy3cMpdygCCU0OxzPHFRmKx+6jicPQRL81EhmNVo9teCb37d3gtxGCEWYkDgL9S 5Pdm0tcJGy9DAeEZu2q3YFLR3WKvImISOEZtN1eX+BuWJSz3JKKKn+/sws6R4OcQOQca ZbuO6n3Ml7Uiy6az2xmtJ+v1z2amLkQAKnhRHVsd91a8V5b5bsRbhJE6wWccrvzK3W6N CS/KzsCms745Ag7opmZH2SGGqyLyJPBzUxlncc+bViIh24hZA2GIEAnlSioOocbwz15B X/2g== 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 g10si1840119plt.119.2019.08.29.05.41.19; Thu, 29 Aug 2019 05:41:35 -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 S1727309AbfH2MkV (ORCPT + 99 others); Thu, 29 Aug 2019 08:40:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56736 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725782AbfH2MkV (ORCPT ); Thu, 29 Aug 2019 08:40:21 -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 A8CCC3083363; Thu, 29 Aug 2019 12:40:20 +0000 (UTC) Received: from gondolin (dhcp-192-222.str.redhat.com [10.33.192.222]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0F6C66013A; Thu, 29 Aug 2019 12:40:15 +0000 (UTC) Date: Thu, 29 Aug 2019 14:40:13 +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 v2] KVM: s390: Test for bad access register and size at the start of S390_MEM_OP Message-ID: <20190829144013.322edb0a.cohuck@redhat.com> In-Reply-To: <20190829122517.31042-1-thuth@redhat.com> References: <20190829122517.31042-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.5.16 (mx1.redhat.com [10.5.110.44]); Thu, 29 Aug 2019 12:40:20 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 29 Aug 2019 14:25:17 +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. > > 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 > --- > v2: Check mop->size to be non-zero > > 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..49d7722229ae 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 || !mop->size) > return -EINVAL; > > if (mop->size > MEM_OP_MAX_SIZE) Reviewed-by: Cornelia Huck