Open kingluo opened 2 months ago
This is a reliability issue. Relatively crucial since KASAN could reveal the bug https://github.com/tempesta-tech/tempesta/pull/2208 , which took quite a time to find. Must be solved in 0.9.
The thing is that TfwPool is a pool allocator, which frees many items at once and there is no such allocator in the Linux kernel. So just using kmallc()
instead could be problematic. Maybe the better way is to make TfwPool work with KASAN,
@RomanBelozerov probably we'll need a separate CI workflow, maybe periodic, to run all our test suite with as much as possible kernel sanitizers and checkers.
One more thing: TfwPool-allocated pages can be moved to skb and sent as paged data, so using kmalloc()
directly seems not possible.
Also would be good to make the system also work with kmemleak and other memory debugging tools
The tool is required to have to reveal further bugs and regressions, but it does take significant development effort, so I have to move it to the next milestone
As known, we use our home-brewed memory allocation for performance, e.g.
tfw_pool_new
, but the drawback is that it bypasses the KASAN. So we must ensure memory safety ourselves and cannot rely on general sanitizers.kmalloc/kmem_cache
, so KASAN does not shadow the heap memory.memcpy
are written in assembly code by ourselves, so no asan instrumentation is generated by GCC, as well as some overflow checks (through some compiler tricks e.g.__builtin_object_size
).If we forge the same bug like https://github.com/tempesta-tech/tempesta/pull/2208 but using
kmalloc
and the kernel'smemcpy
:Then KASAN will report it, we can explicitly know the bug.
We should make a unified API to manage memory but with different implementations for debug or release. We can enable the kernel's implementation automatically at the compile time if
CONFIG_KASAN
is 1.