Skip to content

libtrap: misaligned address #146

@jozhalaj

Description

@jozhalaj

Hi,

I'm working on an IoT detector using a nemea-framework. The detector works fine on the x86 architecture, but when tested on a Turris router with OpenWRT and an ARM processor, it crashes on a Bus Error when receiving a message and then retrieving message items using the ur_get () macro. Crashes only occur when compiler optimization is turned on. This line of code causes crash.

ZWaveDetector.cpp:236: double event_type = ur_get(in_events_template, in_record, F_EVENT_TYPE);

I tried compilation using clang with a sanitizer. I got this output after sending UniRec message to detector:

ZWaveDetector.cpp:235:26: runtime error: load of misaligned address 0x63300001c84a for type 'ur_time_t' (aka 'unsigned long'), which requires 8 byte alignment
0x63300001c84a: note: pointer points here
00 00 f0 3f 22 db f9 1e 54 27 c5 5e 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00
^
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ZWaveDetector.cpp:235:26 in

ZWaveDetector.cpp:236:24: runtime error: load of misaligned address 0x63300001c81a for type 'double', which requires 8 byte alignment
0x63300001c81a: note: pointer points here
00 00 00 00 00 00 00 00 00 00 32 40 00 00 00 00 00 00 00 00 00 00 20 49 84 32 ec 41 00 00 00 00
^
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ZWaveDetector.cpp:236:24 in

You can reproduce it with following sequence of commands:

$ git clone https://github.com/CESNET/NEMEA-SIoT.git
$ git checkout libtrap-bug-reproduce
$ cd zwave-detector
$ ./bootstrap.sh
$ ./configure CXX=clang++ CXXFLAGS=-fsanitize=address,undefined
$ make
$ logreplay -f test_input.csv -i u:events &
$ ./siot-zwave-detector -i u:frames,u:events,u:alerts

Strict aliasing issues may cause bus errors on ARM architecture, so it seems to me that the issue can be conected with the problems reported by ASan.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions