KMM misaligns objects after realloc with non-aligned size
Closed this issue · 3 comments
mickdermack commented
As opposed to allocateMemory
, reallocateMemory
does not align the size, and the KernelMemoryManager
in general does not align heap allocations. Because of this, after calling krealloc
with a non-aligned size (which ustl does quite often), future allocations may be non-aligned. This is a problem especially on ARM where misaligned Locks throw an exception when attempting to lock them.
We fixed this in our repo by just aligning the size of reallocs. I'm not sure if that's the best solution.
This test program manages to reproduce the problem on base SWEB, arm_icp
quite reliably:
#include "nonstd.h"
#include "fcntl.h"
int main()
{
// Use up some smaller free heap chunks
for (int i = 0; i < 5; i++)
open("/usr/README.txt", 0);
// This will reallocate the buffer for the path with an odd size and misalign
// more or less all objects belonging to the process, including the Loader and
// its program_binary_lock_, which will cause a CPU exception in kernelspace.
createprocess("///////////////////usr/mult.sweb", 1);
return 0;
}
dgruss commented
On 13.04.2018 17:25, Michael Ehrenreich wrote:
We fixed this in our repo by just aligning the size of reallocs. I'm not sure if that's the best solution.
Sounds like we shoulddo that.
mickdermack commented
PR on the devel
or master
branch?
dgruss commented
Master in this caseAm 17.04.2018 15:53 schrieb Michael Ehrenreich <notifications@github.com>:PR on the devel or master branch?
—You are receiving this because you commented.Reply to this email directly, view it on GitHub, or mute the thread.