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

Casting pointer without alignment freezes RP2040 platform #5665

Closed
Mictronics opened this issue Dec 25, 2024 · 3 comments
Closed

Casting pointer without alignment freezes RP2040 platform #5665

Mictronics opened this issue Dec 25, 2024 · 3 comments

Comments

@Mictronics
Copy link
Contributor

https://github.com/meshtastic/firmware/blob/a7d9e8107ac9f16575e349503ac5ce1c3a866ec4/src/mesh/aes-ccm.cpp#L21C1-L22C35

Compiling .pio/build/rp2040-lora/src/mesh/aes-ccm.cpp.o
src/mesh/aes-ccm.cpp: In function 'void xor_aes_block(uint8_t*, const uint8_t*)':
src/mesh/aes-ccm.cpp:21:19: warning: cast from 'uint8_t*' {aka 'unsigned char*'} to 'uint32_t*' {aka 'long unsigned int*'} increases required alignment of target type [-Wcast-align]
   21 |     uint32_t *d = (uint32_t *)dst;
      |                   ^~~~~~~~~~~~~~~
src/mesh/aes-ccm.cpp:22:19: warning: cast from 'const uint8_t*' {aka 'const unsigned char*'} to 'uint32_t*' {aka 'long unsigned int*'} increases required alignment of target type [-Wcast-align]
   22 |     uint32_t *s = (uint32_t *)src;
      |                   ^~~~~~~~~~~~~~~

The following XOR operations fails and freezes the device.

DEBUG | 13:18:53 152 [RadioIf] Lora RX (id=0x5fc749a5 fr=0xebe30cb7 to=0xe7678f25, WantAck=1, HopLim=7 Ch=0x0 encrypted rxSNR=5.25 rxRSSI=-64 hopStart=7)
DEBUG | 13:18:54 152 [RadioIf] Packet RX: 600ms
DEBUG | 13:18:54 152 [Router] Add packet record (id=0x5fc749a5 fr=0xebe30cb7 to=0xe7678f25, WantAck=1, HopLim=7 Ch=0x0 encrypted rxSNR=5.25 rxRSSI=-64 hopStart=7)
DEBUG | 13:18:54 152 [Router] Attempt PKI decryption
INFO  | 13:18:54 152 [Router] Random nonce value: 1708761091
DEBUG | 13:18:54 152 [Router] Attempt decrypt with nonce:  ax 4x cx 5x 0x ax dx 6x bx 0x ex ex 0x

DEBUG | 13:18:54 152 [Router] Attempt decrypt with shared_key starting with:  ax 6x ax ax 1x 5x 6x fx

Device is frozen here.

Was working fine in 2.5.14 but now code seems to be no longer aligned after recent changes. Testing with commits up to a7d9e81 in my own fork&branch. Reproducible on two different rp2040-lora.

Same branch works fine on T-Echo nrf52.

@Mictronics
Copy link
Contributor Author

Debug trace when running on a Pico with JLink:

isr_hardfault@0x100030c4 (/home/earle/Arduino/hardware/pico/rp2040/pico-sdk/src/rp2_common/pico_crt0/crt0.S:170)
<signal handler called>@0xfffffffd (Unbekannte Quelle:0)
xor_aes_block@0x10016f3a (/home/lupus/git/MeshtasticFirmware/src/mesh/aes-ccm.cpp:24)
aes_ccm_encr@0x10017054 (/home/lupus/git/MeshtasticFirmware/src/mesh/aes-ccm.cpp:89)
aes_ccm_ad@0x1001724c (/home/lupus/git/MeshtasticFirmware/src/mesh/aes-ccm.cpp:154)
CryptoEngine::decryptCurve25519@0x1000e4ba (/home/lupus/git/MeshtasticFirmware/src/mesh/CryptoEngine.cpp:132)
perhapsDecode@0x10016026 (/home/lupus/git/MeshtasticFirmware/src/mesh/Router.cpp:336)
Router::handleReceived@0x100164bc (/home/lupus/git/MeshtasticFirmware/src/mesh/Router.cpp:578)
Router::perhapsHandleReceived@0x10016672 (/home/lupus/git/MeshtasticFirmware/src/mesh/Router.cpp:680)
Router::perhapsHandleReceived@0x10016672 (/home/lupus/git/MeshtasticFirmware/src/mesh/Router.cpp:633)
Router::runOnce@0x100166bc (/home/lupus/git/MeshtasticFirmware/src/mesh/Router.cpp:70)
ReliableRouter::runOnce@0x100158f0 (/home/lupus/git/MeshtasticFirmware/src/mesh/ReliableRouter.h:79)
concurrency::OSThread::run@0x1000641a (/home/lupus/git/MeshtasticFirmware/src/concurrency/OSThread.cpp:85)
ThreadController::runOrDelay@0x10025d2a (/home/lupus/git/MeshtasticFirmware/.pio/libdeps/pico_waveshare/Thread/ThreadController.cpp:59)
loop@0x1000cd5a (/home/lupus/git/MeshtasticFirmware/src/main.cpp:1291)
__core0@0x1003fe8a (/home/lupus/.platformio/packages/framework-arduinopico/libraries/FreeRTOS/src/variantHooks.cpp:141)
vPortStartFirstTask@0x10040228 (/home/lupus/.platformio/packages/framework-arduinopico/libraries/FreeRTOS/lib/FreeRTOS-Kernel/portable/ThirdParty/GCC/RP2040/port.c:242)

@Mictronics
Copy link
Contributor Author

image
Local variables in xor_aes_block on hardfault.

Mictronics added a commit to Mictronics/meshtastic_firmware that referenced this issue Dec 27, 2024
Mictronics added a commit to Mictronics/meshtastic_firmware that referenced this issue Dec 27, 2024
GUVWAF added a commit that referenced this issue Dec 27, 2024
* Fix issue #5665.

---------

Co-authored-by: Ben Meadors <[email protected]>
Co-authored-by: Thomas Göttgens <[email protected]>
Co-authored-by: GUVWAF <[email protected]>
@GUVWAF
Copy link
Member

GUVWAF commented Dec 27, 2024

Fixed by #5678.

@GUVWAF GUVWAF closed this as completed Dec 27, 2024
thebentern added a commit that referenced this issue Jan 7, 2025
* Fix LED pinout for T-Echo board marked v1.0, date 2021-6-28

* Merge PR #420

* Fixed double and missing Default class.

* Use correct format specifier and fixed typo.

* Removed duplicate code.

* Fix error: #if with no expression

* Fix warning: extra tokens at end of #endif directive.

* Fix antenna switching logic. Complementary-pin control logic is required on the rp2040-lora board.

* Fix deprecated macros.

* Set RP2040 in dormant mode when deep sleep is triggered.

* Fix array out of bounds read.

* Admin key count needs to be set otherwise the key will be zero loaded after reset.

* Don't reset the admin key size when loading defaults. Preserve an existing key in config if possible.

* Remove log spam when reading INA voltage sensor.

* Remove static declaration for admin keys from userPrefs.h. Load hard coded admin keys in case config file has empty slots.

* Removed newlines from log.

* Fix issue #5665.

* Fix build for Pico2 RP2350 platform.

---------

Co-authored-by: Ben Meadors <[email protected]>
Co-authored-by: Thomas Göttgens <[email protected]>
Co-authored-by: GUVWAF <[email protected]>
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

No branches or pull requests

2 participants