Skip to content

ctr_encrypt ctr->pad not aligned #549

@mkj

Description

@mkj

Description

Running under ubsan catches undefined behaviour in ctr_encrypt. The problem is that ctr->pad isn't 16 byte aligned, but we have a cast to a ulong64. I'm not sure how important it is for portability, I guess x64 works fine? Unsure the best way to fix it, other than just disabling LTC_FAST for that section - maybe the compiler will unroll it anyway...

ctr_encrypt.c:63               *(LTC_FAST_TYPE_PTR_CAST((unsigned char *)ctr->pad + x));

Steps to Reproduce

make CC=clang CFLAGS="-fsanitize=undefined -fno-sanitize-recover=undefined -DUSE_LTM -DLTM_DESC" EXTRALIBS="-ltommath" LD=clang++ LDFLAGS=-fsanitize=undefined test

./test
...
store_test..........src/modes/ctr/ctr_encrypt.c:57:60: runtime error: load of misaligned address 0x000000eae01c for type 'LTC_FAST_TYPE' (aka 'unsigned long long'), which requires 8 byte alignment
0x000000eae01c: note: pointer points here
  00 00 00 00 9e 26 81 83  ff ee e7 0b 2e 07 2e 5c  68 ee e6 29 00 00 00 00  00 00 00 00 00 00 00 00
              ^ 
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/modes/ctr/ctr_encrypt.c:57:60 in 

Version

v1.18.2-595-gcfbd7f8d
Ubuntu 20.04, x64
clang 10.0.0-4ubuntu1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions