target/xtensa: Assert that interrupt level is within bounds
PATCH 1/1 target/xtensa: Assert that interrupt level is within bounds
In handle_interrupt() we use level as an index into the interrupt_vector[] array. This is safe because we have checked it against env->config->nlevel, but Coverity can't see that (and it is only true because each CPU config sets its XCHAL_NUM_INTLEVELS to something less than MAX_NLEVELS), so it complains about a possible array overrun (CID 1507131)
Add an assert() which will make Coverity happy and catch the unlikely case of a mis-set XCHAL_NUM_INTLEVELS in future.
---
NB: only tested with 'make check-avocado'. You could argue that we should mark the coverity issue as false-positive instead if you like.
--- target/xtensa/exc_helper.c | 3 +++ 1 file changed, 3 insertions(+)
target/xtensa/exc_helper.c +3 -0
@@ -169,6 +169,9 @@ static void handle_interrupt(CPUXtensaState *env)CPUState *cs =env_cpu (env);if (level >1 ) { +/* env->config->nlevel check should have ensured this */ +assert (level <sizeof (env->config->interrupt_vector)); + env->sregs[EPC1 + level -1 ] = env->pc; env->sregs[EPS2 + level -2 ] = env->sregs[PS ]; env->sregs[PS] =
Signature · 1 line
2.34.1
Quoted 10 lines · Peter Maydell
In
handle_interrupt()we use level as an index into the interrupt_vector[] array. This is safe because we have checked it againstenv->config->nlevel, but Coverity can't see that (and it is only true because each CPU config sets itsXCHAL_NUM_INTLEVELSto something less thanMAX_NLEVELS), so it complains about a possible array overrun (CID 1507131)Add an
assert()which will make Coverity happy and catch the unlikely case of a mis-setXCHAL_NUM_INTLEVELSin future.
Quoted 7 lines
Signed-off-by Peter Maydell <[email protected]>---
NB: only tested with 'make check-avocado'. You could argue that we should mark the coverity issue as false-positive instead if you like.--- target/xtensa/exc_helper.c | 3 +++ 1 file changed, 3 insertions(+)
Signature · 2 lines
Thanks. -- Max
Quoted 20 lines · Max Filippov
Quoted 10 lines · Peter Maydell
In
handle_interrupt()we use level as an index into the interrupt_vector[] array. This is safe because we have checked it againstenv->config->nlevel, but Coverity can't see that (and it is only true because each CPU config sets itsXCHAL_NUM_INTLEVELSto something less thanMAX_NLEVELS), so it complains about a possible array overrun (CID 1507131)Add an
assert()which will make Coverity happy and catch the unlikely case of a mis-setXCHAL_NUM_INTLEVELSin future.Quoted 7 lines
Signed-off-by Peter Maydell <[email protected]>---
NB: only tested with 'make check-avocado'. You could argue that we should mark the coverity issue as false-positive instead if you like.--- target/xtensa/exc_helper.c | 3 +++ 1 file changed, 3 insertions(+)
Quoted 1 line
Acked-by Max Filippov <[email protected]>
Thanks. I'll take it via target-arm since I'm doing a pullreq anyway, unless you'd prefer otherwise.
-- PMM
Quoted 22 lines · Peter Maydell
Quoted 20 lines · Max Filippov
Quoted 17 lines · Peter Maydell
In
handle_interrupt()we use level as an index into the interrupt_vector[] array. This is safe because we have checked it againstenv->config->nlevel, but Coverity can't see that (and it is only true because each CPU config sets itsXCHAL_NUM_INTLEVELSto something less thanMAX_NLEVELS), so it complains about a possible array overrun (CID 1507131)Add an
assert()which will make Coverity happy and catch the unlikely case of a mis-setXCHAL_NUM_INTLEVELSin future.Signed-off-by Peter Maydell <[email protected]>---
NB: only tested with 'make check-avocado'. You could argue that we should mark the coverity issue as false-positive instead if you like.--- target/xtensa/exc_helper.c | 3 +++ 1 file changed, 3 insertions(+)
Quoted 4 lines
Quoted 1 line
Acked-by Max Filippov <[email protected]>Thanks. I'll take it via target-arm since I'm doing a pullreq anyway, unless you'd prefer otherwise.
It's good, please go ahead.
Signature · 2 lines
Thanks. -- Max