> The problem is that once you assume that, you've completely > lost control over what happens when the program's behavior is > undefined due to memory lifetime bugs in the application (UAF/DF/etc) Yes, but that's exactly the contract between the C language and the programmer: to leave everything in the hands of people for maximum control and efficiency. If we need more "protection", then we can just use other more advanced (and inefficient) languages. Also, because of the enormous flexibility that C gives the programmer (and also hugely destructive when used incorrectly). So I'm afraid that the various checks we do at such a high cost may also be "better than nothing" to prevent bugs? Of course, these tradeoffs are indeed a delicate matter. It's hard to have a definitive answer. -- Best Regards BaiYang baiyang@gmail.com http://i.baiy.cn **** < END OF EMAIL > **** From: Rich Felker Date: 2022-09-20 20:16 To: baiyang CC: musl Subject: Re: Re: [musl] The heap memory performance (malloc/free/realloc) is significantly degraded in musl 1.2 (compared to 1.1) On Tue, Sep 20, 2022 at 01:56:12PM +0800, baiyang wrote: > > // This multi-threaded access to the pagemap is safe for fairly > > // subtle reasons. We basically assume that when an object X is > > // allocated by thread A and deallocated by thread B, there must > > // have been appropriate synchronization in the handoff of object > > // X from thread A to thread B. > > Thanks for your information. > I feel this assumption is very reasonable: you can't have one thread > doing "free(p)" while another thread is accessing the block pointed > to by p without any synchronization mechanism at the same time. That's a correct assumption given that the program's behavior is defined. The problem is that once you assume that, you've completely lost control over what happens when the program's behavior is undefined due to memory lifetime bugs in the application (UAF/DF/etc) and an allocator that does this will necessarily allow bugs in the lifetimes of objects that aren't inherently exploitable on the application level (don't contain pointers that will be written through that might clobber other application state, etc.) to be used to gain control over the allocator state and eventually gain control over the flow of execution through manipulating other allocated objects that are attack vectors. A hardened allocator like mallocng or hardened_malloc does not make assumptions about the validity of data reachable for clobbering through application bugs that haven't already yielded a high level of control to the attacker. Instead, the metadata assumed to be valid is at "secret locations" outside the area where application data is stored that are intended not to be determinable without already having some strong level of control over execution flow. And on top of that, it's cross-validated as much as possible. We also do validation where we can of the "in-band" data that is easily reachable by overflows in application buffers, etc. This both blocks a lot of potential exploits, and catches application bugs that could be exploitable before they turn into exploits, by having them crash on developers'/packagers' systems before they're deployed and getting the root cause investigated and fixed. Rich