ppc/pnv: PNOR fixes
cover ppc/pnv: PNOR fixes
Hello,
Coverity found a couple of issues in the PnvPNOR model. Here are the fixes.
Thanks,
C.
Cédric Le Goater (2):
ppc/pnv: check return value of blk_pwrite() ppc/pnv: fix check on return value of blk_getlength()
include/hw/ppc/pnv_pnor.h | 2 +- hw/ppc/pnv_pnor.c | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-)
Signature · 1 line
2.21.1
PATCH 1/2 ppc/pnv: check return value of blk_pwrite()
When updating the PNOR file contents, we should check for a possible failure of blk_pwrite().
Fixes Coverity issue CID 1412228.
--- hw/ppc/pnv_pnor.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
hw/ppc/pnv_pnor.c +6 -2
@@ -33,6 +33,7 @@ static uint64_t pnv_pnor_read(void *opaque, hwaddr addr, unsigned size)static void pnv_pnor_update (PnvPnor *s,int offset,int size) {int offset_end; +int ret;if (s->blk) {return ;
@@ -42,8 +43,11 @@ static void pnv_pnor_update(PnvPnor *s, int offset, int size) offset =QEMU_ALIGN_DOWN (offset,BDRV_SECTOR_SIZE ); offset_end =QEMU_ALIGN_UP (offset_end,BDRV_SECTOR_SIZE ); -blk_pwrite (s->blk, offset, s->storage + offset, - offset_end - offset,0 ); + ret =blk_pwrite (s->blk, offset, s->storage + offset, + offset_end - offset,0 ); +if (ret <0 ) { +error_report ("Could not update PNOR: %s" ,strerror (-ret)); + } } static void pnv_pnor_write(void *opaque, hwaddr addr, uint64_t data,
Signature · 1 line
2.21.1
Re: [PATCH 1/2] ppc/pnv: check return value of blk_pwrite()
Quoted 7 lines · On Tue, 7 Jan 2020 18:18:08 +0100 Cédric Le Goater <[email protected]> wrote:
When updating the PNOR file contents, we should check for a possible failure of
blk_pwrite().Fixes Coverity issue CID 1412228.
Signed-off-by Cédric Le Goater <[email protected]>---
Quoted 29 lines
hw/ppc/pnv_pnor.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)hw/ppc/pnv_pnor.c +6
-2@@ -33,6 +33,7 @@ static uint64_t pnv_pnor_read(void *opaque, hwaddr addr, unsigned size)static void pnv_pnor_update (PnvPnor *s,int offset,int size) {int offset_end; +int ret;if (s->blk) {return ;@@ -42,8 +43,11 @@ static void pnv_pnor_update(PnvPnor *s, int offset, int size) offset =QEMU_ALIGN_DOWN (offset,BDRV_SECTOR_SIZE ); offset_end =QEMU_ALIGN_UP (offset_end,BDRV_SECTOR_SIZE ); -blk_pwrite (s->blk, offset, s->storage + offset, - offset_end - offset,0 ); + ret =blk_pwrite (s->blk, offset, s->storage + offset, + offset_end - offset,0 ); +if (ret <0 ) { +error_report ("Could not update PNOR: %s" ,strerror (-ret)); + } } static void pnv_pnor_write(void *opaque, hwaddr addr, uint64_t data,
Re: [PATCH 1/2] ppc/pnv: check return value of blk_pwrite()
In reply to Cédric Le GoaterQuoted 23 lines · Cédric Le Goater
When updating the PNOR file contents, we should check for a possible failure of
blk_pwrite().Fixes Coverity issue CID 1412228.
Signed-off-by Cédric Le Goater <[email protected]>--- hw/ppc/pnv_pnor.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)hw/ppc/pnv_pnor.c +1
-0@@ -33,6 +33,7 @@ static uint64_t pnv_pnor_read(void *opaque, hwaddr addr, unsigned size)static void pnv_pnor_update (PnvPnor *s,int offset,int size) {int offset_end; +int ret;if (s->blk) {return ;
hw/ppc/pnv_pnor.c static void pnv_pnor_update(PnvPnor *s, int offset, int size) · line 49
Quoted 9 lines
hw/ppc/pnv_pnor.c +4
-2@@ -42,8 +43,11 @@ static void pnv_pnor_update(PnvPnor *s, int offset, int size) offset =QEMU_ALIGN_DOWN (offset,BDRV_SECTOR_SIZE ); offset_end =QEMU_ALIGN_UP (offset_end,BDRV_SECTOR_SIZE ); -blk_pwrite (s->blk, offset, s->storage + offset, - offset_end - offset,0 ); + ret =blk_pwrite (s->blk, offset, s->storage + offset, + offset_end - offset,0 ); +if (ret <0 ) { +error_report ("Could not update PNOR: %s" ,strerror (-ret));
Can you report the failed offset too please?
Quoted 5 lines
hw/ppc/pnv_pnor.c +1
-0+ } } static void pnv_pnor_write(void *opaque, hwaddr addr, uint64_t data,
Re: [PATCH 1/2] ppc/pnv: check return value of blk_pwrite()
Quoted 25 lines · Philippe Mathieu-Daudé
Quoted 24 lines · Cédric Le Goater
When updating the PNOR file contents, we should check for a possible failure of
blk_pwrite().Fixes Coverity issue CID 1412228.
Signed-off-by Cédric Le Goater <[email protected]>--- hw/ppc/pnv_pnor.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)hw/ppc/pnv_pnor.c +1
-0@@ -33,6 +33,7 @@ static uint64_t pnv_pnor_read(void *opaque, hwaddr addr, unsigned size)static void pnv_pnor_update (PnvPnor *s,int offset,int size) {int offset_end; +int ret;if (s->blk) {return ;@@ -42,8 +43,11 @@ static void pnv_pnor_update(PnvPnor *s, int offset, int size) offset =QEMU_ALIGN_DOWN (offset,BDRV_SECTOR_SIZE ); offset_end =QEMU_ALIGN_UP (offset_end,BDRV_SECTOR_SIZE );
Quoted 8 lines
hw/ppc/pnv_pnor.c static void pnv_pnor_update(PnvPnor *s, int offset, int size) · line 49
Quoted 6 lines
hw/ppc/pnv_pnor.c +4
-2-blk_pwrite (s->blk, offset, s->storage + offset, - offset_end - offset,0 ); + ret =blk_pwrite (s->blk, offset, s->storage + offset, + offset_end - offset,0 ); +if (ret <0 ) { +error_report ("Could not update PNOR: %s" ,strerror (-ret));Can you report the failed offset too please?
Since this fixes a coverity warning, I'm applying now, and extending the error message can be a followup.
Quoted 8 lines
Reviewed-by Philippe Mathieu-Daudé <[email protected]>Quoted 4 lines
hw/ppc/pnv_pnor.c +1
-0+ } } static void pnv_pnor_write(void *opaque, hwaddr addr, uint64_t data,
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
PATCH 2/2 ppc/pnv: fix check on return value of blk_getlength()
In reply to Cédric Le Goaterblk_getlength() returns an int64_t but the result is stored in a uint32_t. Errors (negative values) won't be caught by the check in pnv_pnor_realize() and blk_blockalign() will allocate a very large buffer in such cases.
Fixes Coverity issue CID 1412226.
--- include/hw/ppc/pnv_pnor.h | 2 +- hw/ppc/pnv_pnor.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
include/hw/ppc/pnv_pnor.h +1 -1
@@ -23,7 +23,7 @@ typedef struct PnvPnor {BlockBackend *blk;uint8_t *storage; -uint32_t size; +int64_t size;MemoryRegion mmio; } PnvPnor;
hw/ppc/pnv_pnor.c +1 -1
@@ -111,7 +111,7 @@ static void pnv_pnor_realize(DeviceState *dev, Error **errp) }static Property pnv_pnor_properties[] = { -DEFINE_PROP_UINT32 ("size" , PnvPnor, size,128 <<20 ), +DEFINE_PROP_INT64 ("size" , PnvPnor, size,128 <<20 ),DEFINE_PROP_DRIVE ("drive" , PnvPnor, blk),DEFINE_PROP_END_OF_LIST (), };
Signature · 1 line
2.21.1
Re: [PATCH 2/2] ppc/pnv: fix check on return value of blk_getlength()
Quoted 9 lines · On Tue, 7 Jan 2020 18:18:09 +0100 Cédric Le Goater <[email protected]> wrote:
blk_getlength()returns anint64_tbut the result is stored in auint32_t. Errors (negative values) won't be caught by the check inpnv_pnor_realize()andblk_blockalign()will allocate a very large buffer in such cases.Fixes Coverity issue CID 1412226.
Signed-off-by Cédric Le Goater <[email protected]>---
Quoted 30 lines
include/hw/ppc/pnv_pnor.h | 2 +- hw/ppc/pnv_pnor.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)include/hw/ppc/pnv_pnor.h +1
-1@@ -23,7 +23,7 @@ typedef struct PnvPnor {BlockBackend *blk;uint8_t *storage; -uint32_t size; +int64_t size;MemoryRegion mmio; } PnvPnor;hw/ppc/pnv_pnor.c +1
-1@@ -111,7 +111,7 @@ static void pnv_pnor_realize(DeviceState *dev, Error **errp) }static Property pnv_pnor_properties[] = { -DEFINE_PROP_UINT32 ("size" , PnvPnor, size,128 <<20 ), +DEFINE_PROP_INT64 ("size" , PnvPnor, size,128 <<20 ),DEFINE_PROP_DRIVE ("drive" , PnvPnor, blk),DEFINE_PROP_END_OF_LIST (), };
Re: [PATCH 2/2] ppc/pnv: fix check on return value of blk_getlength()
In reply to Cédric Le GoaterQuoted 31 lines · Cédric Le Goater
blk_getlength()returns anint64_tbut the result is stored in auint32_t. Errors (negative values) won't be caught by the check inpnv_pnor_realize()andblk_blockalign()will allocate a very large buffer in such cases.Fixes Coverity issue CID 1412226.
Signed-off-by Cédric Le Goater <[email protected]>--- include/hw/ppc/pnv_pnor.h | 2 +- hw/ppc/pnv_pnor.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)include/hw/ppc/pnv_pnor.h +1
-1@@ -23,7 +23,7 @@ typedef struct PnvPnor {BlockBackend *blk;uint8_t *storage; -uint32_t size; +int64_t size;MemoryRegion mmio; } PnvPnor;hw/ppc/pnv_pnor.c +0
-0
hw/ppc/pnv_pnor.c static void pnv_pnor_realize(DeviceState *dev, Error **errp) · line 114
Quoted 5 lines
hw/ppc/pnv_pnor.c +1
-1@@ -111,7 +111,7 @@ static void pnv_pnor_realize(DeviceState *dev, Error **errp) }static Property pnv_pnor_properties[] = { -DEFINE_PROP_UINT32 ("size" , PnvPnor, size,128 <<20 ), +DEFINE_PROP_INT64 ("size" , PnvPnor, size,128 <<20 ),
If you respin the series please consider using '128 * MiB' here.
Quoted 4 lines
hw/ppc/pnv_pnor.c +0
-0DEFINE_PROP_DRIVE ("drive" , PnvPnor, blk), DEFINE_PROP_END_OF_LIST(), };
David Gibson
AppliedRe: [PATCH 2/2] ppc/pnv: fix check on return value of blk_getlength()
In reply to Cédric Le GoaterQuoted 8 lines · Cédric Le Goater
blk_getlength()returns anint64_tbut the result is stored in auint32_t. Errors (negative values) won't be caught by the check inpnv_pnor_realize()andblk_blockalign()will allocate a very large buffer in such cases.Fixes Coverity issue CID 1412226.
Signed-off-by Cédric Le Goater <[email protected]>
Applied to ppc-for-5.0.
Quoted 31 lines
--- include/hw/ppc/pnv_pnor.h | 2 +- hw/ppc/pnv_pnor.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)include/hw/ppc/pnv_pnor.h +1
-1@@ -23,7 +23,7 @@ typedef struct PnvPnor {BlockBackend *blk;uint8_t *storage; -uint32_t size; +int64_t size;MemoryRegion mmio; } PnvPnor;hw/ppc/pnv_pnor.c +1
-1@@ -111,7 +111,7 @@ static void pnv_pnor_realize(DeviceState *dev, Error **errp) }static Property pnv_pnor_properties[] = { -DEFINE_PROP_UINT32 ("size" , PnvPnor, size,128 <<20 ), +DEFINE_PROP_INT64 ("size" , PnvPnor, size,128 <<20 ),DEFINE_PROP_DRIVE ("drive" , PnvPnor, blk),DEFINE_PROP_END_OF_LIST (), };
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson