cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-s390-sclp-check-sccb-len-before-filling-in-data.patch

8fced6
From 6cc7c8dd7a6fac493c648c607bec4c38c0b275b6 Mon Sep 17 00:00:00 2001
8fced6
From: Thomas Huth <thuth@redhat.com>
8fced6
Date: Wed, 11 Nov 2020 12:03:09 -0500
8fced6
Subject: [PATCH 09/18] s390/sclp: check sccb len before filling in data
8fced6
8fced6
RH-Author: Thomas Huth <thuth@redhat.com>
8fced6
Message-id: <20201111120316.707489-6-thuth@redhat.com>
8fced6
Patchwork-id: 99502
8fced6
O-Subject: [RHEL-8.4.0 qemu-kvm PATCH v2 05/12] s390/sclp: check sccb len before filling in data
8fced6
Bugzilla: 1798506
8fced6
RH-Acked-by: Jens Freimann <jfreimann@redhat.com>
8fced6
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
8fced6
RH-Acked-by: David Hildenbrand <david@redhat.com>
8fced6
8fced6
From: Collin Walling <walling@linux.ibm.com>
8fced6
8fced6
The SCCB must be checked for a sufficient length before it is filled
8fced6
with any data. If the length is insufficient, then the SCLP command
8fced6
is suppressed and the proper response code is set in the SCCB header.
8fced6
8fced6
While we're at it, let's cleanup the length check by placing the
8fced6
calculation inside a macro.
8fced6
8fced6
Fixes: 832be0d8a3bb ("s390x: sclp: Report insufficient SCCB length")
8fced6
Signed-off-by: Collin Walling <walling@linux.ibm.com>
8fced6
Reviewed-by: Janosch Frank <frankja@linux.ibm.com>
8fced6
Reviewed-by: David Hildenbrand <david@redhat.com>
8fced6
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
8fced6
Reviewed-by: Thomas Huth <thuth@redhat.com>
8fced6
Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
8fced6
Message-Id: <20200915194416.107460-5-walling@linux.ibm.com>
8fced6
Signed-off-by: Cornelia Huck <cohuck@redhat.com>
8fced6
(cherry picked from commit 0260b97824495ebfacfa8bbae0be10b0ef986bf6)
8fced6
Signed-off-by: Thomas Huth <thuth@redhat.com>
8fced6
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
8fced6
---
8fced6
 hw/s390x/sclp.c | 26 ++++++++++++++------------
8fced6
 1 file changed, 14 insertions(+), 12 deletions(-)
8fced6
8fced6
diff --git a/hw/s390x/sclp.c b/hw/s390x/sclp.c
8fced6
index cf1292beb22..2b4c6c5cfad 100644
8fced6
--- a/hw/s390x/sclp.c
8fced6
+++ b/hw/s390x/sclp.c
8fced6
@@ -78,6 +78,8 @@ static void prepare_cpu_entries(MachineState *ms, CPUEntry *entry, int *count)
8fced6
     }
8fced6
 }
8fced6
 
8fced6
+#define SCCB_REQ_LEN(s, max_cpus) (sizeof(s) + max_cpus * sizeof(CPUEntry))
8fced6
+
8fced6
 /* Provide information about the configuration, CPUs and storage */
8fced6
 static void read_SCP_info(SCLPDevice *sclp, SCCB *sccb)
8fced6
 {
8fced6
@@ -86,6 +88,12 @@ static void read_SCP_info(SCLPDevice *sclp, SCCB *sccb)
8fced6
     int cpu_count;
8fced6
     int rnsize, rnmax;
8fced6
     IplParameterBlock *ipib = s390_ipl_get_iplb();
8fced6
+    int required_len = SCCB_REQ_LEN(ReadInfo, machine->possible_cpus->len);
8fced6
+
8fced6
+    if (be16_to_cpu(sccb->h.length) < required_len) {
8fced6
+        sccb->h.response_code = cpu_to_be16(SCLP_RC_INSUFFICIENT_SCCB_LENGTH);
8fced6
+        return;
8fced6
+    }
8fced6
 
8fced6
     /* CPU information */
8fced6
     prepare_cpu_entries(machine, read_info->entries, &cpu_count);
8fced6
@@ -95,12 +103,6 @@ static void read_SCP_info(SCLPDevice *sclp, SCCB *sccb)
8fced6
 
8fced6
     read_info->ibc_val = cpu_to_be32(s390_get_ibc_val());
8fced6
 
8fced6
-    if (be16_to_cpu(sccb->h.length) <
8fced6
-            (sizeof(ReadInfo) + cpu_count * sizeof(CPUEntry))) {
8fced6
-        sccb->h.response_code = cpu_to_be16(SCLP_RC_INSUFFICIENT_SCCB_LENGTH);
8fced6
-        return;
8fced6
-    }
8fced6
-
8fced6
     /* Configuration Characteristic (Extension) */
8fced6
     s390_get_feat_block(S390_FEAT_TYPE_SCLP_CONF_CHAR,
8fced6
                          read_info->conf_char);
8fced6
@@ -146,18 +148,18 @@ static void sclp_read_cpu_info(SCLPDevice *sclp, SCCB *sccb)
8fced6
     MachineState *machine = MACHINE(qdev_get_machine());
8fced6
     ReadCpuInfo *cpu_info = (ReadCpuInfo *) sccb;
8fced6
     int cpu_count;
8fced6
+    int required_len = SCCB_REQ_LEN(ReadCpuInfo, machine->possible_cpus->len);
8fced6
+
8fced6
+    if (be16_to_cpu(sccb->h.length) < required_len) {
8fced6
+        sccb->h.response_code = cpu_to_be16(SCLP_RC_INSUFFICIENT_SCCB_LENGTH);
8fced6
+        return;
8fced6
+    }
8fced6
 
8fced6
     prepare_cpu_entries(machine, cpu_info->entries, &cpu_count);
8fced6
     cpu_info->nr_configured = cpu_to_be16(cpu_count);
8fced6
     cpu_info->offset_configured = cpu_to_be16(offsetof(ReadCpuInfo, entries));
8fced6
     cpu_info->nr_standby = cpu_to_be16(0);
8fced6
 
8fced6
-    if (be16_to_cpu(sccb->h.length) <
8fced6
-            (sizeof(ReadCpuInfo) + cpu_count * sizeof(CPUEntry))) {
8fced6
-        sccb->h.response_code = cpu_to_be16(SCLP_RC_INSUFFICIENT_SCCB_LENGTH);
8fced6
-        return;
8fced6
-    }
8fced6
-
8fced6
     /* The standby offset is 16-byte for each CPU */
8fced6
     cpu_info->offset_standby = cpu_to_be16(cpu_info->offset_configured
8fced6
         + cpu_info->nr_configured*sizeof(CPUEntry));
8fced6
-- 
8fced6
2.27.0
8fced6