yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
c687bc
From bc395a979a00bb3e16f3bd92b5b2006db4a5aee3 Mon Sep 17 00:00:00 2001
c687bc
From: Thomas Huth <thuth@redhat.com>
c687bc
Date: Wed, 11 Nov 2020 12:03:07 -0500
c687bc
Subject: [PATCH 07/18] s390/sclp: rework sclp boundary checks
c687bc
c687bc
RH-Author: Thomas Huth <thuth@redhat.com>
c687bc
Message-id: <20201111120316.707489-4-thuth@redhat.com>
c687bc
Patchwork-id: 99500
c687bc
O-Subject: [RHEL-8.4.0 qemu-kvm PATCH v2 03/12] s390/sclp: rework sclp boundary checks
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
Rework the SCLP boundary check to account for different SCLP commands
c687bc
(eventually) allowing different boundary sizes.
c687bc
c687bc
Signed-off-by: Collin Walling <walling@linux.ibm.com>
c687bc
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
c687bc
Reviewed-by: Thomas Huth <thuth@redhat.com>
c687bc
Acked-by: Janosch Frank <frankja@linux.ibm.com>
c687bc
Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
c687bc
Message-Id: <20200915194416.107460-3-walling@linux.ibm.com>
c687bc
Signed-off-by: Cornelia Huck <cohuck@redhat.com>
c687bc
(cherry picked from commit db13387ca01a69d870cc16dd232375c2603596f2)
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/sclp.c | 19 ++++++++++++++++++-
c687bc
 1 file changed, 18 insertions(+), 1 deletion(-)
c687bc
c687bc
diff --git a/hw/s390x/sclp.c b/hw/s390x/sclp.c
c687bc
index fe7d0fece80..38278497319 100644
c687bc
--- a/hw/s390x/sclp.c
c687bc
+++ b/hw/s390x/sclp.c
c687bc
@@ -49,6 +49,18 @@ static inline bool sclp_command_code_valid(uint32_t code)
c687bc
     return false;
c687bc
 }
c687bc
 
c687bc
+static bool sccb_verify_boundary(uint64_t sccb_addr, uint16_t sccb_len)
c687bc
+{
c687bc
+    uint64_t sccb_max_addr = sccb_addr + sccb_len - 1;
c687bc
+    uint64_t sccb_boundary = (sccb_addr & PAGE_MASK) + PAGE_SIZE;
c687bc
+
c687bc
+    if (sccb_max_addr < sccb_boundary) {
c687bc
+        return true;
c687bc
+    }
c687bc
+
c687bc
+    return false;
c687bc
+}
c687bc
+
c687bc
 static void prepare_cpu_entries(MachineState *ms, CPUEntry *entry, int *count)
c687bc
 {
c687bc
     uint8_t features[SCCB_CPU_FEATURE_LEN] = { 0 };
c687bc
@@ -229,6 +241,11 @@ int sclp_service_call_protected(CPUS390XState *env, uint64_t sccb,
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
+        goto out_write;
c687bc
+    }
c687bc
+
c687bc
     sclp_c->execute(sclp, &work_sccb, code);
c687bc
 out_write:
c687bc
     s390_cpu_pv_mem_write(env_archcpu(env), 0, &work_sccb,
c687bc
@@ -274,7 +291,7 @@ int sclp_service_call(CPUS390XState *env, uint64_t sccb, uint32_t code)
c687bc
         goto out_write;
c687bc
     }
c687bc
 
c687bc
-    if ((sccb + be16_to_cpu(work_sccb.h.length)) > ((sccb & PAGE_MASK) + PAGE_SIZE)) {
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
2.27.0
c687bc