Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

arch/stackframe: fix heap buffer overflow #1234

Merged
merged 2 commits into from
Jun 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions arch/arm/src/common/arm_stackframe.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@

FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size)
{
uintptr_t topaddr;

/* Align the frame_size */

frame_size = STACK_ALIGN_UP(frame_size);
Expand All @@ -126,8 +124,7 @@ FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size)

/* Save the adjusted stack values in the struct tcb_s */

topaddr = (uintptr_t)tcb->adj_stack_ptr - frame_size;
tcb->adj_stack_ptr = (FAR void *)topaddr;
tcb->adj_stack_ptr = (uint8_t *)tcb->adj_stack_ptr - frame_size;
tcb->adj_stack_size -= frame_size;

/* Reset the initial stack pointer */
Expand All @@ -136,5 +133,5 @@ FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size)

/* And return the pointer to the allocated region */

return (FAR void *)(topaddr + sizeof(uint32_t));
return tcb->adj_stack_ptr;
}
9 changes: 5 additions & 4 deletions arch/avr/src/avr/up_stackframe.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@

FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size)
{
uintptr_t topaddr;
/* Align the frame_size */

frame_size = STACK_ALIGN_UP(frame_size);

/* Is there already a stack allocated? Is it big enough? */

Expand All @@ -110,8 +112,7 @@ FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size)

/* Save the adjusted stack values in the struct tcb_s */

topaddr = (uintptr_t)tcb->adj_stack_ptr - frame_size;
tcb->adj_stack_ptr = (FAR void *)topaddr;
tcb->adj_stack_ptr = (uint8_t *)tcb->adj_stack_ptr - frame_size;
tcb->adj_stack_size -= frame_size;

/* Set the initial stack pointer to the "base" of the allocated stack */
Expand All @@ -121,5 +122,5 @@ FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size)

/* And return the pointer to the allocated region */

return (FAR void *)(topaddr + sizeof(uint8_t));
return tcb->adj_stack_ptr;
}
7 changes: 2 additions & 5 deletions arch/avr/src/avr32/up_stackframe.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@

FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size)
{
uintptr_t topaddr;

/* Align the frame_size */

frame_size = STACK_ALIGN_UP(frame_size);
Expand All @@ -126,8 +124,7 @@ FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size)

/* Save the adjusted stack values in the struct tcb_s */

topaddr = (uintptr_t)tcb->adj_stack_ptr - frame_size;
tcb->adj_stack_ptr = (FAR void *)topaddr;
tcb->adj_stack_ptr = (uint8_t *)tcb->adj_stack_ptr - frame_size;
tcb->adj_stack_size -= frame_size;

/* Reset the initial stack pointer */
Expand All @@ -136,5 +133,5 @@ FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size)

/* And return the pointer to the allocated region */

return (FAR void *)(topaddr + sizeof(uint32_t));
return tcb->adj_stack_ptr;
}
7 changes: 2 additions & 5 deletions arch/hc/src/common/up_stackframe.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@

FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size)
{
uintptr_t topaddr;

/* Align the frame_size */

frame_size = STACK_ALIGN_UP(frame_size);
Expand All @@ -126,8 +124,7 @@ FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size)

/* Save the adjusted stack values in the struct tcb_s */

topaddr = (uintptr_t)tcb->adj_stack_ptr - frame_size;
tcb->adj_stack_ptr = (FAR void *)topaddr;
tcb->adj_stack_ptr = (uint8_t *)tcb->adj_stack_ptr - frame_size;
tcb->adj_stack_size -= frame_size;

/* Reset the initial stack pointer */
Expand All @@ -137,5 +134,5 @@ FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size)

/* And return the pointer to the allocated region */

return (FAR void *)(topaddr + sizeof(uint16_t));
return tcb->adj_stack_ptr;
}
7 changes: 2 additions & 5 deletions arch/mips/src/common/mips_stackframe.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@

FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size)
{
uintptr_t topaddr;

/* Align the frame_size */

frame_size = STACK_ALIGN_UP(frame_size);
Expand All @@ -129,8 +127,7 @@ FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size)

/* Save the adjusted stack values in the struct tcb_s */

topaddr = (uintptr_t)tcb->adj_stack_ptr - frame_size;
tcb->adj_stack_ptr = (FAR void *)topaddr;
tcb->adj_stack_ptr = (uint8_t *)tcb->adj_stack_ptr - frame_size;
tcb->adj_stack_size -= frame_size;

/* Reset the initial stack pointer */
Expand All @@ -139,5 +136,5 @@ FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size)

/* And return the pointer to the allocated region */

return (FAR void *)(topaddr + sizeof(uint32_t));
return tcb->adj_stack_ptr;
}
7 changes: 2 additions & 5 deletions arch/misoc/src/lm32/lm32_stackframe.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@

FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size)
{
uintptr_t topaddr;

/* Align the frame_size */

frame_size = STACK_ALIGN_UP(frame_size);
Expand All @@ -122,8 +120,7 @@ FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size)

/* Save the adjusted stack values in the struct tcb_s */

topaddr = (uintptr_t)tcb->adj_stack_ptr - frame_size;
tcb->adj_stack_ptr = (FAR void *)topaddr;
tcb->adj_stack_ptr = (uint8_t *)tcb->adj_stack_ptr - frame_size;
tcb->adj_stack_size -= frame_size;

/* Reset the initial stack pointer */
Expand All @@ -132,5 +129,5 @@ FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size)

/* And return the pointer to the allocated region */

return (FAR void *)(topaddr + sizeof(uint32_t));
return tcb->adj_stack_ptr;
}
7 changes: 2 additions & 5 deletions arch/misoc/src/minerva/minerva_stackframe.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@

FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size)
{
uintptr_t topaddr;

/* Align the frame_size */

frame_size = STACK_ALIGN_UP(frame_size);
Expand All @@ -122,8 +120,7 @@ FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size)

/* Save the adjusted stack values in the struct tcb_s */

topaddr = (uintptr_t) tcb->adj_stack_ptr - frame_size;
tcb->adj_stack_ptr = (FAR void *)topaddr;
tcb->adj_stack_ptr = (uint8_t *)tcb->adj_stack_ptr - frame_size;
tcb->adj_stack_size -= frame_size;

/* Reset the initial stack pointer */
Expand All @@ -132,5 +129,5 @@ FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size)

/* And return the pointer to the allocated region */

return (FAR void *)(topaddr + sizeof(uint32_t));
return tcb->adj_stack_ptr;
}
7 changes: 2 additions & 5 deletions arch/or1k/src/common/up_stackframe.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@

FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size)
{
uintptr_t topaddr;

/* Align the frame_size */

frame_size = STACK_ALIGN_UP(frame_size);
Expand All @@ -118,8 +116,7 @@ FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size)

/* Save the adjusted stack values in the struct tcb_s */

topaddr = (uintptr_t)tcb->adj_stack_ptr - frame_size;
tcb->adj_stack_ptr = (FAR void *)topaddr;
tcb->adj_stack_ptr = (uint8_t *)tcb->adj_stack_ptr - frame_size;
tcb->adj_stack_size -= frame_size;

/* Reset the initial stack pointer */
Expand All @@ -128,5 +125,5 @@ FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size)

/* And return the pointer to the allocated region */

return (FAR void *)(topaddr + sizeof(uint32_t));
return tcb->adj_stack_ptr;
}
8 changes: 3 additions & 5 deletions arch/renesas/src/common/up_stackframe.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
/****************************************************************************
* Pre-processor Macros
****************************************************************************/

/* The SH stack must be aligned at word (4 byte) boundaries. If necessary
* frame_size must be rounded up to the next boundary
*/
Expand Down Expand Up @@ -109,8 +110,6 @@

FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size)
{
uintptr_t topaddr;

/* Align the frame_size */

frame_size = STACK_ALIGN_UP(frame_size);
Expand All @@ -124,8 +123,7 @@ FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size)

/* Save the adjusted stack values in the struct tcb_s */

topaddr = (uintptr_t)tcb->adj_stack_ptr - frame_size;
tcb->adj_stack_ptr = (FAR void *)topaddr;
tcb->adj_stack_ptr = (uint8_t *)tcb->adj_stack_ptr - frame_size;
tcb->adj_stack_size -= frame_size;

/* Reset the initial state */
Expand All @@ -134,5 +132,5 @@ FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size)

/* And return a pointer to allocated memory */

return (FAR void *)(topaddr + sizeof(uint32_t));
return tcb->adj_stack_ptr;
}
7 changes: 2 additions & 5 deletions arch/risc-v/src/common/riscv_stackframe.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@

FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size)
{
uintptr_t topaddr;

/* Align the frame_size */

frame_size = STACK_ALIGN_UP(frame_size);
Expand All @@ -129,8 +127,7 @@ FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size)

/* Save the adjusted stack values in the struct tcb_s */

topaddr = (uintptr_t)tcb->adj_stack_ptr - frame_size;
tcb->adj_stack_ptr = (FAR void *)topaddr;
tcb->adj_stack_ptr = (uint8_t *)tcb->adj_stack_ptr - frame_size;
tcb->adj_stack_size -= frame_size;

/* Reset the initial stack pointer */
Expand All @@ -139,5 +136,5 @@ FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size)

/* And return the pointer to the allocated region */

return (FAR void *)(topaddr);
return tcb->adj_stack_ptr;
}
7 changes: 2 additions & 5 deletions arch/sim/src/sim/up_stackframe.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@

FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size)
{
uintptr_t topaddr;

/* Align the frame_size */

frame_size = STACK_ALIGN_UP(frame_size);
Expand All @@ -118,8 +116,7 @@ FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size)

/* Save the adjusted stack values in the struct tcb_s */

topaddr = (uintptr_t)tcb->adj_stack_ptr - frame_size;
tcb->adj_stack_ptr = (FAR void *)topaddr;
tcb->adj_stack_ptr = (uint8_t *)tcb->adj_stack_ptr - frame_size;
tcb->adj_stack_size -= frame_size;

/* Reset the initial state */
Expand All @@ -128,5 +125,5 @@ FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size)

/* And return a pointer to the allocated memory */

return (FAR void *)(topaddr + sizeof(uint32_t));
return tcb->adj_stack_ptr;
}
7 changes: 2 additions & 5 deletions arch/x86/src/i486/up_stackframe.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@

FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size)
{
uintptr_t topaddr;

/* Align the frame_size */

frame_size = STACK_ALIGN_UP(frame_size);
Expand All @@ -127,8 +125,7 @@ FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size)

/* Save the adjusted stack values in the struct tcb_s */

topaddr = (uintptr_t)tcb->adj_stack_ptr - frame_size;
tcb->adj_stack_ptr = (FAR void *)topaddr;
tcb->adj_stack_ptr = (uint8_t *)tcb->adj_stack_ptr - frame_size;
tcb->adj_stack_size -= frame_size;

/* Reset the initial stack pointer */
Expand All @@ -137,5 +134,5 @@ FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size)

/* And return the pointer to the allocated region */

return (FAR void *)(topaddr + sizeof(uint32_t));
return tcb->adj_stack_ptr;
}
8 changes: 2 additions & 6 deletions arch/x86_64/src/intel64/up_stackframe.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@

FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size)
{
uintptr_t topaddr;

/* Align the frame_size */

frame_size = STACK_ALIGN_UP(frame_size);
Expand All @@ -112,8 +110,7 @@ FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size)

/* Save the adjusted stack values in the struct tcb_s */

topaddr = (uintptr_t)tcb->adj_stack_ptr - frame_size;
tcb->adj_stack_ptr = (FAR void *)topaddr;
tcb->adj_stack_ptr = (uint8_t *)tcb->adj_stack_ptr - frame_size;
tcb->adj_stack_size -= frame_size;

/* Reset the initial stack pointer */
Expand All @@ -122,6 +119,5 @@ FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size)

/* And return the pointer to the allocated region */

return (FAR void *)(topaddr + sizeof(uint64_t));
return tcb->adj_stack_ptr;
}

7 changes: 2 additions & 5 deletions arch/xtensa/src/common/xtensa_stackframe.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@

FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size)
{
uintptr_t topaddr;

/* Align the frame_size */

frame_size = STACK_ALIGN_UP(frame_size);
Expand All @@ -121,8 +119,7 @@ FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size)

/* Save the adjusted stack values in the struct tcb_s */

topaddr = (uintptr_t)tcb->adj_stack_ptr - frame_size;
tcb->adj_stack_ptr = (FAR void *)topaddr;
tcb->adj_stack_ptr = (uint8_t *)tcb->adj_stack_ptr - frame_size;
tcb->adj_stack_size -= frame_size;

/* Reset the initial stack pointer (A1) */
Expand All @@ -131,5 +128,5 @@ FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size)

/* And return the pointer to the allocated region */

return (FAR void *)(topaddr + sizeof(uint32_t));
return tcb->adj_stack_ptr;
}
Loading