checkstack: fix access overflow when checkstack

We should check length first, and then check the value

Signed-off-by: ligd <liguiding1@xiaomi.com>
This commit is contained in:
ligd
2025-09-11 18:28:57 +08:00
committed by Alan C. Assis
parent 3c6cb0b76e
commit 113bb02568
11 changed files with 11 additions and 11 deletions
+1 -1
View File
@@ -119,7 +119,7 @@ size_t arm_stack_check(void *stackbase, size_t nbytes)
*/
for (ptr = (uint32_t *)start, mark = (nbytes >> 2);
*ptr == STACK_COLOR && mark > 0;
mark > 0 && *ptr == STACK_COLOR;
ptr++, mark--);
/* If the stack is completely used, then this might mean that the stack
+1 -1
View File
@@ -101,7 +101,7 @@ size_t arm64_stack_check(void *stackbase, size_t nbytes)
*/
for (ptr = (uint32_t *)start, mark = (nbytes >> 2);
*ptr == STACK_COLOR && mark > 0;
mark > 0 && *ptr == STACK_COLOR;
ptr++, mark--);
/* If the stack is completely used, then this might mean that the stack
+1 -1
View File
@@ -108,7 +108,7 @@ size_t avr_stack_check(uintptr_t alloc, size_t size)
*/
for (ptr = (FAR uint8_t *)alloc, mark = size;
*ptr == STACK_COLOR && mark > 0;
mark > 0 && *ptr == STACK_COLOR;
ptr++, mark--);
/* If the stack is completely used, then this might mean that the stack
+1 -1
View File
@@ -100,7 +100,7 @@ size_t ceva_stack_check(uintptr_t alloc, size_t size)
*/
for (ptr = (uint32_t *)alloc, mark = nwords;
*ptr == STACK_COLOR && mark > 0;
mark > 0 && *ptr == STACK_COLOR;
ptr++, mark--);
/* If the stack is completely used, then this might mean that the stack
+1 -1
View File
@@ -115,7 +115,7 @@ size_t or1k_stack_check(uintptr_t alloc, size_t size)
size = end - start;
for (ptr = (uint32_t *)start, mark = (size >> 2);
*ptr == STACK_COLOR && mark > 0;
mark > 0 && *ptr == STACK_COLOR;
ptr++, mark--);
/* Return our guess about how much stack space was used */
+1 -1
View File
@@ -117,7 +117,7 @@ size_t riscv_stack_check(uintptr_t alloc, size_t size)
*/
for (ptr = (uint32_t *)start, mark = (size >> 2);
*ptr == STACK_COLOR && mark > 0;
mark > 0 && *ptr == STACK_COLOR;
ptr++, mark--);
/* If the stack is completely used, then this might mean that the stack
+1 -1
View File
@@ -91,7 +91,7 @@ size_t sim_stack_check(void *alloc, size_t size)
*/
for (ptr = (uint32_t *)start, mark = (size >> 2);
*ptr == STACK_COLOR && mark > 0;
mark > 0 && *ptr == STACK_COLOR;
ptr++, mark--);
/* If the stack is completely used, then this might mean that the stack
+1 -1
View File
@@ -115,7 +115,7 @@ size_t sparc_stack_check(void *stackbase, size_t nbytes)
*/
for (ptr = (uint32_t *)start, mark = (nbytes >> 2);
*ptr == STACK_COLOR && mark > 0;
mark > 0 && *ptr == STACK_COLOR;
ptr++, mark--);
/* If the stack is completely used, then this might mean that the stack
+1 -1
View File
@@ -93,7 +93,7 @@ size_t tricore_stack_check(uintptr_t alloc, size_t size)
*/
for (ptr = (uint32_t *)start, mark = (size >> 2);
*ptr == STACK_COLOR && mark > 0;
mark > 0 && *ptr == STACK_COLOR;
ptr++, mark--);
/* Return our guess about how much stack space was used */
+1 -1
View File
@@ -86,7 +86,7 @@ size_t x86_64_stack_check(void *stackbase, size_t nbytes)
*/
for (ptr = (uint32_t *)start, mark = (nbytes >> 2);
*ptr == STACK_COLOR && mark > 0;
mark > 0 && *ptr == STACK_COLOR;
ptr++, mark--);
/* Return our guess about how much stack space was used */
+1 -1
View File
@@ -116,7 +116,7 @@ size_t xtensa_stack_check(uintptr_t alloc, size_t size)
*/
for (ptr = (uint32_t *)start, mark = (size >> 2);
*ptr == STACK_COLOR && mark > 0;
mark > 0 && *ptr == STACK_COLOR;
ptr++, mark--);
/* If the stack is completely used, then this might mean that the stack