ppc405_uc: Fix buffer overflow
PATCH 1/1 ppc405_uc: Fix buffer overflow
Report from smatch:
ppc405_uc.c:209 dcr_read_pob(12) error: buffer overflow 'pob->besr' 2 <= 2 ppc405_uc.c:232 dcr_write_pob(12) error: buffer overflow 'pob->besr' 2 <= 2
The old code reads and writes besr[POB0_BESR1 - POB0_BESR0] or besr[2] which is one too much.
---
As this code was wrong for more than 5 years, there is no urgent need to fix it now for QEMU 1.2.
Regards,
Stefan Weil
hw/ppc405_uc.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
hw/ppc405_uc.c +11 -5
@@ -191,7 +191,8 @@ enum {typedef struct ppc4xx_pob_t ppc4xx_pob_t ;struct ppc4xx_pob_t {uint32_t bear; -uint32_t besr[2 ]; +uint32_t besr0; +uint32_t besr1; };static uint32_t dcr_read_pob (void *opaque,int dcrn)
@@ -205,8 +206,10 @@ static uint32_t dcr_read_pob (void *opaque, int dcrn) ret = pob->bear;break ;case POB0_BESR0 : + ret = pob->besr0; +break ;case POB0_BESR1 : - ret = pob->besr[dcrn -POB0_BESR0 ]; + ret = pob->besr1;break ;default :/* Avoid gcc warning */
@@ -227,9 +230,12 @@ static void dcr_write_pob (void *opaque, int dcrn, uint32_t val)/* Read only */ break ;case POB0_BESR0 : +/* Write-clear */ + pob->besr0 &= ~val; +break ;case POB0_BESR1 :/* Write-clear */ - pob->besr[dcrn -POB0_BESR0 ] &= ~val; + pob->besr1 &= ~val;break ; } }
@@ -241,8 +247,8 @@ static void ppc4xx_pob_reset (void *opaque) pob = opaque;/* No error */ pob->bear =0x00000000 ; - pob->besr[0 ] =0x0000000 ; - pob->besr[1 ] =0x0000000 ; + pob->besr0 =0x0000000 ; + pob->besr1 =0x0000000 ; }static void ppc4xx_pob_init (CPUPPCState *env)
Signature · 1 line
1.7.10
Am 31.08.2012 22:21, schrieb Stefan Weil:
Quoted 26 lines
Report from smatch:
ppc405_uc.c:209
dcr_read_pob(12)error: buffer overflow 'pob->besr' 2 <= 2 ppc405_uc.c:232dcr_write_pob(12)error: buffer overflow 'pob->besr' 2 <= 2The old code reads and writes besr[POB0_BESR1 -
POB0_BESR0] or besr[2] which is one too much.Signed-off-by Stefan Weil <[email protected]>---
As this code was wrong for more than 5 years, there is no urgent need to fix it now for QEMU 1.2.
Regards,
Stefan Weil
hw/ppc405_uc.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)hw/ppc405_uc.c +0
-0
hw/ppc405_uc.c enum { · line 198
Quoted 9 lines
hw/ppc405_uc.c +2
-1@@ -191,7 +191,8 @@ enum {typedef struct ppc4xx_pob_t ppc4xx_pob_t ;struct ppc4xx_pob_t {uint32_t bear; -uint32_t besr[2 ]; +uint32_t besr0; +uint32_t besr1; };static uint32_t dcr_read_pob (void *opaque,int dcrn)
We could alternatively leave besr[2] and access it with hardcoded 0..1.
Adding qemu-stable to the mix so it can be backported to stable-1.2 after the release.
Andreas
Quoted 38 lines
hw/ppc405_uc.c +9
-4@@ -205,8 +206,10 @@ static uint32_t dcr_read_pob (void *opaque, int dcrn) ret = pob->bear;break ;case POB0_BESR0 : + ret = pob->besr0; +break ;case POB0_BESR1 : - ret = pob->besr[dcrn -POB0_BESR0 ]; + ret = pob->besr1;break ;default :/* Avoid gcc warning */ @@ -227,9 +230,12 @@ static void dcr_write_pob (void *opaque, int dcrn, uint32_t val)/* Read only */ break ;case POB0_BESR0 : +/* Write-clear */ + pob->besr0 &= ~val; +break ;case POB0_BESR1 :/* Write-clear */ - pob->besr[dcrn -POB0_BESR0 ] &= ~val; + pob->besr1 &= ~val;break ; } }@@ -241,8 +247,8 @@ static void ppc4xx_pob_reset (void *opaque) pob = opaque;/* No error */ pob->bear =0x00000000 ; - pob->besr[0 ] =0x0000000 ; - pob->besr[1 ] =0x0000000 ; + pob->besr0 =0x0000000 ; + pob->besr1 =0x0000000 ; }static void ppc4xx_pob_init (CPUPPCState *env)
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Quoted 35 lines · Andreas Färber
Am 31.08.2012 22:21, schrieb Stefan Weil:
Quoted 34 lines
Report from smatch:
ppc405_uc.c:209
dcr_read_pob(12)error: buffer overflow 'pob->besr' 2 <= 2 ppc405_uc.c:232dcr_write_pob(12)error: buffer overflow 'pob->besr' 2 <= 2The old code reads and writes besr[POB0_BESR1 -
POB0_BESR0] or besr[2] which is one too much.Signed-off-by Stefan Weil <[email protected]>---
As this code was wrong for more than 5 years, there is no urgent need to fix it now for QEMU 1.2.
Regards,
Stefan Weil
hw/ppc405_uc.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)hw/ppc405_uc.c +2
-1@@ -191,7 +191,8 @@ enum {typedef struct ppc4xx_pob_t ppc4xx_pob_t ;struct ppc4xx_pob_t {uint32_t bear; -uint32_t besr[2 ]; +uint32_t besr0; +uint32_t besr1; };
Quoted 5 lines
hw/ppc405_uc.c enum { · line 198
Quoted 1 line
hw/ppc405_uc.c +0
-0static uint32_t dcr_read_pob (void *opaque,int dcrn)Reviewed-by Andreas Färber <[email protected]>We could alternatively leave besr[2] and access it with hardcoded 0..1.
Minimally invasive fix would be besr[dcrn != POB0_BESR0].
[...]
Quoted 41 lines · Markus Armbruster
Quoted 39 lines · Andreas Färber
Am 31.08.2012 22:21, schrieb Stefan Weil:
Quoted 26 lines
Report from smatch:
ppc405_uc.c:209
dcr_read_pob(12)error: buffer overflow 'pob->besr' 2 <= 2 ppc405_uc.c:232dcr_write_pob(12)error: buffer overflow 'pob->besr' 2 <= 2The old code reads and writes besr[POB0_BESR1 -
POB0_BESR0] or besr[2] which is one too much.Signed-off-by Stefan Weil <[email protected]>---
As this code was wrong for more than 5 years, there is no urgent need to fix it now for QEMU 1.2.
Regards,
Stefan Weil
hw/ppc405_uc.c| 16 +++++++++++-----1 file changed, 11 insertions(+), 5 deletions(-)hw/ppc405_uc.c +0
-0hw/ppc405_uc.c enum { · line 198
Quoted 9 lines
hw/ppc405_uc.c +2
-1@@ -191,7 +191,8 @@ enum {typedef struct ppc4xx_pob_t ppc4xx_pob_t ;struct ppc4xx_pob_t {uint32_t bear; -uint32_t besr[2 ]; +uint32_t besr0; +uint32_t besr1; };static uint32_t dcr_read_pob (void *opaque,int dcrn)Reviewed-by Andreas Färber <[email protected]>
Quoted 5 lines
Quoted 1 line
We could alternatively leave besr[2] and access it with hardcoded 0..1.
Minimally invasive fix would be besr[dcrn !=
POB0_BESR0].[...]
I don't think the change is important enough for these stylistic questions :). I'll just apply it once I'm back to a real internet connection.
Alex
Am 01.09.2012 08:23, schrieb Alexander Graf:
Quoted 6 lines · Markus Armbruster
Quoted 3 lines
Andreas Färber <[email protected]> writes:
staticuint32_tdcr_read_pob(void *opaque, int dcrn)
...
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Reviewed-by Andreas Färber <[email protected]>We could alternatively leave besr[2] and access it with hardcoded 0..1.
Quoted 7 lines
Quoted 3 lines
Minimally invasive fix would be besr[dcrn !=
POB0_BESR0].[...]
I don't think the change is important enough for these stylistic questions :). I'll just apply it once I'm back to a real internet connection.
Alex
Of course I considered those minimally invasive solutions.
There was already other code in the same file which used besr0, besr1, and the wrong statements were simple enough to justify a duplication. If I were a compiler, I'd generate smaller and faster code with the new code :-)
Cheers,
Stefan W.
Alexander Graf
AppliedQuoted 9 lines · Stefan Weil
Report from smatch:
ppc405_uc.c:209
dcr_read_pob(12)error: buffer overflow 'pob->besr' 2 <= 2 ppc405_uc.c:232dcr_write_pob(12)error: buffer overflow 'pob->besr' 2 <= 2The old code reads and writes besr[POB0_BESR1 -
POB0_BESR0] or besr[2] which is one too much.Signed-off-by Stefan Weil <[email protected]>
Thanks, applied to ppc-next.
Alex