mm/slub.c: Allow poisoning to use the fast path
Subsystems (2)
RFC PATCH 1/1 mm/slub.c: Allow poisoning to use the fast path
All slub debug features currently disable the fast path completely. Some features such as consistency checks require this to allow taking of locks. Poisoning and red zoning don't require this and can safely use the per-cpu fast path. Introduce a Kconfig to continue to use the fast path when 'fast' debugging options are enabled. The code will automatically revert to always using the slow path when 'slow' options are enabled.
---
This is a follow up from my previous proposal to add an alternate per-cpu list. The feedback was just add to the fast path. With this version, the hackbench penalty with slub_debug=P is only 3%. hackbench is too noisy to give an idea of the change with just slub_debug=- so I looked at some of the bulk allocation benchmarks from https://github.com/netoptimizer/prototype-kernel . With slab_bulk_test01, the penalty was between 4-7 cycles even with slub_debug=-.
--- init/Kconfig | 10 ++++++++++ mm/slub.c | 50 +++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 55 insertions(+), 5 deletions(-)
init/Kconfig +10 -0
@@ -1582,6 +1582,16 @@ config SLUB_CPU_PARTIAL which requires the taking of locks that may cause latency spikes. Typically one would choose no for a realtime system. +config SLUB_FAST_POISON + bool "Allow poisoning debug options to use the fast path" + depends on SLUB_CPU_PARTIAL + help + Some SLUB debugging options are safe to use without taking extra + locks and can use the per-cpu lists. Enable this option to let + poisoning and red zoning use the per-cpu lists. The trade-off is + a few extra checks in the fast path. You should select this option + if you intend to use poisoning for non-debugging uses. + config MMAP_ALLOW_UNINITIALIZED bool "Allow mmapped anonymous memory to be uninitialized" depends on EXPERT && !MMU
mm/slub.c +45 -5
107 lines not on this page · raw message
Signature · 7 lines
2.13.0 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 7 lines · Laura Abbott
All slub debug features currently disable the fast path completely. Some features such as consistency checks require this to allow taking of locks. Poisoning and red zoning don't require this and can safely use the per-cpu fast path. Introduce a
Kconfigto continue to use the fast path when 'fast' debugging options are enabled. The code will automatically revert to always using the slow path when 'slow' options are enabled.
Ok I see that the objects are initialized with poisoning and redzoning but I do not see that there is fastpath code to actually check the values before the object is reinitialized. Is that intentional or am I missing something?
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 10 lines · Christopher Lameter
Quoted 7 lines · Laura Abbott
All slub debug features currently disable the fast path completely. Some features such as consistency checks require this to allow taking of locks. Poisoning and red zoning don't require this and can safely use the per-cpu fast path. Introduce a
Kconfigto continue to use the fast path when 'fast' debugging options are enabled. The code will automatically revert to always using the slow path when 'slow' options are enabled.
Quoted 5 lines
Ok I see that the objects are initialized with poisoning and redzoning but I do not see that there is fastpath code to actually check the values before the object is reinitialized. Is that intentional or am I missing something?
Yes, that's intentional here. I see the validation as a separate more expensive feature. I had a crude patch to do some checks for testing and I know Daniel Micay had an out of tree patch to do some checks as well.
Thanks,
Laura
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 9 lines · Laura Abbott
Quoted 4 lines
Ok I see that the objects are initialized with poisoning and redzoning but I do not see that there is fastpath code to actually check the values before the object is reinitialized. Is that intentional or am I missing something?
Yes, that's intentional here. I see the validation as a separate more expensive feature. I had a crude patch to do some checks for testing and I know Daniel Micay had an out of tree patch to do some checks as well.
Ok then this patch does nothing? How does this help?
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 7 lines · Christopher Lameter
Quoted 5 lines · Laura Abbott
Quoted 4 lines
Ok I see that the objects are initialized with poisoning and redzoning but I do not see that there is fastpath code to actually check the values before the object is reinitialized. Is that intentional or am I missing something?
Quoted 6 lines
Quoted 4 lines
Yes, that's intentional here. I see the validation as a separate more expensive feature. I had a crude patch to do some checks for testing and I know Daniel Micay had an out of tree patch to do some checks as well.
Ok then this patch does nothing? How does this help?
The purpose of this patch is to ensure the poisoning can happen without too much penalty. Even if there aren't checks to abort/warn when there is a problem, there's still value in ensuring objects are always poisoned.
Thanks,
Laura
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 13 lines · Laura Abbott
Quoted 12 lines · Christopher Lameter
Quoted 9 lines · Laura Abbott
Quoted 4 lines
Ok I see that the objects are initialized with poisoning and redzoning but I do not see that there is fastpath code to actually check the values before the object is reinitialized. Is that intentional or am I missing something?
Yes, that's intentional here. I see the validation as a separate more expensive feature. I had a crude patch to do some checks for testing and I know Daniel Micay had an out of tree patch to do some checks as well.
Quoted 5 lines
Quoted 1 line
Ok then this patch does nothing? How does this help?
The purpose of this patch is to ensure the poisoning can happen without too much penalty. Even if there aren't checks to abort/warn when there is a problem, there's still value in ensuring objects are always poisoned.
To clarify, this is desirable to kill exploitation of exposure-after-free flaws and some classes of use-after-free flaws, since the contents will have be wiped out after a free. (Verification of poison is nice, but is expensive compared to the benefit against these exploits -- and notably doesn't protect against the other use-after-free attacks where the contents are changed after the next allocation, which would have passed the poison verification.)
-Kees
Signature · 8 lines
Kees Cook Pixel Security -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 8 lines · Kees Cook
To clarify, this is desirable to kill exploitation of exposure-after-free flaws and some classes of use-after-free flaws, since the contents will have be wiped out after a free. (Verification of poison is nice, but is expensive compared to the benefit against these exploits -- and notably doesn't protect against the other use-after-free attacks where the contents are changed after the next allocation, which would have passed the poison verification.)
Well the only variable in the freed area that is in use by the allocator is the free pointer. This ensures that complete object is poisoned and the free pointer has a separate storage area right? So the size of the slab objects increase. In addition to more hotpath processing we also have increased object sizes.
I am not familiar with the terminology here.
So exposure-after-free means that the contents of the object can be used after it was freed?
Contents are changed after allocation? Someone gets a pointer to the object and the mods it later?
Quoted 11 lines · Christopher Lameter
Quoted 8 lines · Kees Cook
To clarify, this is desirable to kill exploitation of exposure-after-free flaws and some classes of use-after-free flaws, since the contents will have be wiped out after a free. (Verification of poison is nice, but is expensive compared to the benefit against these exploits -- and notably doesn't protect against the other use-after-free attacks where the contents are changed after the next allocation, which would have passed the poison verification.)
Quoted 5 lines
Well the only variable in the freed area that is in use by the allocator is the free pointer. This ensures that complete object is poisoned and the free pointer has a separate storage area right? So the size of the slab objects increase. In addition to more hotpath processing we also have increased object sizes.
I'll let Laura speak to that; this is mainly an implementation detail. I think it would be fine to leave the free pointer written in-object after poisoning.
Quoted 1 line
I am not familiar with the terminology here.
Sorry, my fault for not being more clear! More below...
Quoted 2 lines
So exposure-after-free means that the contents of the object can be used after it was freed?
There's a few things mixed together, but mainly this is about removing the idea of "uninitialized" memory contents. One example is just simply a memory region getting reused immediately, but failing to properly initialize it, so the old contents are still there, and they get exposed in some way (for a recent example, see [1]), leaking sensitive kernel contents that an attacker can use to extend another attack (e.g. leaking the precise location of some other target in kernel memory). A simple example could look like this:
userspace makes syscall
... some function call path ...
kfree($location);
userspace makes syscall
... other function ...
ptr = kmalloc(...); // ptr is $location now
... buggy logic that never writes to ptr contents ... copy_to_user(user, ptr, ...); // contents of $location copied to userspace
Quoted 2 lines
Contents are changed after allocation? Someone gets a pointer to the object and the mods it later?
The classic use-after-free attack isn't normally affected by cache poisoning, since the attack pattern is:
userspace makes syscalltracked_struct = kmalloc(...);
...kfree(tracked_struct); // some bug causes an early free
userspace makes syscall
...other_struct = kmalloc(...); // tracked_struct same as other_struct now other_struct->fields = evil_from_userspace; // overwrite by attacker
userspace makes syscall
...tracked_struct->function_pointer(...); // calls attacker-controlled function
In other words, between the kfree() and the use, it gets reallocated and written to, but the old reference remains and operates on the newly written contents (in this worst-case example, it's a function pointer overwrite). What I meant by "some classes of use-after-free flaws" was that in rare cases, the "written to" step isn't needed, since the existing contents can be used as-is (i.e. like the "exposure-after-free" example I showed first), but it differs in what primitives it provides to an attacker since it's not "just" an exposure, but results in an attacker having control over kernel behavior due to unexpected contents in memory.
Similar things happen to stack variables (there are lots of stack info-leak examples, and see my presentation[2] for a direct execution control example due to "uninitialized" variables), but that is being worked on separately (forced stack variable init, and forced stack clearing). The fast-path poisoning-on-free effort here is to protect the slab cache from these classes of flaws and attacks.
-Kees
[1] http://seclists.org/oss-sec/2017/q2/455
[2] https://outflux.net/slides/2011/defcon/kernel-exploitation.pdf
Signature · 8 lines
Kees Cook Pixel Security -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>