From b11833cbba5b74f578d72f2d909fe8e12f4e8ef7 Mon Sep 17 00:00:00 2001 From: "chao.an" Date: Wed, 15 Dec 2021 19:40:52 +0800 Subject: [PATCH] arch/assert: flush the syslog before stack dump flush the syslog before stack dump to avoid buffer overwrite Signed-off-by: chao.an --- arch/arm/src/arm/arm_assert.c | 4 ++++ arch/arm/src/armv6-m/arm_assert.c | 4 ++++ arch/arm/src/armv7-a/arm_assert.c | 4 ++++ arch/arm/src/armv7-m/arm_assert.c | 4 ++++ arch/arm/src/armv7-r/arm_assert.c | 4 ++++ arch/arm/src/armv8-m/arm_assert.c | 4 ++++ arch/avr/src/avr/up_dumpstate.c | 7 ++++++- arch/avr/src/avr32/up_dumpstate.c | 5 +++++ arch/hc/src/m9s12/m9s12_assert.c | 6 +++++- arch/mips/src/mips32/mips_dumpstate.c | 5 +++++ arch/misoc/src/lm32/lm32_dumpstate.c | 5 +++++ arch/misoc/src/minerva/minerva_dumpstate.c | 5 +++++ arch/or1k/src/common/up_assert.c | 5 +++++ arch/renesas/src/m16c/m16c_dumpstate.c | 7 ++++++- arch/renesas/src/rx65n/rx65n_dumpstate.c | 7 ++++++- arch/renesas/src/sh1/sh1_dumpstate.c | 7 ++++++- arch/risc-v/src/rv32im/riscv_assert.c | 6 +++++- arch/risc-v/src/rv64gc/riscv_assert.c | 4 ++++ arch/x86/src/common/up_assert.c | 4 ++++ arch/x86_64/src/common/up_assert.c | 4 ++++ arch/xtensa/src/common/xtensa_dumpstate.c | 7 ++++++- arch/z16/src/common/z16_stackdump.c | 7 ++++++- 22 files changed, 107 insertions(+), 8 deletions(-) diff --git a/arch/arm/src/arm/arm_assert.c b/arch/arm/src/arm/arm_assert.c index e2be7da0e1..e21c617228 100644 --- a/arch/arm/src/arm/arm_assert.c +++ b/arch/arm/src/arm/arm_assert.c @@ -77,6 +77,10 @@ static void up_stackdump(uint32_t sp, uint32_t stack_top) { uint32_t stack; + /* Flush any buffered SYSLOG data to avoid overwrite */ + + syslog_flush(); + for (stack = sp & ~0x1f; stack < (stack_top & ~0x1f); stack += 32) { uint32_t *ptr = (uint32_t *)stack; diff --git a/arch/arm/src/armv6-m/arm_assert.c b/arch/arm/src/armv6-m/arm_assert.c index 547ad5da8c..e8719bc709 100644 --- a/arch/arm/src/armv6-m/arm_assert.c +++ b/arch/arm/src/armv6-m/arm_assert.c @@ -76,6 +76,10 @@ static void up_stackdump(uint32_t sp, uint32_t stack_top) { uint32_t stack; + /* Flush any buffered SYSLOG data to avoid overwrite */ + + syslog_flush(); + for (stack = sp & ~0x1f; stack < (stack_top & ~0x1f); stack += 32) { uint32_t *ptr = (uint32_t *)stack; diff --git a/arch/arm/src/armv7-a/arm_assert.c b/arch/arm/src/armv7-a/arm_assert.c index 67bd0de0be..09005b44b5 100644 --- a/arch/arm/src/armv7-a/arm_assert.c +++ b/arch/arm/src/armv7-a/arm_assert.c @@ -79,6 +79,10 @@ static void up_stackdump(uint32_t sp, uint32_t stack_top) { uint32_t stack; + /* Flush any buffered SYSLOG data to avoid overwrite */ + + syslog_flush(); + for (stack = sp & ~0x1f; stack < (stack_top & ~0x1f); stack += 32) { uint32_t *ptr = (uint32_t *)stack; diff --git a/arch/arm/src/armv7-m/arm_assert.c b/arch/arm/src/armv7-m/arm_assert.c index f0318ecdaf..8ece0217c3 100644 --- a/arch/arm/src/armv7-m/arm_assert.c +++ b/arch/arm/src/armv7-m/arm_assert.c @@ -79,6 +79,10 @@ static void up_stackdump(uint32_t sp, uint32_t stack_top) { uint32_t stack; + /* Flush any buffered SYSLOG data to avoid overwrite */ + + syslog_flush(); + for (stack = sp & ~0x1f; stack < (stack_top & ~0x1f); stack += 32) { uint32_t *ptr = (uint32_t *)stack; diff --git a/arch/arm/src/armv7-r/arm_assert.c b/arch/arm/src/armv7-r/arm_assert.c index 05b1d7a72a..aa3668fb25 100644 --- a/arch/arm/src/armv7-r/arm_assert.c +++ b/arch/arm/src/armv7-r/arm_assert.c @@ -76,6 +76,10 @@ static void up_stackdump(uint32_t sp, uint32_t stack_top) { uint32_t stack; + /* Flush any buffered SYSLOG data to avoid overwrite */ + + syslog_flush(); + for (stack = sp & ~0x1f; stack < (stack_top & ~0x1f); stack += 32) { uint32_t *ptr = (uint32_t *)stack; diff --git a/arch/arm/src/armv8-m/arm_assert.c b/arch/arm/src/armv8-m/arm_assert.c index 30ef42d220..726d94d034 100644 --- a/arch/arm/src/armv8-m/arm_assert.c +++ b/arch/arm/src/armv8-m/arm_assert.c @@ -79,6 +79,10 @@ static void up_stackdump(uint32_t sp, uint32_t stack_top) { uint32_t stack; + /* Flush any buffered SYSLOG data to avoid overwrite */ + + syslog_flush(); + for (stack = sp & ~0x1f; stack < (stack_top & ~0x1f); stack += 32) { uint32_t *ptr = (uint32_t *)stack; diff --git a/arch/avr/src/avr/up_dumpstate.c b/arch/avr/src/avr/up_dumpstate.c index aac8edd330..69273fb903 100644 --- a/arch/avr/src/avr/up_dumpstate.c +++ b/arch/avr/src/avr/up_dumpstate.c @@ -31,6 +31,7 @@ #include #include +#include #include #include "up_arch.h" @@ -51,7 +52,11 @@ static void up_stackdump(uint16_t sp, uint16_t stack_top) { uint16_t stack; - for (stack = sp & ~3; stack < (stack_top & ~0x1f); stack += 12) + /* Flush any buffered SYSLOG data to avoid overwrite */ + + syslog_flush(); + + for (stack = sp & ~0x3; stack < (stack_top & ~0x3); stack += 12) { uint8_t *ptr = (uint8_t *)stack; _alert("%04x: %02x %02x %02x %02x %02x %02x %02x %02x" diff --git a/arch/avr/src/avr32/up_dumpstate.c b/arch/avr/src/avr32/up_dumpstate.c index 3384a85226..ace3b8fb61 100644 --- a/arch/avr/src/avr32/up_dumpstate.c +++ b/arch/avr/src/avr32/up_dumpstate.c @@ -31,6 +31,7 @@ #include #include +#include #include #include "up_arch.h" @@ -51,6 +52,10 @@ static void up_stackdump(uint32_t sp, uint32_t stack_top) { uint32_t stack; + /* Flush any buffered SYSLOG data to avoid overwrite */ + + syslog_flush(); + for (stack = sp & ~0x1f; stack < (stack_top & ~0x1f); stack += 32) { uint32_t *ptr = (uint32_t *)stack; diff --git a/arch/hc/src/m9s12/m9s12_assert.c b/arch/hc/src/m9s12/m9s12_assert.c index 02b25319c2..66829f226f 100644 --- a/arch/hc/src/m9s12/m9s12_assert.c +++ b/arch/hc/src/m9s12/m9s12_assert.c @@ -76,7 +76,11 @@ static void up_stackdump(uint16_t sp, uint16_t stack_top) { uint16_t stack; - for (stack = sp; stack < (stack_top & ~0x1f); stack += 16) + /* Flush any buffered SYSLOG data to avoid overwrite */ + + syslog_flush(); + + for (stack = sp & ~0x1f; stack < (stack_top & ~0x1f); stack += 16) { uint8_t *ptr = (uint8_t *)stack; diff --git a/arch/mips/src/mips32/mips_dumpstate.c b/arch/mips/src/mips32/mips_dumpstate.c index 07bec6354f..2eab5fff14 100644 --- a/arch/mips/src/mips32/mips_dumpstate.c +++ b/arch/mips/src/mips32/mips_dumpstate.c @@ -32,6 +32,7 @@ #include #include +#include #include #include "mips_arch.h" @@ -52,6 +53,10 @@ static void up_stackdump(uint32_t sp, uint32_t stack_top) { uint32_t stack; + /* Flush any buffered SYSLOG data to avoid overwrite */ + + syslog_flush(); + for (stack = sp & ~0x1f; stack < (stack_top & ~0x1f); stack += 32) { uint32_t *ptr = (uint32_t *)stack; diff --git a/arch/misoc/src/lm32/lm32_dumpstate.c b/arch/misoc/src/lm32/lm32_dumpstate.c index ec69734244..de704c6a75 100644 --- a/arch/misoc/src/lm32/lm32_dumpstate.c +++ b/arch/misoc/src/lm32/lm32_dumpstate.c @@ -31,6 +31,7 @@ #include #include +#include #include #include "sched/sched.h" @@ -50,6 +51,10 @@ static void up_stackdump(uint32_t sp, uint32_t stack_top) { uint32_t stack; + /* Flush any buffered SYSLOG data to avoid overwrite */ + + syslog_flush(); + for (stack = sp & ~0x1f; stack < (stack_top & ~0x1f); stack += 32) { uint32_t *ptr = (uint32_t *)stack; diff --git a/arch/misoc/src/minerva/minerva_dumpstate.c b/arch/misoc/src/minerva/minerva_dumpstate.c index d3fd061456..7be48d3036 100644 --- a/arch/misoc/src/minerva/minerva_dumpstate.c +++ b/arch/misoc/src/minerva/minerva_dumpstate.c @@ -31,6 +31,7 @@ #include #include +#include #include #include "sched/sched.h" @@ -50,6 +51,10 @@ static void up_stackdump(uint32_t sp, uint32_t stack_top) { uint32_t stack; + /* Flush any buffered SYSLOG data to avoid overwrite */ + + syslog_flush(); + for (stack = sp & ~0x1f; stack < (stack_top & ~0x1f); stack += 32) { uint32_t *ptr = (uint32_t *) stack; diff --git a/arch/or1k/src/common/up_assert.c b/arch/or1k/src/common/up_assert.c index 0b239279f7..6f0e4f1166 100644 --- a/arch/or1k/src/common/up_assert.c +++ b/arch/or1k/src/common/up_assert.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -75,6 +76,10 @@ static void up_stackdump(uint32_t sp, uint32_t stack_top) { uint32_t stack; + /* Flush any buffered SYSLOG data to avoid overwrite */ + + syslog_flush(); + for (stack = sp & ~0x1f; stack < (stack_top & ~0x1f); stack += 32) { uint32_t *ptr = (uint32_t *)stack; diff --git a/arch/renesas/src/m16c/m16c_dumpstate.c b/arch/renesas/src/m16c/m16c_dumpstate.c index 9ef1a5f751..1a873ab9fa 100644 --- a/arch/renesas/src/m16c/m16c_dumpstate.c +++ b/arch/renesas/src/m16c/m16c_dumpstate.c @@ -29,6 +29,7 @@ #include #include +#include #include "up_arch.h" #include "up_internal.h" @@ -67,7 +68,11 @@ static void m16c_stackdump(uint16_t sp, uint16_t stack_top) { uint16_t stack; - for (stack = sp & ~7; stack < stack_top; stack += 8) + /* Flush any buffered SYSLOG data to avoid overwrite */ + + syslog_flush(); + + for (stack = sp & ~7; stack < (stack_top & ~7); stack += 8) { uint8_t *ptr = (uint8_t *)stack; _alert("%04x: %02x %02x %02x %02x %02x %02x %02x %02x\n", diff --git a/arch/renesas/src/rx65n/rx65n_dumpstate.c b/arch/renesas/src/rx65n/rx65n_dumpstate.c index 5f8a0c36a9..9b838e986e 100644 --- a/arch/renesas/src/rx65n/rx65n_dumpstate.c +++ b/arch/renesas/src/rx65n/rx65n_dumpstate.c @@ -30,6 +30,7 @@ #include #include +#include #include "up_arch.h" #include "up_internal.h" @@ -69,7 +70,11 @@ static void rx65n_stackdump(uint16_t sp, uint16_t stack_top) { uint16_t stack; - for (stack = sp & ~7; stack < stack_top; stack += 8) /* check */ + /* Flush any buffered SYSLOG data to avoid overwrite */ + + syslog_flush(); + + for (stack = sp & ~7; stack < (stack_top & ~7); stack += 8) /* check */ { uint8_t *ptr = (uint8_t *)&stack; diff --git a/arch/renesas/src/sh1/sh1_dumpstate.c b/arch/renesas/src/sh1/sh1_dumpstate.c index 1989fd59e8..26259af23a 100644 --- a/arch/renesas/src/sh1/sh1_dumpstate.c +++ b/arch/renesas/src/sh1/sh1_dumpstate.c @@ -29,6 +29,7 @@ #include #include +#include #include "up_arch.h" #include "up_internal.h" @@ -54,7 +55,11 @@ static void sh1_stackdump(uint32_t sp, uint32_t stack_top) { uint32_t stack; - for (stack = sp & ~0x1f; stack < stack_top; stack += 32) + /* Flush any buffered SYSLOG data to avoid overwrite */ + + syslog_flush(); + + for (stack = sp & ~0x1f; stack < (stack_top & ~0x1f); stack += 32) { uint32_t *ptr = (uint32_t *)stack; _alert("%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n", diff --git a/arch/risc-v/src/rv32im/riscv_assert.c b/arch/risc-v/src/rv32im/riscv_assert.c index 686f307006..4261f099bc 100644 --- a/arch/risc-v/src/rv32im/riscv_assert.c +++ b/arch/risc-v/src/rv32im/riscv_assert.c @@ -72,7 +72,11 @@ static void riscv_stackdump(uint32_t sp, uint32_t stack_top) { uint32_t stack; - for (stack = sp & ~0x1f; stack < stack_top; stack += 32) + /* Flush any buffered SYSLOG data to avoid overwrite */ + + syslog_flush(); + + for (stack = sp & ~0x1f; stack < (stack_top & ~0x1f); stack += 32) { uint32_t *ptr = (uint32_t *)stack; _alert("%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n", diff --git a/arch/risc-v/src/rv64gc/riscv_assert.c b/arch/risc-v/src/rv64gc/riscv_assert.c index f337a4fdb4..fffab713ae 100644 --- a/arch/risc-v/src/rv64gc/riscv_assert.c +++ b/arch/risc-v/src/rv64gc/riscv_assert.c @@ -75,6 +75,10 @@ static void up_stackdump(uint64_t sp, uintptr_t stack_top) { uintptr_t stack; + /* Flush any buffered SYSLOG data to avoid overwrite */ + + syslog_flush(); + for (stack = sp & ~0x1f; stack < (stack_top & ~0x1f); stack += 32) { uint32_t *ptr = (uint32_t *)stack; diff --git a/arch/x86/src/common/up_assert.c b/arch/x86/src/common/up_assert.c index 18ddacca6d..5f73f526a4 100644 --- a/arch/x86/src/common/up_assert.c +++ b/arch/x86/src/common/up_assert.c @@ -77,6 +77,10 @@ static void up_stackdump(uint32_t sp, uint32_t stack_top) { uint32_t stack; + /* Flush any buffered SYSLOG data to avoid overwrite */ + + syslog_flush(); + for (stack = sp & ~0x1f; stack < (stack_top & ~0x1f); stack += 32) { uint32_t *ptr = (uint32_t *)stack; diff --git a/arch/x86_64/src/common/up_assert.c b/arch/x86_64/src/common/up_assert.c index eebca3e34a..0114cd65a8 100644 --- a/arch/x86_64/src/common/up_assert.c +++ b/arch/x86_64/src/common/up_assert.c @@ -69,6 +69,10 @@ static void up_stackdump(uint64_t sp, uint64_t stack_top) { uint64_t stack; + /* Flush any buffered SYSLOG data to avoid overwrite */ + + syslog_flush(); + for (stack = sp & ~0x1f; stack < (stack_top & ~0x1f); stack += 32) { uint32_t *ptr = (uint32_t *)stack; diff --git a/arch/xtensa/src/common/xtensa_dumpstate.c b/arch/xtensa/src/common/xtensa_dumpstate.c index 7a8d7e17ac..52aad0729b 100644 --- a/arch/xtensa/src/common/xtensa_dumpstate.c +++ b/arch/xtensa/src/common/xtensa_dumpstate.c @@ -31,6 +31,7 @@ #include #include +#include #include #include @@ -102,7 +103,11 @@ static void xtensa_stackdump(uint32_t sp, uint32_t stack_top) { uint32_t stack; - for (stack = sp & ~0x1f; stack < stack_top; stack += 32) + /* Flush any buffered SYSLOG data to avoid overwrite */ + + syslog_flush(); + + for (stack = sp & ~0x1f; stack < (stack_top & ~0x1f); stack += 32) { uint32_t *ptr = (uint32_t *)stack; _alert("%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n", diff --git a/arch/z16/src/common/z16_stackdump.c b/arch/z16/src/common/z16_stackdump.c index ad35189173..5c0d6d6516 100644 --- a/arch/z16/src/common/z16_stackdump.c +++ b/arch/z16/src/common/z16_stackdump.c @@ -23,6 +23,7 @@ ****************************************************************************/ #include +#include #include @@ -68,8 +69,12 @@ static void z16_stackdump(void) stack = stack_base; } + /* Flush any buffered SYSLOG data to avoid overwrite */ + + syslog_flush(); + for (stack = stack & ~0x0f; - stack < stack_base + stack_size; + stack < ((stack_base + stack_size) & ~0x0f); stack += 8 * sizeof(chipreg_t)) { chipreg_t *ptr = (chipreg_t *)stack;