s390x: even more hardening fixes
PATCH v3 5/9 vfio/ccw: Clear error object pointer after non-fatal errors
In reply to Eric FarmanJust like in vfio/ap, there is a non-fatal message that could be generated, with a stale pointer in the error object variable.
Unlike vfio/ap, there is no secondary message that could attempt to use it. Clear it in the same way, in case that ever changes.
--- hw/vfio/ccw.c | 2 ++ 1 file changed, 2 insertions(+)
hw/vfio/ccw.c +2 -0
@@ -604,8 +604,10 @@ static void vfio_ccw_realize(DeviceState *dev, Error **errp)/* * Report this error, but do not make it a failing condition. * Lack of this IRQ in the host does not prevent normal operation. +* Clear the pointer, since the warning will release it. */ warn_report_err (err); + err =NULL ; }return ;
Signature · 1 line
2.53.0
PATCH v3 3/9 virtio-ccw: Fix rc check in read configuration path
In reply to Eric FarmanBoth the read and write config paths use wrappers around cds->op_handler, depending on the direction the I/O is flowing. But they expect opposite values in the returned variable to indicate success.
Fix this by unifying those checks, where CCW_CMD_READ_CONF needs to see !ret as success. The end result is some erroneous data in the SCSW response data, but the overall success/failure is correct.
--- hw/s390x/virtio-ccw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/s390x/virtio-ccw.c +1 -1
@@ -475,7 +475,7 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw) }else {virtio_bus_get_vdev_config (&dev->bus, vdev->config); ret =ccw_dstream_write_buf (&sch->cds, vdev->config, len); -if (ret) { +if (!ret) { sch->curr_status.scsw.count = ccw.count - len; } }
Signature · 1 line
2.53.0
PATCH v3 7/9 hw/intc/s390x: Fix check after g_try_realloc
In reply to Eric FarmanThe loop to store pending IRQs uses g_try_realloc() to expand the buffer being used, but the returned address is stored in a pointer-to-pointer, thus the check is supposed to be examining the contents of the pointer, and not the pointer itself.
Define a temporary variable to catch and test the returned pointer. If it's NULL, return to the caller to perform the free on the unmodified buffer. If it's not NULL, store it in the caller's pointer and restart the loop against the new struct.
--- hw/intc/s390_flic_kvm.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
hw/intc/s390_flic_kvm.c +4 -2
@@ -254,6 +254,7 @@ static int __get_all_irqs(KVMS390FLICState *flic, void **buf, int len) { int r; +void *new_buf =NULL ; do { /* returns -ENOMEM if buffer is too small and number
@@ -263,10 +264,11 @@ static int __get_all_irqs(KVMS390FLICState *flic,break ; } len *=2 ; - *buf =g_try_realloc (*buf, len); -if (!buf) { + new_buf =g_try_realloc (*buf, len); +if (!new_buf) {return -ENOMEM ; } + *buf = new_buf; }while (r == -ENOMEM && len <=KVM_S390_FLIC_MAX_BUFFER );return r;
Signature · 1 line
2.53.0
PATCH v3 4/9 vfio/ap: Clear error object pointer after non-fatal errors
In reply to Eric FarmanRegistering a new IRQ notifier will allocate an error object if needed, and warn_report_err() will release that memory once it's finished. The pointer remains, however, so subsequent errors after the non-fatal errors in vfio_ap_realize() would cause an assertion failure for a non-NULL pointer.
Fix this by clearing the pointer once the warning has been reported, to reset the state of the error objects.
--- hw/vfio/ap.c | 4 ++++ 1 file changed, 4 insertions(+)
hw/vfio/ap.c +4 -0
@@ -247,8 +247,10 @@ static void vfio_ap_realize(DeviceState *dev, Error **errp)/* * Report this error, but do not make it a failing condition. * Lack of this IRQ in the host does not prevent normal operation. +* Clear the pointer, since the warning will release it. */ warn_report_err (err); + err =NULL ; }if (!vfio_ap_register_irq_notifier (vapdev,VFIO_AP_CFG_CHG_IRQ_INDEX , &err))
@@ -256,8 +258,10 @@ static void vfio_ap_realize(DeviceState *dev, Error **errp)/* * Report this error, but do not make it a failing condition. * Lack of this IRQ in the host does not prevent normal operation. +* Clear the pointer, since the warning will release it. */ warn_report_err (err); + err =NULL ; }return ;
Signature · 1 line
2.53.0
PATCH v3 8/9 s390x/css: Use datastream pointer for checking no-data CCWs
In reply to Eric FarmanThe channel subsystem will reject channel programs that incorporate 256 CCWs without a data transfer, but the existing check to account for this only does so for CCWs with a data address of zero. Other valid CCWs that wouldn't transfer data are not accounted for.
Rather than re-inventing the wheel, use the output of the datastream at the end of the entire CCW parsing tree to indicate whether data was moved or not.
--- hw/s390x/css.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-)
hw/s390x/css.c +14 -7
@@ -1016,13 +1016,6 @@ static int css_interpret_ccw(SubchDev *sch, hwaddr ccw_addr, check_len = !((ccw.flags &CCW_FLAG_SLI ) && !(ccw.flags &CCW_FLAG_DC )); -if (!ccw.cda) { -if (sch->ccw_no_data_cnt ==255 ) { -return -EINVAL ; - } - sch->ccw_no_data_cnt++; - } -/* Look at the command. */ ccw_dstream_init (&sch->cds, &ccw, &(sch->orb));switch (ccw.cmd_code) {
@@ -1103,6 +1096,20 @@ static int css_interpret_ccw(SubchDev *sch, hwaddr ccw_addr, } sch->last_cmd = ccw; sch->last_cmd_valid = true; + +/* +* A CCW that transfers no data is allowed, but ensure an upper limit +* is established to prevent long-running channel programs that don't +* move actual data. +*/ +if (ret ==0 && sch->cds.at_byte ==0 ) { +if (sch->ccw_no_data_cnt ==255 ) { + ret = -EINVAL ; + }else { + sch->ccw_no_data_cnt++; + } + } +if (ret ==0 ) {if (ccw.flags &CCW_FLAG_CC ) { sch->channel_prog +=8 ;
Signature · 1 line
2.53.0
PATCH v3 6/9 hw/intc/s390x: Fix payload to KVM_HAS_DEVICE_ATTR ioctl
In reply to Eric FarmanThe ioctl to determine whether KVM_DEV_FLIC_CLEAR_IO_IRQ is present receives the contents of the attribute struct as its payload, rather than a pointer to the payload itself as is convention.
This may result in erroneous errors from the ioctl, which would result in clear_io_supported being false when it otherwise could be used (which is helpful in device recovery).
--- hw/intc/s390_flic_kvm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/intc/s390_flic_kvm.c +1 -1
@@ -633,7 +633,7 @@ static void kvm_s390_flic_realize(DeviceState *dev, Error **errp)/* Check clear_io_irq support */ test_attr.group =KVM_DEV_FLIC_CLEAR_IO_IRQ ; flic_state->clear_io_supported = !ioctl (flic_state->fd, -KVM_HAS_DEVICE_ATTR , test_attr); +KVM_HAS_DEVICE_ATTR , &test_attr); }static void kvm_s390_flic_reset (DeviceState *dev)
Signature · 1 line
2.53.0
PATCH v3 9/9 s390x/sclp: Reject short headers in PV case
In reply to Eric FarmanAn invalid length in an SCCB header correctly generates a specification exception for the regular (non-PV) codepath that processes an SCLP instruction intercept. The PV case doesn't, even though such a thing should already be sanitized. Since a short length will cause problems later down the line with the storage that will be allocated based on that size, put up a defensive check and return if it is too short.
--- hw/s390x/sclp.c | 6 ++++++ 1 file changed, 6 insertions(+)
hw/s390x/sclp.c +6 -0
@@ -277,6 +277,11 @@ int sclp_service_call_protected(S390CPU *cpu, uint64_t sccb, uint32_t code)s390_cpu_pv_mem_read (env_archcpu (env),0 , &header,sizeof (SCCBHeader)); +/* Do nothing if the header appears malformed */ +if (be16_to_cpu (header.length) <sizeof (SCCBHeader)) { + goto out_no_write; + } + work_sccb =g_malloc0 (be16_to_cpu (header.length));s390_cpu_pv_mem_read (env_archcpu (env),0 , work_sccb,be16_to_cpu (header.length));
@@ -290,6 +295,7 @@ int sclp_service_call_protected(S390CPU *cpu, uint64_t sccb, uint32_t code) out_write:s390_cpu_pv_mem_write (env_archcpu (env),0 , work_sccb,be16_to_cpu (header.length)); +out_no_write: sclp_c->service_interrupt (sclp,SCLP_PV_DUMMY_ADDR );return 0 ; }
Signature · 1 line
2.53.0
PATCH v3 2/9 virtio-ccw: Do not overwrite existing indicators
In reply to Eric FarmanThe various indicators pointers allow them to be overwritten, but leak any existing structs that might be there. If indicators exist, ensure that they are released before setting the new ones.
Both the regular and adapter interrupt paths check that they aren't being asked to enable interrupts when the other one is enabled, so just do this release once all the potential checks are completed.
--- hw/s390x/virtio-ccw.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
hw/s390x/virtio-ccw.c +21 -0
@@ -582,6 +582,11 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw)if (ret) {break ; } +if (dev->indicators) { +/* Need to remove existing indicators first */ +release_indicator (&dev->routes.adapter, dev->indicators); + dev->indicators =NULL ; + } indicators =be64_to_cpu (indicators); dev->indicators =get_indicator (indicators,sizeof (uint64_t )); sch->curr_status.scsw.count = ccw.count -sizeof (indicators);
@@ -606,6 +611,11 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw)if (ret) {break ; } +if (dev->indicators2) { +/* Need to remove existing indicators first */ +release_indicator (&dev->routes.adapter, dev->indicators2); + dev->indicators2 =NULL ; + } indicators =be64_to_cpu (indicators); dev->indicators2 =get_indicator (indicators,sizeof (uint64_t )); sch->curr_status.scsw.count = ccw.count -sizeof (indicators);
@@ -666,6 +676,17 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw) }else if (thinint.isc >MAX_ISC ) { ret = -ENOSYS ; }else { +if (dev->indicators) { +/* Need to remove existing indicators first */ +release_indicator (&dev->routes.adapter, dev->indicators); + dev->indicators =NULL ; + } +if (dev->summary_indicator) { +/* Need to remove existing indicators first */ +release_indicator (&dev->routes.adapter, + dev->summary_indicator); + dev->summary_indicator =NULL ; + } thinint.ind_bit =be64_to_cpu (thinint.ind_bit); thinint.summary_indicator =be64_to_cpu (thinint.summary_indicator);
Signature · 1 line
2.53.0
v3 cover s390x: even more hardening fixes
A small pile of additional hardening fixes.
v2->v3:
- Collect reviews/acks (Thanks Christian, Matt!)
- [CB] Patch 7: Rename realloc variable to new_buf
- [CB] Patch 8: Move check of at_byte before check of command chaining flag
v1->v2: https://lore.kernel.org/qemu-devel/[email protected]/
- Collect reviews/acks (Thanks Matt, Christian, Tony!)
- [MR] Add fixes/stable tags to patches 1, 2, 8
- [CB, MR] Drop fixes/stable tags from patches 5, 6
- [CB] Patch 2: Unwind indicators upon re-set, instead of rejecting it
- [MR] Patch 7: Use a temporary variable on g_try_realloc() call
- [MR] Patch 8: Use CCW datastream to increment no-data count
v1: https://lore.kernel.org/qemu-devel/[email protected]/
Eric Farman (9):
virtio-ccw: Limit ISC to MAX_ISC
virtio-ccw: Do not overwrite existing indicators
virtio-ccw: Fix rc check in read configuration path vfio/ap: Clear error object pointer after non-fatal errors vfio/ccw: Clear error object pointer after non-fatal errors hw/intc/s390x: Fix payload to KVM_HAS_DEVICE_ATTR ioctl hw/intc/s390x: Fix check after g_try_realloc s390x/css: Use datastream pointer for checking no-data CCWs s390x/sclp: Reject short headers in PV case
hw/intc/s390_flic_kvm.c | 8 +++++--- hw/s390x/css.c | 28 ++++++++++++++++++++-------- hw/s390x/sclp.c | 6 ++++++ hw/s390x/virtio-ccw.c | 29 ++++++++++++++++++++++++++++- hw/vfio/ap.c | 4 ++++ hw/vfio/ccw.c | 2 ++ 6 files changed, 65 insertions(+), 12 deletions(-)
Signature · 1 line
2.53.0
PATCH v3 1/9 virtio-ccw: Limit ISC to MAX_ISC
The interrupt subclass is often defined as a uint8, though in practice it will be within the range of just 0-7. Ensure that a guest-supplied subclass does not extend beyond its expected range, especially when used as an array index.
--- hw/s390x/css.c | 7 ++++++- hw/s390x/virtio-ccw.c | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-)
hw/s390x/css.c +6 -1
@@ -654,8 +654,13 @@ void css_adapter_interrupt(CssIoAdapterType type, uint8_t isc)S390FLICState *fs =s390_get_flic ();S390FLICStateClass *fsc =s390_get_flic_class (fs);uint32_t io_int_word = (isc <<27 ) |IO_INT_WORD_AI ; -IoAdapter *adapter = channel_subsys.io_adapters[type][isc]; +IoAdapter *adapter; + +if (type >=CSS_IO_ADAPTER_TYPE_NUMS || isc >MAX_ISC ) { +return ; + } + adapter = channel_subsys.io_adapters[type][isc];if (!adapter) {return ; }
hw/s390x/virtio-ccw.c +6 -0
@@ -46,6 +46,10 @@ static int virtio_ccw_dev_post_load(void *opaque, int version_id)CcwDevice *ccw_dev =CCW_DEVICE (dev);CCWDeviceClass *ck =CCW_DEVICE_GET_CLASS (ccw_dev); +if (dev->thinint_isc >MAX_ISC ) { +return -EINVAL ; + } + ccw_dev->sch->driver_data = dev;if (ccw_dev->sch->thinint_active) { dev->routes.adapter.adapter_id = css_get_adapter_id(
@@ -659,6 +663,8 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw) }else {if (ccw_dstream_read (&sch->cds, thinint)) { ret = -EFAULT ; + }else if (thinint.isc >MAX_ISC ) { + ret = -ENOSYS ; }else { thinint.ind_bit =be64_to_cpu (thinint.ind_bit); thinint.summary_indicator =
Signature · 1 line
2.53.0
Re: [PATCH v3 8/9] s390x/css: Use datastream pointer for checking no-data CCWs
In reply to Eric FarmanQuoted 5 lines · Eric Farman
The channel subsystem will reject channel programs that incorporate 256 CCWs without a data transfer, but the existing check to account for this only does so for CCWs with a data address of zero. Other valid CCWs that wouldn't transfer data are not accounted for.
Quoted 7 lines
Rather than re-inventing the wheel, use the output of the datastream at the end of the entire CCW parsing tree to indicate whether data was moved or not.
Fixes e8601dd5d0 ("s390x/css: catch ccw sequence errors")Signed-off-by Eric Farman <[email protected]>
Am 22.09.26 um 22:15 schrieb Eric Farman:
Quoted 17 lines
A small pile of additional hardening fixes.
v2->v3:
- Collect reviews/acks (Thanks Christian, Matt!)
- [CB] Patch 7: Rename realloc variable tonew_buf
- [CB] Patch 8: Move check ofat_bytebefore check of command chaining flag
v1->v2: https://lore.kernel.org/qemu-devel/[email protected]/
- Collect reviews/acks (Thanks Matt, Christian, Tony!)
- [MR] Add fixes/stable tags to patches 1, 2, 8
- [CB, MR] Drop fixes/stable tags from patches 5, 6
- [CB] Patch 2: Unwind indicators upon re-set, instead of rejecting it
- [MR] Patch 7: Use a temporary variable ong_try_realloc()call
- [MR] Patch 8: Use CCW datastream to increment no-data count
Quoted 10 lines
Eric Farman (9):
virtio-ccw: Limit ISC toMAX_ISC
virtio-ccw: Do not overwrite existing indicators
virtio-ccw: Fix rc check in read configuration path vfio/ap: Clear error object pointer after non-fatal errors vfio/ccw: Clear error object pointer after non-fatal errors hw/intc/s390x: Fix payload toKVM_HAS_DEVICE_ATTRioctl hw/intc/s390x: Fix check afterg_try_reallocs390x/css: Use datastream pointer for checking no-data CCWs s390x/sclp: Reject short headers in PV case
Series looks sane to me.
Re: [PATCH v3 9/9] s390x/sclp: Reject short headers in PV case
In reply to Eric FarmanQuoted 7 lines · Eric Farman
An invalid length in an SCCB header correctly generates a specification exception for the regular (non-PV) codepath that processes an SCLP instruction intercept. The PV case doesn't, even though such a thing should already be sanitized. Since a short length will cause problems later down the line with the storage that will be allocated based on that size, put up a defensive check and return if it is too short.
Quoted 7 lines
Cc Janosch Frank <[email protected]>Fixes c1db53a591 ("s390/sclp: read sccb from mem based on provided length")Reviewed-by Matthew Rosato <[email protected]>Signed-off-by Eric Farman <[email protected]>---
How would you hit that if the architecture says FW will automatically inject a spec exception without exiting to the hypervisor if length < 8?
Did you witness this happening?
Am I missing something?
Quoted 27 lines
hw/s390x/sclp.c | 6 ++++++ 1 file changed, 6 insertions(+)hw/s390x/sclp.c +6
-0@@ -277,6 +277,11 @@ int sclp_service_call_protected(S390CPU *cpu, uint64_t sccb, uint32_t code)s390_cpu_pv_mem_read (env_archcpu (env),0 , &header,sizeof (SCCBHeader)); +/* Do nothing if the header appears malformed */ +if (be16_to_cpu (header.length) <sizeof (SCCBHeader)) { + goto out_no_write; + } + work_sccb =g_malloc0 (be16_to_cpu (header.length));s390_cpu_pv_mem_read (env_archcpu (env),0 , work_sccb,be16_to_cpu (header.length));@@ -290,6 +295,7 @@ int sclp_service_call_protected(S390CPU *cpu, uint64_t sccb, uint32_t code) out_write:s390_cpu_pv_mem_write (env_archcpu (env),0 , work_sccb,be16_to_cpu (header.length)); +out_no_write: sclp_c->service_interrupt (sclp,SCLP_PV_DUMMY_ADDR );return 0 ; }
Re: [PATCH v3 9/9] s390x/sclp: Reject short headers in PV case
Am 24.09.26 um 16:36 schrieb Janosch Frank:
Quoted 16 lines · Eric Farman
Quoted 7 lines
An invalid length in an SCCB header correctly generates a specification exception for the regular (non-PV) codepath that processes an SCLP instruction intercept. The PV case doesn't, even though such a thing should already be sanitized. Since a short length will cause problems later down the line with the storage that will be allocated based on that size, put up a defensive check and return if it is too short.
Quoted 7 lines
Cc Janosch Frank <[email protected]>Fixes c1db53a591 ("s390/sclp: read sccb from mem based on provided length")Reviewed-by Matthew Rosato <[email protected]>Signed-off-by Eric Farman <[email protected]>---
Quoted 1 line
How would you hit that if the architecture says FW will automatically inject a spec exception without exiting to the hypervisor if length < 8?
As I said in my review, current UV will sanitize this, so this is just defence in depth in case there would be an implementation error.
Quoted 30 lines
Did you witness this happening?
Am I missing something?Quoted 25 lines
hw/s390x/sclp.c| 6 ++++++1 file changed, 6 insertions(+)hw/s390x/sclp.c +5
-0@@ -277,6 +277,11 @@ int sclp_service_call_protected(S390CPU *cpu, uint64_t sccb, uint32_t code) s390_cpu_pv_mem_read(env_archcpu(env), 0, &header, sizeof(SCCBHeader)); + /* Do nothing if the header appears malformed */ + if (be16_to_cpu(header.length) < sizeof(SCCBHeader)) { + goto out_no_write; + } + work_sccb = g_malloc0(be16_to_cpu(header.length)); s390_cpu_pv_mem_read(env_archcpu(env), 0, work_sccb, be16_to_cpu(header.length));@@ -290,6 +295,7 @@ int sclp_service_call_protected(S390CPU *cpu, uint64_t sccb, uint32_t code)
out_write:
s390_cpu_pv_mem_write(env_archcpu(env), 0, work_sccb, be16_to_cpu(header.length)); +out_no_write:
sclp_c->service_interrupt(sclp, SCLP_PV_DUMMY_ADDR); return 0;
}
Re: [PATCH v3 9/9] s390x/sclp: Reject short headers in PV case
Quoted 8 lines · Christian Borntraeger
Am 24.09.26 um 16:36 schrieb Janosch Frank:
Quoted 5 lines · Eric Farman
Quoted 4 lines
An invalid length in an SCCB header correctly generates a specification exception for the regular (non-PV) codepath that processes an SCLP instruction intercept. The PV case doesn't, even though such a thing should already be sanitized. Since a short length will cause problems
...even though such a thing should already be handled by the UV.
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
later down the line with the storage that will be allocated based on that size, put up a defensive check and return if it is too short.
Cc Janosch Frank <[email protected]>Fixes c1db53a591 ("s390/sclp: read sccb from mem based on provided length")Reviewed-by Matthew Rosato <[email protected]>Signed-off-by Eric Farman <[email protected]>---
Quoted 4 lines
Quoted 1 line
How would you hit that if the architecture says FW will automatically inject a spec exception without exiting to the hypervisor if length < 8?
As I said in my review, current UV will sanitize this, so this is just defence in depth in case there would be an implementation error.
That got lost in my mailbox overflow.
Alright, then let's extend the comment and commit description before someone deletes this as dead code.
Quoted 8 lines
Quoted 8 lines
Did you witness this happening?
Am I missing something?Quoted 3 lines
hw/s390x/sclp.c | 6 ++++++ 1 file changed, 6 insertions(+)
Quoted 7 lines
Quoted 7 lines
hw/s390x/sclp.c int sclp_service_call_protected(S390CPU *cpu, uint64_t sccb, uint32_t code) · line 278
Quoted 7 lines
hw/s390x/sclp.c +1
-0@@ -277,6 +277,11 @@ int sclp_service_call_protected(S390CPU *cpu, uint64_t sccb, uint32_t code) s390_cpu_pv_mem_read(env_archcpu(env), 0, &header, sizeof(SCCBHeader)); + /* Do nothing if the header appears malformed */
... We should never end up here due to UV checks but let's be sure.
Quoted 17 lines
Quoted 16 lines
Quoted 15 lines
hw/s390x/sclp.c +5
-0+ if (be16_to_cpu(header.length) < sizeof(SCCBHeader)) { + goto out_no_write; + } + work_sccb = g_malloc0(be16_to_cpu(header.length)); s390_cpu_pv_mem_read(env_archcpu(env), 0, work_sccb, be16_to_cpu(header.length));@@ -290,6 +295,7 @@ int sclp_service_call_protected(S390CPU *cpu, uint64_t sccb, uint32_t code) out_write: s390_cpu_pv_mem_write(env_archcpu(env), 0, work_sccb, be16_to_cpu(header.length)); +out_no_write: sclp_c->service_interrupt(sclp, SCLP_PV_DUMMY_ADDR); return 0; }
Re: [PATCH v3 9/9] s390x/sclp: Reject short headers in PV case
Quoted 23 lines · Janosch Frank
Quoted 8 lines · Christian Borntraeger
Am 24.09.26 um 16:36 schrieb Janosch Frank:
Quoted 5 lines · Eric Farman
Quoted 4 lines
An invalid length in an SCCB header correctly generates a specification exception for the regular (non-PV) codepath that processes an SCLP instruction intercept. The PV case doesn't, even though such a thing should already be sanitized. Since a short length will cause problems
...even though such a thing should already be handled by the UV.
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
later down the line with the storage that will be allocated based on that size, put up a defensive check and return if it is too short.
Cc Janosch Frank <[email protected]>Fixes c1db53a591 ("s390/sclp: read sccb from mem based on provided length")Reviewed-by Matthew Rosato <[email protected]>Signed-off-by Eric Farman <[email protected]>---
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
How would you hit that if the architecture says FW will automatically inject a spec exception without exiting to the hypervisor if length < 8?
As I said in my review, current UV will sanitize this, so this is just defence in depth in case there would be an implementation error.
That got lost in my mailbox overflow.
Alright, then let's extend the comment and commit description before someone deletes this as dead code.
Works for me. I'll fold the above/below comments in when I apply.
Quoted 39 lines
Quoted 9 lines
Quoted 9 lines
Did you witness this happening?
Am I missing something?Quoted 3 lines
hw/s390x/sclp.c| 6 ++++++1 file changed, 6 insertions(+)Quoted 8 lines
Quoted 8 lines
hw/s390x/sclp.c int sclp_service_call_protected(S390CPU *cpu, · line 279
Quoted 8 lines
hw/s390x/sclp.c +1
-0@@ -277,6 +277,11 @@ int sclp_service_call_protected(S390CPU *cpu, uint64_t sccb, uint32_t code) s390_cpu_pv_mem_read(env_archcpu(env), 0, &header, sizeof(SCCBHeader)); + /* Do nothing if the header appears malformed */... We should never end up here due to UV checks but let's be sure.
Quoted 18 lines
Quoted 17 lines
Quoted 16 lines
hw/s390x/sclp.c +4
-0+ if (be16_to_cpu(header.length) < sizeof(SCCBHeader)) { + goto out_no_write; + } + work_sccb = g_malloc0(be16_to_cpu(header.length)); s390_cpu_pv_mem_read(env_archcpu(env), 0, work_sccb, be16_to_cpu(header.length));@@ -290,6 +295,7 @@ int sclp_service_call_protected(S390CPU *cpu, uint64_t sccb, uint32_t code)
out_write:
s390_cpu_pv_mem_write(env_archcpu(env), 0, work_sccb, be16_to_cpu(header.length)); +out_no_write:
sclp_c->service_interrupt(sclp, SCLP_PV_DUMMY_ADDR); return 0;
}
Quoted 28 lines · Eric Farman
A small pile of additional hardening fixes.
v2->v3:
- Collect reviews/acks (Thanks Christian, Matt!)
- [CB] Patch 7: Rename realloc variable tonew_buf
- [CB] Patch 8: Move check ofat_bytebefore check of command chaining flag
v1->v2: https://lore.kernel.org/qemu-devel/[email protected]/
- Collect reviews/acks (Thanks Matt, Christian, Tony!)
- [MR] Add fixes/stable tags to patches 1, 2, 8
- [CB, MR] Drop fixes/stable tags from patches 5, 6
- [CB] Patch 2: Unwind indicators upon re-set, instead of rejecting it
- [MR] Patch 7: Use a temporary variable ong_try_realloc()call
- [MR] Patch 8: Use CCW datastream to increment no-data countv1: https://lore.kernel.org/qemu-devel/[email protected]/
Eric Farman (9):
virtio-ccw: Limit ISC toMAX_ISC
virtio-ccw: Do not overwrite existing indicators
virtio-ccw: Fix rc check in read configuration path vfio/ap: Clear error object pointer after non-fatal errors vfio/ccw: Clear error object pointer after non-fatal errors hw/intc/s390x: Fix payload toKVM_HAS_DEVICE_ATTRioctl hw/intc/s390x: Fix check afterg_try_reallocs390x/css: Use datastream pointer for checking no-data CCWs s390x/sclp: Reject short headers in PV case
Quoted 8 lines
hw/intc/s390_flic_kvm.c | 8 +++++--- hw/s390x/css.c | 28 ++++++++++++++++++++-------- hw/s390x/sclp.c | 6 ++++++ hw/s390x/virtio-ccw.c | 29 ++++++++++++++++++++++++++++- hw/vfio/ap.c | 4 ++++ hw/vfio/ccw.c | 2 ++ 6 files changed, 65 insertions(+), 12 deletions(-)
Applied for 11.2; thank you!