Skip to content

Conversation

@yamt
Copy link
Collaborator

@yamt yamt commented Oct 29, 2021

Detected by UBSan

/root/src/wasm-micro-runtime/core/iwasm/aot/arch/aot_reloc_x86_64.c:232:43: runtime error: addition of unsigned offset to 0x000041209004 overflowed to 0x000041209000
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /root/src/wasm-micro-runtime/core/iwasm/aot/arch/aot_reloc_x86_64.c:232:43 in

Detected by UBSan

```
/root/src/wasm-micro-runtime/core/iwasm/aot/arch/aot_reloc_x86_64.c:232:43: runtime error: addition of unsigned offset to 0x000041209004 overflowed to 0x000041209000
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /root/src/wasm-micro-runtime/core/iwasm/aot/arch/aot_reloc_x86_64.c:232:43 in
```
((uint8 *)symbol_addr + reloc_addend
- (target_section_addr + reloc_offset));
((uintptr_t)symbol_addr + reloc_addend
- (uintptr_t)(target_section_addr + reloc_offset));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we also fix other places, e.g. L168-L170?

Copy link
Contributor

@wenyongh wenyongh Oct 31, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And not known which expression causes integer overflow? target_section_addr + reloc_offset, plt + reloc_addend, or (plt + reloc_addend - (target_section_addr + reloc_offset))? Here the type of plt and target_section_addr is uint8 *, the range is 0 ~ 2^64-1 in x86-64, a little confused why there is integer overflow, could you please give an example as there might be some other places to be fixed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • iirc, pointer overflows like these are undefined behavior in C. unsigned integer overflows are ok.
  • i haven't checked other places. i just fixed a few places which actually got complaints from UBSAN during my tests.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, so the code inserted by the compiler detected pointer overflow and reported error, from the output log runtime error: addition of unsigned offset to 0x000041209004 overflowed to 0x00004120900 ... aot_reloc_x86_64.c:232:43,the overflow should occur at (uint8 *)symbol_addr + reloc_addend. We will merge this PR firstly and check whether there are other places to fix. Thanks a lot!

@wenyongh wenyongh merged commit 2613a68 into bytecodealliance:main Nov 8, 2021
wenyongh referenced this pull request in wenyongh/wasm-micro-runtime Nov 8, 2021
aot_reloc_x86_64: Fix pointer overflows (#809)
vickiegpt pushed a commit to vickiegpt/wamr-aot-gc-checkpoint-restore that referenced this pull request May 27, 2024
Fix pointer overflow of `(uint8 *)symbol_addr + reloc_addend` detected by UBSan:
```
core/iwasm/aot/arch/aot_reloc_x86_64.c:232:43: runtime error: addition of unsigned offset to 0x000041209004 overflowed to 0x000041209000
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior core/iwasm/aot/arch/aot_reloc_x86_64.c:232:43
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants