Memory allocators

On glibc-based systems, you can replace malloc, free, new, delete, etc using /etc/ld.so.preload.

There are quite a few allocators that can take advantage of this.

Examples:

  • hardened_malloc (used in GrapheneOS)
  • scudo (info) (used in Android 11+)
  • jemalloc (used in Android 10- , or Android 11+ on low-ram mode, also used at Meta, and a fork is in Firefox)
  • mimalloc (used in Unreal Engine 4.25+ games)

A ton of others can be found here.

Maybe you can filter out some of the secure ones and recommend them.

1 Like

iirc hardened_malloc doesnt work with all desktop applications.

hardened_malloc actually works quite well system wide

my packaged version for Fedora includes a handful of workaround to make it more seamless

there is a comparison here isoalloc/SECURITY_COMPARISON.MD at d7ad2a2f5148ac63b38040161b9b89fe81059587 · struct/isoalloc · GitHub

4 Likes

I think using custom mallocs are slightly above the complexity that PG audience is used to. Its better to use systems that have it pre-built like secureblue and formerly kicksecure (they deprecated it now). Ultimately projects that wish to use the hardened malloc well will have to build it into the libc itself instead of using preload according to Micay (creator of hardened malloc), and its a medium priority goal for secureblue.

Divest’s brace is also a good option as @SkewedZeppelin pointed out.

I dunno much about mallocs though, so its all borrowed opinions from my end :slight_smile:

2 Likes

Everything firefox-based (tor browser, thunderbird, etc) does not work with hardened_malloc. They’ll crash immediately with it loaded. FWIW I also found firefox unstable with scudo. Thunderbird seemed fine with scudo however IIRC.

hardened_malloc also causes instability to nix-build, which is why nixos replaced it with scudo it in their hardened profile.

2 Likes

GNOME has some segfaults with scudo too. Chromium works perfectly fine.

Integrating it into the libc would have much better results, many apps have issues with manually replacing malloc using LD_PRELOAD.
Not sure if using patchelf to inject the library would help but probably wouldn’t.

1 Like

Brace doesn’t include hardened_malloc, it is mostly just configuration files. Instead, you would have to install the divested-release repo and install Brace + hardened_malloc from there.

Yes that is what i meant, thanks for correcting!

I’m going to say a similar thing to what I said about Electron and wlroots, which is that if we are going to proactively recommend this then I want to see proof that using a hardened memory allocator could have prevented a real-world exploit for somebody in the past.

Unlike with those two cases though, I think there might actually be evidence out there that using an alternative memory allocator could have some use in real-world scenarios, so I’m interested to see what stories/evidence you come up with.

1 Like

You don’t implement security checks after getting exploited; let’s say I create my own OS, with no any security measures. My OS technically didn’t get any malware or exploited yet; does that make it any secure? Did I know that I didn’t make any effort into securing it? Yes.

Let’s take for example the “BitLocker sniffing” video, ESET lays it out very well with this article https://www.eset.com/blog/enterprise/keeping-encryption-secure-from-bitlocker-sniffing/

Also, why bother with creating post-quantum cryptography algorithms when there have been no any evidence of real-world attack that breaks current good encryption algorithms used worldwide?

If an intruder enters your house, do you leave all your secrets in the open? Don’t you put it into account and hide anything precious/important to you?

Security is a hoax, right?

When in doubt, add to knowledge base or write a blog post.

3 Likes

Afaik Firefox works with custom memory allocators if it’s built with --enable-replace-malloc, as it’s built on Fedora

Tor browser also works with them
https://gitlab.torproject.org/tpo/applications/tor-browser-build/-/merge_requests/1001
https://gitlab.torproject.org/tpo/applications/tor-browser-build/-/merge_requests/933

You can always disable it on a per-application basis with bwrap. It’s not a problem.

There’s a clear difference between brand new software, and operating systems that are currently in use by millions of people every day and have been for decades…

1 Like

This is the only reason hardened allocators exist? I’m not familiar with Graphene’s impl, but Scudo specifically was built to mitigate memory-related (mostly the heap) attacks/corruption (data-race, buffer overflow, double-free, deterministic addressing, use-after-free, to point out some (mirror)). It is used in Android and Chrome.

Particularly important on Android as memory-related exploits once accounted for more than 60% of vulnerabilities (mirror).

5 Likes

Is scudo actually being used in Chromium? Always thought it used tcmalloc/PartitionAlloc.

Yes but usage by a developer is not the same as Privacy Guides recommending usage by end-users.

For instance, the Call Of Duty game has had a memory corruption bug, uncovered by GrapheneOS hardened_malloc. The bug could potentially have some adverse side effects, but it’s a proprietary video game, so we might not know for sure. But if a more severe issue were to exist, it will be certainly blocked, at least by this allocator.

Jonah, you already recommend that users take numerous steps that in theory should be “on the distribution/developer” to implement/enable by default and that have very minor privacy/security improvements, like switching to ZRAM (swapfile is perfectly fine if the drive is encrypted).

IMO making the Linux desktop section more comprehensive in PG can only help users, because in terms of security no distribution is good out of the box except for maybe Secureblue but it comes with usability drawbacks.

In my opinion around half of what is written here and here should make it to the knowledge base and be more frequently updated, with extra attention to the sandboxing portion because it is the biggest problem.

Oops, couldn’t understand your message before writing this.