3 ms·
I’m a bit curious how this confers a security advantage. Isn’t the kernel clearing free pages before handing them out? Or does it not bother when it’s a kernel
by vlovich123 4y ago
I’m a bit curious how this confers a security advantage. Isn’t the kernel clearing free pages before handing them out? Or does it not bother when it’s a kernel allocation?
If the latter, wouldn’t that be an obvious risk mitigation without even needing to segment by type (ie only hand out zeroed pages for allocations)?
If they’re being zeroed out, then I’m not sure I understand how grouping by type improves UAF security since the attacker couldn’t control the contents.
I’m sure I’m just ignorant here since there’s so much research into this type of hardening. Genuinely curious.
- helloooooooo 4y agoIt’s not pages. It’s individual allocations. When free-ing and allocation, it returns it back to the free list to be popped off the next time an allocation of appropriate size comes along. Some implementations have a stochastic element to randomize the freelist entry returned to alloc. A type segregated heap mitigates many classes of type confusion exploitation by preventing confusing objects in use-after-free scenarios. It’s also incredibly expensive to zero out free-ed allocations each time.
- saagarjha 4y agoIt’s not too bad, the kernel has been doing this for a couple years already.
- saagarjha 4y agoI haven’t read the whole thing yet but just zeroing allocations (see comment below on allocations versus pages) is not a full fix, because a UAF can come through a dangling pointer. What you need to mitigate against this is preventing allocations from being reused. This is infeasible to do perfectly because it just means you leak everything but in isolated cases you can do things like prevent different types from being given the same allocation (and thus allowing for shenanigans when code does a type confusion) or do other kinds of segregation and randomization to make it difficult to predict when it will be coming back.
- malf 4y agoSearch the article for ‘iovec’, they explain exactly that.
- olliej 4y agoThe big issue you're trying to address with type based segregation isn't so much the leak of uninitialized data, but rather an attacker managing to get the executing code to have more than one reference to a single piece of memory, but each reference thinks that memory is a different type. They give an example in the "Type isolation" section where they have two different types, but one has controllable value, and the other has a pointer. In this scenario the attacker has some way to read the time field. What the attacker does is get you to heap allocate a timespec struct, free it but keep the pointer (classic dangling reference), and then get your code to allocate an iovec. Assuming the attacker has done things "right", the iovec that they allocate will be allocated at the address of the timespec that was freed. Now, it's reasonable to believe that the attacker has someway to get the time described by a timespec, so that is what the attacker now does, except now the dangling timespec pointer is pointing to what is actually an iovec, and so the tv_sec field is no longer a real time value, but is actually a pointer. So when the attacker reads that time out, they can convert it back into an address in memory, which gives them the ability to bypass address space randomization. Now, if the attacker has complete control of the tv_sec they can also read arbitrary memory by setting the time on the ostensibly dangling pointer, and then getting the kernel to read values from the iovec. It should be fairly easy to see how separating where different types of object are stored breaks this path - the most the attacker can do with a dangling timespec is point it at a different timespec, ditto for iovec. Obviously this is not some magical Security Is Fixed panacea - the underlying use after free bug is the issue - but it does make actually exploiting that UaF harder. The post references a few other implementations of type segregating allocators, which also have blog posts that may provide some different details (although obviously the core type segregation portions also have a lot of overlap).