s390x: more interface hardening
cover s390x: more interface hardening
Some more fixes in the sclp resiliency
Christian Borntraeger (2):
s390x/sclp: prevent re-reading the sclp header s390x/sclpcpi: check event length field before reading from buffer
hw/s390x/sclp.c | 4 +++- hw/s390x/sclpcpi.c | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-)
Signature · 1 line
2.53.0
PATCH 1/2 s390x/sclp: prevent re-reading the sclp header
We verify the sccb length and then allocate based on that length. The following access re-reads the sccb again. This can race against other vCPUs overwriting the length field.
sclp_service_call_protected does not need a change as the ultravisor provides a consistent snapshot.
--- hw/s390x/sclp.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
hw/s390x/sclp.c +3 -1
@@ -329,7 +329,8 @@ int sclp_service_call(S390CPU *cpu, uint64_t sccb, uint32_t code)/* * we want to work on a private copy of the sccb, to prevent guests * from playing dirty tricks by modifying the memory content after -* the host has checked the values +* the host has checked the values. +* Reuse the previously fetched header */ work_sccb =g_malloc0 (be16_to_cpu (header.length)); ret = address_space_read(as, sccb, attrs,
@@ -337,6 +338,7 @@ int sclp_service_call(S390CPU *cpu, uint64_t sccb, uint32_t code)if (ret !=MEMTX_OK ) {return -PGM_ADDRESSING ; } + work_sccb->h = header;if (!sclp_command_code_valid (code)) { work_sccb->h.response_code =cpu_to_be16 (SCLP_RC_INVALID_SCLP_COMMAND );
Signature · 1 line
2.53.0
Re: [PATCH 1/2] s390x/sclp: prevent re-reading the sclp header
Quoted 7 lines · Christian Borntraeger
We verify the sccb length and then allocate based on that length. The following access re-reads the sccb again. This can race against other vCPUs overwriting the length field.
sclp_service_call_protecteddoes not need a change as the ultravisor provides a consistent snapshot.
Quoted 7 lines
Fixes c1db53a5910f ("s390/sclp: read sccb from mem based on provided length")Signed-off-by Christian Borntraeger <[email protected]>Reviewed-by Matthew Rosato <[email protected]>--- hw/s390x/sclp.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
Re: [PATCH 1/2] s390x/sclp: prevent re-reading the sclp header
In reply to Christian BorntraegerQuoted 30 lines · Christian Borntraeger
We verify the sccb length and then allocate based on that length. The following access re-reads the sccb again. This can race against other vCPUs overwriting the length field.
sclp_service_call_protecteddoes not need a change as the ultravisor provides a consistent snapshot.Fixes c1db53a5910f ("s390/sclp: read sccb from mem based on provided length")Signed-off-by Christian Borntraeger <[email protected]>Reviewed-by Matthew Rosato <[email protected]>--- hw/s390x/sclp.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)hw/s390x/sclp.c +2
-1@@ -329,7 +329,8 @@ int sclp_service_call(S390CPU *cpu, uint64_t sccb, uint32_t code)/* * we want to work on a private copy of the sccb, to prevent guests * from playing dirty tricks by modifying the memory content after -* the host has checked the values +* the host has checked the values. +* Reuse the previously fetched header */ work_sccb =g_malloc0 (be16_to_cpu (header.length)); ret = address_space_read(as, sccb, attrs,
hw/s390x/sclp.c int sclp_service_call(S390CPU *cpu, uint64_t sccb, uint32_t code) · line 344
Quoted 7 lines
hw/s390x/sclp.c +1
-0@@ -337,6 +338,7 @@ int sclp_service_call(S390CPU *cpu, uint64_t sccb, uint32_t code)if (ret !=MEMTX_OK ) {return -PGM_ADDRESSING ; } + work_sccb->h = header;if (!sclp_command_code_valid (code)) { work_sccb->h.response_code =cpu_to_be16 (SCLP_RC_INVALID_SCLP_COMMAND );
I guess the alternative (and messier) approach would be to re-validate the new header. This proposal looks good to me.
Signature · 2 lines
Regards, Collin
PATCH 2/2 s390x/sclpcpi: check event length field before reading from buffer
In reply to Christian BorntraegerA guest might send a too short SCCB with SCLP_EVENT_CTRL_PGM_ID. QEMU would fill its data structures with garbage data. Check for the precise length of the CBI data structure and reject otherwise.
--- hw/s390x/sclpcpi.c | 5 +++++ 1 file changed, 5 insertions(+)
hw/s390x/sclpcpi.c +5 -0
@@ -97,6 +97,11 @@ static int write_event_data(SCLPEvent *event, EventBufferHeader *evt_buf_hdr) ebh);SCLPEventCPI *e =SCLP_EVENT_CPI (event); +/* Caller checks sccb length, buffer header checking is our duty */ +if (be16_to_cpu (evt_buf_hdr->length) !=sizeof (ControlProgramIdMsg)) { +return SCLP_RC_INCONSISTENT_LENGTHS ; + } +ascii_put (e->system_type, (char *)cpim->data.system_type,sizeof (cpim->data.system_type)); ascii_put(e->system_name, (char *)cpim->data.system_name,
Signature · 1 line
2.53.0
Re: [PATCH 2/2] s390x/sclpcpi: check event length field before reading from buffer
Quoted 4 lines · Christian Borntraeger
A guest might send a too short SCCB with
SCLP_EVENT_CTRL_PGM_ID. QEMU would fill its data structures with garbage data. Check for the precise length of the CBI data structure and reject otherwise.
Quoted 8 lines
Fixes f345978f24be ("hw/s390x: add Control-Program Identification to QOM")Signed-off-by Christian Borntraeger <[email protected]>Reviewed-by Matthew Rosato <[email protected]>Reviewed-by Janosch Frank <[email protected]>--- hw/s390x/sclpcpi.c | 5 +++++ 1 file changed, 5 insertions(+)