From nobody Sun May 19 18:35:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1569497756; cv=none; d=zoho.com; s=zohoarc; b=mQSstQA9nbp6BecYhgrddPf1TMIXiAwgObheywhFxFls3Z5+/27sMq5Z7/tHNMDIpdINSiW9xXeoi1M9Iluym5JCcl76dhAL/BxJ0tUBsstJipaCMjGpVeR3REjz8sQfn/TNqNsGGF/cqIzE7oLIwD2yPhRhV8tttpHlVBZwjWE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569497756; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=9anOV5QGFah8YRyF+Wq7AeVt35SwgcWpBG/eZ4Ja0pg=; b=GW1j47QIrOduX/Gsp2J9aTaZM92u0jQgKSOEBXZN0j5n/XsOb++FQSB6Gsx7sK30PCeyA2USkHGVujeeBUiQMJSGbWZ2Ck2XWzbqeXsXjFMSSUEo5RePK96tL/iI4xuoxSBHFJNAKU+u/JD6tyrttxbRzFeCYEAiJjGIOqc4pQo= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1569497756494335.29035370235613; Thu, 26 Sep 2019 04:35:56 -0700 (PDT) Received: from localhost ([::1]:34228 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iDS3s-0001H5-Tz for importer@patchew.org; Thu, 26 Sep 2019 07:35:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54944) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iDS22-0007jU-HC for qemu-devel@nongnu.org; Thu, 26 Sep 2019 07:34:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iDS20-0007nV-5z for qemu-devel@nongnu.org; Thu, 26 Sep 2019 07:33:57 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:23128 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iDS20-0007jh-1S for qemu-devel@nongnu.org; Thu, 26 Sep 2019 07:33:56 -0400 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x8QBWFxj029729 for ; Thu, 26 Sep 2019 07:33:49 -0400 Received: from e06smtp07.uk.ibm.com (e06smtp07.uk.ibm.com [195.75.94.103]) by mx0a-001b2d01.pphosted.com with ESMTP id 2v8ur5tc8k-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 26 Sep 2019 07:33:49 -0400 Received: from localhost by e06smtp07.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 26 Sep 2019 12:33:48 +0100 Received: from b06cxnps4076.portsmouth.uk.ibm.com (9.149.109.198) by e06smtp07.uk.ibm.com (192.168.101.137) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Thu, 26 Sep 2019 12:33:44 +0100 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x8QBXhBl50397318 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 26 Sep 2019 11:33:43 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1FDEA4C044; Thu, 26 Sep 2019 11:33:43 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D755B4C040; Thu, 26 Sep 2019 11:33:42 +0000 (GMT) Received: from p-imbrenda.boeblingen.de.ibm.com (unknown [9.152.224.39]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Thu, 26 Sep 2019 11:33:42 +0000 (GMT) From: Claudio Imbrenda To: qemu-devel@nongnu.org, qemu-s390x@nongnu.org Subject: [PATCH v1 1/2] s390x: Add sclp boundary check and fix error priority Date: Thu, 26 Sep 2019 13:33:41 +0200 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1569497622-12496-1-git-send-email-imbrenda@linux.ibm.com> References: <1569497622-12496-1-git-send-email-imbrenda@linux.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 19092611-0028-0000-0000-000003A2DE34 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19092611-0029-0000-0000-00002464FBA7 Message-Id: <1569497622-12496-2-git-send-email-imbrenda@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2019-09-26_05:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1909260111 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 148.163.158.5 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: borntraeger@de.ibm.com, cohuck@redhat.com, frankja@linux.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Janosch Frank * All sclp codes need to be checked for page boundary violations. * Requests over 4k are not a spec exception. * Invalid command checking has to be done before the boundary check. Signed-off-by: Janosch Frank Reviewed-by: Jason J. Herne --- hw/s390x/event-facility.c | 3 --- hw/s390x/sclp.c | 25 ++++++++++++++++++++++--- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/hw/s390x/event-facility.c b/hw/s390x/event-facility.c index 797ecbb..6620569 100644 --- a/hw/s390x/event-facility.c +++ b/hw/s390x/event-facility.c @@ -377,9 +377,6 @@ static void command_handler(SCLPEventFacility *ef, SCCB= *sccb, uint64_t code) case SCLP_CMD_WRITE_EVENT_MASK: write_event_mask(ef, sccb); break; - default: - sccb->h.response_code =3D cpu_to_be16(SCLP_RC_INVALID_SCLP_COMMAND= ); - break; } } =20 diff --git a/hw/s390x/sclp.c b/hw/s390x/sclp.c index fac7c3b..76feac8 100644 --- a/hw/s390x/sclp.c +++ b/hw/s390x/sclp.c @@ -213,14 +213,33 @@ int sclp_service_call(CPUS390XState *env, uint64_t sc= cb, uint32_t code) cpu_physical_memory_read(sccb, &work_sccb, sccb_len); =20 /* Valid sccb sizes */ - if (be16_to_cpu(work_sccb.h.length) < sizeof(SCCBHeader) || - be16_to_cpu(work_sccb.h.length) > SCCB_SIZE) { + if (be16_to_cpu(work_sccb.h.length) < sizeof(SCCBHeader)) { r =3D -PGM_SPECIFICATION; goto out; } =20 - sclp_c->execute(sclp, &work_sccb, code); + switch (code & SCLP_CMD_CODE_MASK) { + case SCLP_CMDW_READ_SCP_INFO: + case SCLP_CMDW_READ_SCP_INFO_FORCED: + case SCLP_CMDW_READ_CPU_INFO: + case SCLP_CMDW_CONFIGURE_IOA: + case SCLP_CMDW_DECONFIGURE_IOA: + case SCLP_CMD_READ_EVENT_DATA: + case SCLP_CMD_WRITE_EVENT_DATA: + case SCLP_CMD_WRITE_EVENT_MASK: + break; + default: + work_sccb.h.response_code =3D cpu_to_be16(SCLP_RC_INVALID_SCLP_COM= MAND); + goto out_write; + } =20 + if ((sccb + work_sccb.h.length) > ((sccb & PAGE_MASK) + PAGE_SIZE)) { + work_sccb.h.response_code =3D cpu_to_be16(SCLP_RC_SCCB_BOUNDARY_VI= OLATION); + goto out_write; + } + + sclp_c->execute(sclp, &work_sccb, code); +out_write: cpu_physical_memory_write(sccb, &work_sccb, be16_to_cpu(work_sccb.h.length)); =20 --=20 2.7.4 From nobody Sun May 19 18:35:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1569497756; cv=none; d=zoho.com; s=zohoarc; b=TEOpXd7Q3hHGKr/4Tg1eMddHqw3XwV7hhNdd3oXH/kSptXA9IL+YhP57esq4VIwT8s5NlpDeTLCKfFVZm7BJ1z3VnCW9Fwat3DLZsbrGaXzce50Q30CZbDvNlLEz1jUv+qGUwp2xJlRTxVo+jBSjqyatBWYmoaSKUX/9PZ5FAjg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569497756; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=7ymx40UBY2UznYfOwpU6cnUrfcuF+dT2YENa4A8OPdU=; b=fMTDOBpPjxAlBAl0a8eixzB4rYpP+WWk2+DrCNuG+310Xi+027HuHe5JgVjHS4Z+I7Nho5wcWz7Zq/DfAV/2ky+BvMbC2VAM/MkTUnbFJOD5QSTefx7IsZrz4LcvKJirjbocsv2LYpnZ/UC0MP1Qw9TrlIyI+tUpvGlHBTsSkkk= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1569497756584575.2529472617863; Thu, 26 Sep 2019 04:35:56 -0700 (PDT) Received: from localhost ([::1]:34230 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iDS3v-0001Op-5e for importer@patchew.org; Thu, 26 Sep 2019 07:35:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54968) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iDS22-0007m5-89 for qemu-devel@nongnu.org; Thu, 26 Sep 2019 07:33:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iDS20-0007oQ-Vf for qemu-devel@nongnu.org; Thu, 26 Sep 2019 07:33:58 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:35208 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iDS20-0007ln-Gq for qemu-devel@nongnu.org; Thu, 26 Sep 2019 07:33:56 -0400 Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x8QBW3GF061324 for ; Thu, 26 Sep 2019 07:33:48 -0400 Received: from e06smtp04.uk.ibm.com (e06smtp04.uk.ibm.com [195.75.94.100]) by mx0a-001b2d01.pphosted.com with ESMTP id 2v8tjx67yw-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 26 Sep 2019 07:33:48 -0400 Received: from localhost by e06smtp04.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 26 Sep 2019 12:33:46 +0100 Received: from b06cxnps4076.portsmouth.uk.ibm.com (9.149.109.198) by e06smtp04.uk.ibm.com (192.168.101.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Thu, 26 Sep 2019 12:33:45 +0100 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x8QBXhDV50397320 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 26 Sep 2019 11:33:43 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6CD2C4C044; Thu, 26 Sep 2019 11:33:43 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2EEEC4C040; Thu, 26 Sep 2019 11:33:43 +0000 (GMT) Received: from p-imbrenda.boeblingen.de.ibm.com (unknown [9.152.224.39]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Thu, 26 Sep 2019 11:33:43 +0000 (GMT) From: Claudio Imbrenda To: qemu-devel@nongnu.org, qemu-s390x@nongnu.org Subject: [PATCH v1 2/2] s390x: Fix SCLP return code when buffer too small Date: Thu, 26 Sep 2019 13:33:42 +0200 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1569497622-12496-1-git-send-email-imbrenda@linux.ibm.com> References: <1569497622-12496-1-git-send-email-imbrenda@linux.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 19092611-0016-0000-0000-000002B0F3A2 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19092611-0017-0000-0000-00003311C03B Message-Id: <1569497622-12496-3-git-send-email-imbrenda@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2019-09-26_05:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1909260111 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 148.163.158.5 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: borntraeger@de.ibm.com, cohuck@redhat.com, frankja@linux.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Return the correct error code when the SCCB buffer is too small to contain all of the output, for the Read SCP Information and Read CPU Information commands. Signed-off-by: Claudio Imbrenda Reviewed-by: Jason J. Herne --- hw/s390x/sclp.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/hw/s390x/sclp.c b/hw/s390x/sclp.c index 76feac8..8f7fe1c 100644 --- a/hw/s390x/sclp.c +++ b/hw/s390x/sclp.c @@ -68,6 +68,11 @@ static void read_SCP_info(SCLPDevice *sclp, SCCB *sccb) =20 read_info->ibc_val =3D cpu_to_be32(s390_get_ibc_val()); =20 + if (sccb->h.length < (sizeof(ReadInfo) + cpu_count * sizeof(CPUEntry))= ) { + sccb->h.response_code =3D cpu_to_be16(SCLP_RC_INSUFFICIENT_SCCB_LE= NGTH); + return; + } + /* Configuration Characteristic (Extension) */ s390_get_feat_block(S390_FEAT_TYPE_SCLP_CONF_CHAR, read_info->conf_char); @@ -118,6 +123,11 @@ static void sclp_read_cpu_info(SCLPDevice *sclp, SCCB = *sccb) cpu_info->offset_configured =3D cpu_to_be16(offsetof(ReadCpuInfo, entr= ies)); cpu_info->nr_standby =3D cpu_to_be16(0); =20 + if (sccb->h.length < (sizeof(ReadCpuInfo) + cpu_count * sizeof(CPUEntr= y))) { + sccb->h.response_code =3D cpu_to_be16(SCLP_RC_INSUFFICIENT_SCCB_LE= NGTH); + return; + } + /* The standby offset is 16-byte for each CPU */ cpu_info->offset_standby =3D cpu_to_be16(cpu_info->offset_configured + cpu_info->nr_configured*sizeof(CPUEntry)); --=20 2.7.4