Skip to content

Commit

Permalink
Add text layout randomization
Browse files Browse the repository at this point in the history
  • Loading branch information
pawnlord committed Mar 4, 2024
1 parent 80ef547 commit 25ff703
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 36 deletions.
11 changes: 7 additions & 4 deletions application_processor/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,9 @@ fn main() {

let stack_start = ram_origin + (ram_length/4) + gen_addr(0, max_spacing, &mut rng);

let stext = 0x1000e200;

let sentry = gen_addr(0, max_spacing, &mut rng);

let textoffset = gen_addr(0, max_spacing, &mut rng);
let rodataoffset = gen_addr(0, max_spacing, &mut rng);
let dataoffset = gen_addr(0, max_spacing, &mut rng);
let bssoffset = gen_addr(0, max_spacing, &mut rng);
Expand All @@ -192,15 +193,17 @@ fn main() {
}}
/* Bootloader jumps to this address to start the ap */
_stext = {stext:#x};
_sentry = {sentry:#x};
rodataoffset = {rodataoffset:#x};
_stack_start = {stack_start:#x};
dataoffset = {dataoffset:#x};
bssoffset = {bssoffset:#x};
textoffset = {textoffset:#x};
");


File::create(out.join("memory.x"))
.unwrap()
.write_all(memory_x.as_bytes())
Expand Down
22 changes: 10 additions & 12 deletions application_processor/link.x
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,20 @@ SECTIONS
KEEP(*(.vector_table.interrupts)); /* this is the `__INTERRUPTS` symbol */
} > FLASH

PROVIDE(_stext = ADDR(.vector_table) + SIZEOF(.vector_table));

.entry _sentry:
{
.__sentry = .;
*(.Reset);
.__eentry = .;

} > FLASH

/* ### .text */
.text _stext :
.text :
{
. = . + textoffset;
__stext = .;
*(.Reset);

*(.text .text.*);

Expand Down Expand Up @@ -251,15 +258,6 @@ Possible solutions, from most likely to less likely:
may be enabling it)
- Supply the interrupt handlers yourself. Check the documentation for details.");

/* ## .text */
ASSERT(ADDR(.vector_table) + SIZEOF(.vector_table) <= _stext, "
ERROR(cortex-m-rt): The .text section can't be placed inside the .vector_table section
Set _stext to an address greater than the end of .vector_table (See output of `nm`)");

ASSERT(_stext + SIZEOF(.text) < ORIGIN(FLASH) + LENGTH(FLASH), "
ERROR(cortex-m-rt): The .text section must be placed inside the FLASH memory.
Set _stext to an address smaller than 'ORIGIN(FLASH) + LENGTH(FLASH)'");

/* # Other checks */
ASSERT(SIZEOF(.got) == 0, "
ERROR(cortex-m-rt): .got section detected in the input object files
Expand Down
10 changes: 6 additions & 4 deletions component/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,9 @@ fn main() {

let stack_start = ram_origin + (ram_length/4) + gen_addr(0, max_spacing, &mut rng);

let stext = 0x1000e200;

let sentry = gen_addr(0, max_spacing, &mut rng);

let textoffset = gen_addr(0, max_spacing, &mut rng);
let rodataoffset = gen_addr(0, max_spacing, &mut rng);
let dataoffset = gen_addr(0, max_spacing, &mut rng);
let bssoffset = gen_addr(0, max_spacing, &mut rng);
Expand All @@ -171,13 +172,14 @@ fn main() {
}}
/* Bootloader jumps to this address to start the ap */
_stext = {stext:#x};
_sentry = {sentry:#x};
rodataoffset = {rodataoffset:#x};
_stack_start = {stack_start:#x};
dataoffset = {dataoffset:#x};
bssoffset = {bssoffset:#x};
textoffset = {textoffset:#x};
");


Expand Down
8 changes: 4 additions & 4 deletions component/inc/ectf_params.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef __ECTF_PARAMS__
#define __ECTF_PARAMS__
#define COMPONENT_ID 0x11111125
#define COMPONENT_BOOT_MSG "component a"
#define ATTESTATION_LOC "detroit"
#define COMPONENT_ID 0x11111126
#define COMPONENT_BOOT_MSG "component b"
#define ATTESTATION_LOC "honolulu"
#define ATTESTATION_DATE "1/1/2069"
#define ATTESTATION_CUSTOMER "bobs warehouse"
#define ATTESTATION_CUSTOMER "sea anenome"
#endif
22 changes: 10 additions & 12 deletions component/link.x
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,20 @@ SECTIONS
KEEP(*(.vector_table.interrupts)); /* this is the `__INTERRUPTS` symbol */
} > FLASH

PROVIDE(_stext = ADDR(.vector_table) + SIZEOF(.vector_table));

.entry _sentry:
{
.__sentry = .;
*(.Reset);
.__eentry = .;

} > FLASH

/* ### .text */
.text _stext :
.text :
{
. = . + textoffset;
__stext = .;
*(.Reset);

*(.text .text.*);

Expand Down Expand Up @@ -251,15 +258,6 @@ Possible solutions, from most likely to less likely:
may be enabling it)
- Supply the interrupt handlers yourself. Check the documentation for details.");

/* ## .text */
ASSERT(ADDR(.vector_table) + SIZEOF(.vector_table) <= _stext, "
ERROR(cortex-m-rt): The .text section can't be placed inside the .vector_table section
Set _stext to an address greater than the end of .vector_table (See output of `nm`)");

ASSERT(_stext + SIZEOF(.text) < ORIGIN(FLASH) + LENGTH(FLASH), "
ERROR(cortex-m-rt): The .text section must be placed inside the FLASH memory.
Set _stext to an address smaller than 'ORIGIN(FLASH) + LENGTH(FLASH)'");

/* # Other checks */
ASSERT(SIZEOF(.got) == 0, "
ERROR(cortex-m-rt): .got section detected in the input object files
Expand Down

0 comments on commit 25ff703

Please sign in to comment.