|
|
c687bc |
From 212c129b82f0a53725a4167303de2ee0a865f82d Mon Sep 17 00:00:00 2001
|
|
|
c687bc |
From: Thomas Huth <thuth@redhat.com>
|
|
|
c687bc |
Date: Wed, 11 Nov 2020 12:03:08 -0500
|
|
|
c687bc |
Subject: [PATCH 08/18] s390/sclp: read sccb from mem based on provided length
|
|
|
c687bc |
|
|
|
c687bc |
RH-Author: Thomas Huth <thuth@redhat.com>
|
|
|
c687bc |
Message-id: <20201111120316.707489-5-thuth@redhat.com>
|
|
|
c687bc |
Patchwork-id: 99501
|
|
|
c687bc |
O-Subject: [RHEL-8.4.0 qemu-kvm PATCH v2 04/12] s390/sclp: read sccb from mem based on provided length
|
|
|
c687bc |
Bugzilla: 1798506
|
|
|
c687bc |
RH-Acked-by: Jens Freimann <jfreimann@redhat.com>
|
|
|
c687bc |
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
|
|
|
c687bc |
RH-Acked-by: David Hildenbrand <david@redhat.com>
|
|
|
c687bc |
|
|
|
c687bc |
From: Collin Walling <walling@linux.ibm.com>
|
|
|
c687bc |
|
|
|
c687bc |
The header contained within the SCCB passed to the SCLP service call
|
|
|
c687bc |
contains the actual length of the SCCB. Instead of allocating a static
|
|
|
c687bc |
4K size for the work sccb, let's allow for a variable size determined
|
|
|
c687bc |
by the value in the header. The proper checks are already in place to
|
|
|
c687bc |
ensure the SCCB length is sufficent to store a full response and that
|
|
|
c687bc |
the length does not cross any explicitly-set boundaries.
|
|
|
c687bc |
|
|
|
c687bc |
Signed-off-by: Collin Walling <walling@linux.ibm.com>
|
|
|
c687bc |
Reviewed-by: Thomas Huth <thuth@redhat.com>
|
|
|
c687bc |
Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
|
|
|
c687bc |
Message-Id: <20200915194416.107460-4-walling@linux.ibm.com>
|
|
|
c687bc |
Signed-off-by: Cornelia Huck <cohuck@redhat.com>
|
|
|
c687bc |
(cherry picked from commit c1db53a5910f988eeb32f031c53a50f3373fd824)
|
|
|
c687bc |
Signed-off-by: Thomas Huth <thuth@redhat.com>
|
|
|
c687bc |
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
|
|
|
c687bc |
---
|
|
|
c687bc |
hw/s390x/event-facility.c | 2 +-
|
|
|
c687bc |
hw/s390x/sclp.c | 55 ++++++++++++++++++++++-----------------
|
|
|
c687bc |
include/hw/s390x/sclp.h | 2 +-
|
|
|
c687bc |
3 files changed, 33 insertions(+), 26 deletions(-)
|
|
|
c687bc |
|
|
|
c687bc |
diff --git a/hw/s390x/event-facility.c b/hw/s390x/event-facility.c
|
|
|
c687bc |
index 66205697ae7..8aa7017f06b 100644
|
|
|
c687bc |
--- a/hw/s390x/event-facility.c
|
|
|
c687bc |
+++ b/hw/s390x/event-facility.c
|
|
|
c687bc |
@@ -215,7 +215,7 @@ static uint16_t handle_sccb_read_events(SCLPEventFacility *ef, SCCB *sccb,
|
|
|
c687bc |
|
|
|
c687bc |
event_buf = &red->ebh;
|
|
|
c687bc |
event_buf->length = 0;
|
|
|
c687bc |
- slen = sizeof(sccb->data);
|
|
|
c687bc |
+ slen = sccb_data_len(sccb);
|
|
|
c687bc |
|
|
|
c687bc |
rc = SCLP_RC_NO_EVENT_BUFFERS_STORED;
|
|
|
c687bc |
|
|
|
c687bc |
diff --git a/hw/s390x/sclp.c b/hw/s390x/sclp.c
|
|
|
c687bc |
index 38278497319..cf1292beb22 100644
|
|
|
c687bc |
--- a/hw/s390x/sclp.c
|
|
|
c687bc |
+++ b/hw/s390x/sclp.c
|
|
|
c687bc |
@@ -231,25 +231,29 @@ int sclp_service_call_protected(CPUS390XState *env, uint64_t sccb,
|
|
|
c687bc |
{
|
|
|
c687bc |
SCLPDevice *sclp = get_sclp_device();
|
|
|
c687bc |
SCLPDeviceClass *sclp_c = SCLP_GET_CLASS(sclp);
|
|
|
c687bc |
- SCCB work_sccb;
|
|
|
c687bc |
- hwaddr sccb_len = sizeof(SCCB);
|
|
|
c687bc |
+ SCCBHeader header;
|
|
|
c687bc |
+ g_autofree SCCB *work_sccb = NULL;
|
|
|
c687bc |
|
|
|
c687bc |
- s390_cpu_pv_mem_read(env_archcpu(env), 0, &work_sccb, sccb_len);
|
|
|
c687bc |
+ s390_cpu_pv_mem_read(env_archcpu(env), 0, &header, sizeof(SCCBHeader));
|
|
|
c687bc |
+
|
|
|
c687bc |
+ work_sccb = g_malloc0(be16_to_cpu(header.length));
|
|
|
c687bc |
+ s390_cpu_pv_mem_read(env_archcpu(env), 0, work_sccb,
|
|
|
c687bc |
+ be16_to_cpu(header.length));
|
|
|
c687bc |
|
|
|
c687bc |
if (!sclp_command_code_valid(code)) {
|
|
|
c687bc |
- work_sccb.h.response_code = cpu_to_be16(SCLP_RC_INVALID_SCLP_COMMAND);
|
|
|
c687bc |
+ work_sccb->h.response_code = cpu_to_be16(SCLP_RC_INVALID_SCLP_COMMAND);
|
|
|
c687bc |
goto out_write;
|
|
|
c687bc |
}
|
|
|
c687bc |
|
|
|
c687bc |
- if (!sccb_verify_boundary(sccb, be16_to_cpu(work_sccb.h.length))) {
|
|
|
c687bc |
- work_sccb.h.response_code = cpu_to_be16(SCLP_RC_SCCB_BOUNDARY_VIOLATION);
|
|
|
c687bc |
+ if (!sccb_verify_boundary(sccb, be16_to_cpu(work_sccb->h.length))) {
|
|
|
c687bc |
+ work_sccb->h.response_code = cpu_to_be16(SCLP_RC_SCCB_BOUNDARY_VIOLATION);
|
|
|
c687bc |
goto out_write;
|
|
|
c687bc |
}
|
|
|
c687bc |
|
|
|
c687bc |
- sclp_c->execute(sclp, &work_sccb, code);
|
|
|
c687bc |
+ sclp_c->execute(sclp, work_sccb, code);
|
|
|
c687bc |
out_write:
|
|
|
c687bc |
- s390_cpu_pv_mem_write(env_archcpu(env), 0, &work_sccb,
|
|
|
c687bc |
- be16_to_cpu(work_sccb.h.length));
|
|
|
c687bc |
+ s390_cpu_pv_mem_write(env_archcpu(env), 0, work_sccb,
|
|
|
c687bc |
+ be16_to_cpu(work_sccb->h.length));
|
|
|
c687bc |
sclp_c->service_interrupt(sclp, SCLP_PV_DUMMY_ADDR);
|
|
|
c687bc |
return 0;
|
|
|
c687bc |
}
|
|
|
c687bc |
@@ -258,9 +262,8 @@ int sclp_service_call(CPUS390XState *env, uint64_t sccb, uint32_t code)
|
|
|
c687bc |
{
|
|
|
c687bc |
SCLPDevice *sclp = get_sclp_device();
|
|
|
c687bc |
SCLPDeviceClass *sclp_c = SCLP_GET_CLASS(sclp);
|
|
|
c687bc |
- SCCB work_sccb;
|
|
|
c687bc |
-
|
|
|
c687bc |
- hwaddr sccb_len = sizeof(SCCB);
|
|
|
c687bc |
+ SCCBHeader header;
|
|
|
c687bc |
+ g_autofree SCCB *work_sccb = NULL;
|
|
|
c687bc |
|
|
|
c687bc |
/* first some basic checks on program checks */
|
|
|
c687bc |
if (env->psw.mask & PSW_MASK_PSTATE) {
|
|
|
c687bc |
@@ -274,32 +277,36 @@ int sclp_service_call(CPUS390XState *env, uint64_t sccb, uint32_t code)
|
|
|
c687bc |
return -PGM_SPECIFICATION;
|
|
|
c687bc |
}
|
|
|
c687bc |
|
|
|
c687bc |
+ /* the header contains the actual length of the sccb */
|
|
|
c687bc |
+ cpu_physical_memory_read(sccb, &header, sizeof(SCCBHeader));
|
|
|
c687bc |
+
|
|
|
c687bc |
+ /* Valid sccb sizes */
|
|
|
c687bc |
+ if (be16_to_cpu(header.length) < sizeof(SCCBHeader)) {
|
|
|
c687bc |
+ return -PGM_SPECIFICATION;
|
|
|
c687bc |
+ }
|
|
|
c687bc |
+
|
|
|
c687bc |
/*
|
|
|
c687bc |
* we want to work on a private copy of the sccb, to prevent guests
|
|
|
c687bc |
* from playing dirty tricks by modifying the memory content after
|
|
|
c687bc |
* the host has checked the values
|
|
|
c687bc |
*/
|
|
|
c687bc |
- cpu_physical_memory_read(sccb, &work_sccb, sccb_len);
|
|
|
c687bc |
-
|
|
|
c687bc |
- /* Valid sccb sizes */
|
|
|
c687bc |
- if (be16_to_cpu(work_sccb.h.length) < sizeof(SCCBHeader)) {
|
|
|
c687bc |
- return -PGM_SPECIFICATION;
|
|
|
c687bc |
- }
|
|
|
c687bc |
+ work_sccb = g_malloc0(be16_to_cpu(header.length));
|
|
|
c687bc |
+ cpu_physical_memory_read(sccb, work_sccb, be16_to_cpu(header.length));
|
|
|
c687bc |
|
|
|
c687bc |
if (!sclp_command_code_valid(code)) {
|
|
|
c687bc |
- work_sccb.h.response_code = cpu_to_be16(SCLP_RC_INVALID_SCLP_COMMAND);
|
|
|
c687bc |
+ work_sccb->h.response_code = cpu_to_be16(SCLP_RC_INVALID_SCLP_COMMAND);
|
|
|
c687bc |
goto out_write;
|
|
|
c687bc |
}
|
|
|
c687bc |
|
|
|
c687bc |
- if (!sccb_verify_boundary(sccb, be16_to_cpu(work_sccb.h.length))) {
|
|
|
c687bc |
- work_sccb.h.response_code = cpu_to_be16(SCLP_RC_SCCB_BOUNDARY_VIOLATION);
|
|
|
c687bc |
+ if (!sccb_verify_boundary(sccb, be16_to_cpu(work_sccb->h.length))) {
|
|
|
c687bc |
+ work_sccb->h.response_code = cpu_to_be16(SCLP_RC_SCCB_BOUNDARY_VIOLATION);
|
|
|
c687bc |
goto out_write;
|
|
|
c687bc |
}
|
|
|
c687bc |
|
|
|
c687bc |
- sclp_c->execute(sclp, &work_sccb, code);
|
|
|
c687bc |
+ sclp_c->execute(sclp, work_sccb, code);
|
|
|
c687bc |
out_write:
|
|
|
c687bc |
- cpu_physical_memory_write(sccb, &work_sccb,
|
|
|
c687bc |
- be16_to_cpu(work_sccb.h.length));
|
|
|
c687bc |
+ cpu_physical_memory_write(sccb, work_sccb,
|
|
|
c687bc |
+ be16_to_cpu(work_sccb->h.length));
|
|
|
c687bc |
|
|
|
c687bc |
sclp_c->service_interrupt(sclp, sccb);
|
|
|
c687bc |
|
|
|
c687bc |
diff --git a/include/hw/s390x/sclp.h b/include/hw/s390x/sclp.h
|
|
|
c687bc |
index c0a3faa37d7..55f53a46540 100644
|
|
|
c687bc |
--- a/include/hw/s390x/sclp.h
|
|
|
c687bc |
+++ b/include/hw/s390x/sclp.h
|
|
|
c687bc |
@@ -177,7 +177,7 @@ typedef struct IoaCfgSccb {
|
|
|
c687bc |
|
|
|
c687bc |
typedef struct SCCB {
|
|
|
c687bc |
SCCBHeader h;
|
|
|
c687bc |
- char data[SCCB_DATA_LEN];
|
|
|
c687bc |
+ char data[];
|
|
|
c687bc |
} QEMU_PACKED SCCB;
|
|
|
c687bc |
|
|
|
c687bc |
#define TYPE_SCLP "sclp"
|
|
|
c687bc |
--
|
|
|
c687bc |
2.27.0
|
|
|
c687bc |
|