Kernel: Sanitize memory coming in/out of the slab allocator

We were using SANITIZE_KMALLOC which was never defined in this .cpp
file, oops. Now we actually scrub on slab_alloc() and slab_dealloc().
This commit is contained in:
Andreas Kling 2020-02-26 13:21:31 +01:00
parent a57f074187
commit 987dbedf4a
Notes: sideshowbarker 2024-07-19 09:03:11 +09:00

View file

@ -29,6 +29,8 @@
#include <Kernel/Heap/kmalloc.h> #include <Kernel/Heap/kmalloc.h>
#include <Kernel/VM/Region.h> #include <Kernel/VM/Region.h>
#define SANITIZE_SLABS
namespace Kernel { namespace Kernel {
template<size_t templated_slab_size> template<size_t templated_slab_size>
@ -63,7 +65,7 @@ public:
m_freelist = m_freelist->next; m_freelist = m_freelist->next;
++m_num_allocated; ++m_num_allocated;
--m_num_free; --m_num_free;
#ifdef SANITIZE_KMALLOC #ifdef SANITIZE_SLABS
memset(ptr, SLAB_ALLOC_SCRUB_BYTE, slab_size()); memset(ptr, SLAB_ALLOC_SCRUB_BYTE, slab_size());
#endif #endif
return ptr; return ptr;
@ -78,7 +80,7 @@ public:
return; return;
} }
((FreeSlab*)ptr)->next = m_freelist; ((FreeSlab*)ptr)->next = m_freelist;
#ifdef SANITIZE_KMALLOC #ifdef SANITIZE_SLABS
if (slab_size() > sizeof(FreeSlab*)) if (slab_size() > sizeof(FreeSlab*))
memset(((FreeSlab*)ptr)->padding, SLAB_DEALLOC_SCRUB_BYTE, sizeof(FreeSlab::padding)); memset(((FreeSlab*)ptr)->padding, SLAB_DEALLOC_SCRUB_BYTE, sizeof(FreeSlab::padding));
#endif #endif