GrapheneOS / hardened_malloc

Hardened allocator designed for modern systems. It has integration into Android's Bionic libc and can be used externally with musl and glibc as a dynamic library for use on other Linux-based platforms. It will gain more portability / integration over time.
https://grapheneos.org/
MIT License
1.3k stars 97 forks source link

[Question][Android] How to use for debugging? #224

Closed alexmercerind closed 1 year ago

alexmercerind commented 1 year ago

We recently received a bug-report where native code in our application leads to crash if hardened_malloc is utilized on GrapheneOS. Looking at my implementation, I can't figure out where exactly memory corruption or memory access violation is taking place.

I do not use GrapheneOS, neither own a Google Pixel.

What options do I have to possibly use Hardened Malloc or GrapheneOS locally for testing?

It'll be easier for me to locally reproduce the reported issue & possibly retrieve a symbolized stacktrace, possibly using ndk-stack. Alternatively, I will likely be able to hit-and-trial to find out the possible issue causing code-path.

Thanks!

thestinger commented 1 year ago

You could make a userdebug build of GrapheneOS for the emulator since we still have hardened_malloc on x86_64.

% repo init -u https://github.com/GrapheneOS/platform_manifest.git -b 14
% repo sync -j4
% source build/envsetup.sh
% choosecombo release sdk_phone_x86_64 userdebug
% m
% emulator

However, the memory corruption bug in whatever is causing it may be specific to arm64 and Android doesn't really support non-x86 emulator anymore.

Requires a Linux workstation with a huge amount of disk space and a decent amount of memory. Can reduce the number of build jobs if you don't have enough memory. https://grapheneos.org/build has proper documentation.

A userdebug build of the OS combined with a debug build of the app with native debug symbols would help with debugging it.

It's probably a use-after-free bug.

matchboxbananasynergy commented 1 year ago

The issue in media_kit has been resolved, it turns out that it was a memory corruption issue that hardened_malloc was catching, which has now been resolved. :)

Details here: https://github.com/deckerst/aves/issues/722#issuecomment-1763515974

I think this issue can be closed.